我试图循环尝试除了我的菜单选项,部分代码如下,我只是想知道如何无限循环这个以避免程序崩溃...我尝试了一段时间真正的循环但我失败!
while True:
try:
choice = int(input("What would you like to do?\n1)Code a word\n2)Decode a word\n3)Print the coded words list\n4)Quit the program\n5)Clear Coded Words List\n>>>"))#Asking for choice from user
except ValueError:
print("Invalid entry! Try again")
choice =int(input("What would you like to do?\n1)Code a word\n2)Decode a word\n3)Print the coded words list\n4)Quit the program\n5)Clear Coded Words List\n>>>"))#Asking for choice from user
continue
else:
break
答案 0 :(得分:3)
尝试一下
Grid objTextbox = (Grid)sender;
答案 1 :(得分:0)
如果你想让这个代码片段循环,你需要引入一个循环。 E.g:
input_valid = False
while not input_valid:
try:
choice=int(input("What would you like to do?\n1)Code a word\n2)Decode a word\n3)Print the coded words list\n4)Quit the program\n5)Clear Coded Words List\n>>>"))#Asking for choice from user
input_valid = True
except ValueError:
print("Invalid Entry!\nPlease Try Again\n")