触发else语句后,如何使该程序重新开始?

时间:2019-02-19 00:26:21

标签: python

我很好奇,如何使该程序在触发else语句后自动提示用户另一个值。

.col.l2.custom, .col.m1.custom {
    min-height: 100vh; /* use "vh" instead of % */
}

1 个答案:

答案 0 :(得分:4)

将整个内容包装在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