在触发Else语句时,我将如何使该程序重新开始



我很好奇我如何使该程序自动提示用户触发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