elkyfrostglen
elkyfrostglen

Reputation: 11

SyntaxError: multiple statements found in python. Does anyone have experience with this?

The following code is from the textbook in our intro to python class. Between asking my classmates, the instructor, and searching this problem on the internet, no one seems to understand where the error is coming from. My instructor said he couldn't see where a second statement was coming from. If anyone has any experience with this or any suggestions I would greatly appreciate it.

>>> # quadratic.py
#   A program that computes the real roots of a quadratic equation.
#   Note: this program crashes if the equation has no real roots.

import math  # Makes the math library available.

def main():
    print("This program finds the real solutions to a quadratic")
    print()

    a,b,c = eval(input("Please enter the coefficients (a,b,c): "))

    discRoot = math.sqrt(b*b*-4*a*c)
    root1 = (b + discRoot) / (2 * a)
    root2 = (b - discRoot) / (2 * a)

    print()
    print("The solutions are: ", root1, root2)

main()
SyntaxError: multiple statements found while compiling a single statement

Upvotes: 1

Views: 110

Answers (1)

Blckknght
Blckknght

Reputation: 104792

It looks like you've pasted a whole script into an interactive shell in some IDE. Your IDE isn't passing along the lines one by one to Python, but all at once. The code underlying the interactive shell doesn't like this, so you're getting an error.

I'd suggest putting your code into a file and then running it, rather than entering the code via the shell directly. If you really need to only use the interactive shell, separate out the different statements onto their own input lines (the import statement at the top, the def statement in the middle, and the main() expression statement at the end).

Upvotes: 1

Related Questions