我很好奇如何让这个程序在触发 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句