我无法让我的计算器工作。当我运行它时,它说y elif语句是invallid,函数在这个clode块之上,它应该可以工作。
choice = raw_input("chose an operator [1,2,3,4]")
num1 = raw_input("input number 1")
num2 = raw_input("input number 2")
if choice == 1:
print(num1,"+",num2,"=",add(num1,num2)
elif choice == 2:
print(num1,"-",num2,"=",minus(num1,num2)
elif choice == 3:
print(num1,"x",num2,"=",times(num1,num2)
elif choice == 4:
print(num1,"/",num2,"=",divide(num1,num2)
else:
print("that's not a valid operator")
这是我的错误
File "calculator.py", line 27
elif choice == 2:
答案 0 :(得分:2)
您在所有打印报表中都缺少关闭)
,除了最后一个。
答案 1 :(得分:0)
你在每一行都缺少a)
if choice == 1:
print(num1,"+",num2,"=",add(num1,num2) # <--- needs ) to close
注意: raw_input“询问”字符串值,在您的情况下,您应该更改
if choice == 1:
到
if choice == "1":
否则只需使用输入
例如:
choice = input("chose an operator [1,2,3,4]:\n") # <- added \n, puts a new line at that point