Soo I swear this code worked before!
I'm trying to do something very simple..set variables.
As you can see these work:
>>> print("hello")
hello
>>> def main():
print("hey")
>>>main()
hey
So when I try to recreate an example problem, you would expect these variables to work, right?
def main():
print("This calculates the cost of coffee.")
print()
n = eval(input("Enter amount of coffee in pounds: ")
m = 10.50 * n
SyntaxError: invalid syntax
Why??? Why does Python 3.5.2 return "SyntaxError: invalid syntax"?
Thanks guys! Sorry I'm such a noob.
As pointed out in the comments several times, You are simply missing a closing )
on line 4 of your program. line 4 should look like
n = eval(input("Enter amount of coffee in pounds: "))# <--extra parenthesis
Some unrelated points in your code:
eval()
? It looks like your going for float/integer conversion, so use int()
or float()
. print("This calculates the cost of coffee.\\n")
n = float(input("Enter amount of coffee in pounds: "))*10.50
After adding my suggestions to your code, it would yield something like this:
def main():
print("This calculates the cost of coffee.\n")
n = float(input("Enter amount of coffee in pounds: "))*10.50
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.