我遇到一些麻煩打破這些循環:擺脫循環?
done = False
while not done:
while True:
print("Hello driver. You are travelling at 100km/h. Please enter the current time:")
starttime = input("")
try:
stime = int(starttime)
break
except ValueError:
print("Please enter a number!")
x = len(starttime)
while True:
if x < 4:
print("Your input time is smaller than 4-digits. Please enter a proper time.")
break
if x > 4:
print("Your input time is greater than 4-digits. Please enter a proper time.")
break
else:
break
它承認數目是否< 4> 4,但即使輸入的數字是4位數返回到開始該程序而不是繼續下一段代碼,這是不是在這裏。
您在哪裏更改爲True? – 2014-10-29 01:53:16
嘗試: stime = int(starttime)#你的意思是starttime = int(starttime)。 – Crispy 2014-10-29 01:57:57