我一直在研究这段代码,当我测试它时,它说有一个语法错误,但它没有突出我在IDLE中的错误。有什么想法吗?
import os
import sys
Start=True
while Start==True:
Operation=input("Please select from the following operations\n"
"Add\n"
"Subtract\n"
"Note: Please type the option exactly as on\nscreen or you will recieve an error message.")
if Operation==not(in("Add","Subtract")):
print("That is not a mathmatical operation.\nPlease try again.")
time.sleep(2)
os.sys("cls")
while Operation==str("Add"):
print("You have selected Addition!")
time.sleep(2)
os.sys("cls")
答案 0 :(得分:2)
错:
if Operation==not(in("Add","Subtract")):
print("That is not a mathmatical operation.\nPlease try again.")
time.sleep(2)
os.sys("cls")
应该是:
if Operation not in ("Add","Subtract"):
print("That is not a mathmatical operation.\nPlease try again.")
time.sleep(2)
os.sys("cls")
答案 1 :(得分:1)
错误在于:
if Operation==not(in("Add","Subtract")):
正确的代码应该是:
if Operation not in("Add","Subtract"):
您还应在代码的开头添加import time
,以使time.sleep
正常工作。