【发布时间】:2015-09-22 15:55:30
【问题描述】:
这是一些未完成的创建计算器的代码,但是它一直给我一个语法错误。
n1=input("Enter Number: ")
Eo=input("Enter Operator: ")
if Eo=="+" or "-" or "*" or "/":
answer= n1+str(Eo)+input("Enter 2nd number: ")
Traceback (most recent call last):
File "C:/Python27/Programming/Calculator.py", line 2, in <module>
Eo=input("Enter Operator: ")
File "<string>", line 1
+
^
SyntaxError: unexpected EOF while parsing
【问题讨论】:
-
这条线并没有像你想象的那样做:
if Eo=="+" or "-" or "*" or "/": -
另请参阅 How do I test one variable against multiple values?,因为您在
if测试中出现逻辑错误。 -
那么它会做什么?,我希望它在选择其中一个运算符时进行答案计算..
-
请写一个写一百次的程序:“在我能详细解释它的作用之前,我不会在 Python 2.x 中使用
input。”
标签: python