我尝试制造一些机器人,并且与if一起使用多个运算符进行堆叠。这是脚本的一部分:
def start() :
print
ans=True
while ans:
print
ans=raw_input(": User : ")
if ans=="A":
WORDS = ("A", "B", "C")
word = random.choice(WORDS)
print
print ": Syst :", word
time.sleep(1)
start()
else:
print("\n Not Valid Choice Try again")
print
time.sleep(2)
start()
在此行中:如果ans ==“ A”:我想使用多个运算符:我可以这样做:
def start() :
print
ans=True
while ans:
print
ans=raw_input(": User : ")
if ans=="A":
WORDS = ("A", "B", "C")
word = random.choice(WORDS)
print
print ": Syst :", word
time.sleep(1)
start()
elif ans=="B":
WORDS = ("A", "B", "C")
word = random.choice(WORDS)
print
print ": Syst :", word
time.sleep(1)
start()
elif ans=="C":
WORDS = ("A", "B", "C")
word = random.choice(WORDS)
print
print ": Syst :", word
time.sleep(1)
start()
else:
print("\n Not Valid Choice Try again")
print
time.sleep(2)
start()
对我来说不好,因为它会持续很长的时间...我需要像这样:
if ans==("A","B","C"):
WORDS = ("A", "B", "C")
word = random.choice(WORDS)
print
print ": Syst :", word
time.sleep(1)
start()
,它不起作用.. sintax中有一些错误..我无法使其起作用 请原谅我,我的英语不好。
答案 0 :(得分:0)
在这里,感谢Tanmay Jain
if ans=="A" or ans == "B" or ans == "C":
WORDS = ("A", "B", "C")
word = random.choice(WORDS)
print
print ": Iqar :", word
time.sleep(1)
start()