【发布时间】:2017-07-31 20:38:11
【问题描述】:
所以我试图不让第一个 ELSE 继续,直到它满足要求输入仅包含 1 或 2 或 3 的条件......但它没有这样做......在 1 次打印后它去了到第二个 ELSE ......我在这里做错了什么?
def line_func(): # line to separate
print("==========================================================================")
def vs1():
print("") # vertical space
def start1():
vs1()
print("=====================================================")
print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")
while True:
start = input("Answer: ")
vs1()
if start == "y" or start == "Y" or start == "yes" or start == "YES" or start == "Yes":
line_func()
vs1()
menu1 = input("How would you like to proceed?\n\n1)Find an enemy to crush\n2)Restart game\n3)Exit game\n\nodgovor: ")
if menu1 == "1":
vs1()
start_round()
elif menu1 == "2":
vs1()
print("================= RESTARTING GAME ===================")
vs1()
print("=====================================================")
print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")
continue
start1()
elif menu1 == "3":
print("Ok see you next time... bye bye :)")
break
else:
print("You have to choose one of the options to proceed...")
elif start == "n" or start == "N" or start == "no" or start == "NO" or start == "No":
print("Ok see you next time... bye bye :)")
break
else:
print("You have to choose with yes or no...")
start1()
【问题讨论】:
-
提示:当您将输入更改为
start = input("Answer: ").lower()时,您可以将第一个 if 减少为if start == "y" or start == "yes"并且还可以减少关于no-Option 的 elif
标签: python python-3.x