[英]How would i make this program start over upon triggering the else statement?
我很好奇我如何使該程序在觸發else語句后自動提示用戶另一個值。
tires = float(input('How many tires would you like?'))
if tires == 2:
print('That will be $250')
if tires == 4:
print('That will be $400')
else:
print('That is not a valid input, please try again')
將整個內容包裝在while
循環中:
while True:
tires = float(input('How many tires would you like?'))
if tires == 2:
print('That will be $250')
break
elif tires == 4:
print('That will be $400')
break
else:
print('That is not a valid input, please try again')
# keep looping
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.