while True:
print "Please choose from one of the five following options:"
print " 1. 10^1\n 2. 10^2\n 3. 10^3\n 4. 10^4\n 5. 10^5\n"
choice = raw_input()
if choice == 1:
print "1"
elif choice == 2:
print "2"
elif choice == 3:
print "3"
elif choice == 4:
print "4"
elif choice == 5:
print "5"
while choice not in [1,2,3,4,5]:
print "Not a valid choice!\n"
break
我應該使用什麼語法?我一直沒有得到一個有效的選擇。它像Python一樣將每個選擇甚至1,2,3,4,5放置在該列表之外的點列表中。Python Choice不在列表中
你的while循環是不必要的。把它放在if語句中的else子句中。 –