当代码要求用户输入时,如果用户输入错误,它将停止工作

时间:2018-09-10 03:03:18

标签: python loops

week = int(input("Enter The Week Your Stay Starts "))

if week not in range(23,39):
    print("You Cannot Make Bookings Outside Of Weeks 23-39")
elif week in range(23,39) and week in range(23,26) or week in range(36,39):
    print("Peak Rates Apply Do Not Apply To The Week You Have Selected")
    onoff = False
elif week in range(23,39) and week in range(27,35):
    print("Peak Rates Apply To The Week You Have Selected")
    onoff = True
    print("Something Went Wrong Please Try Again And Enter Correct Details")        

总而言之,此代码询问用户他们想要哪个房间。然后在他们输入的星期确定价格是处于高峰还是处于非高峰(决定价格)。如果用户输入的内容超出23-39范围,则不应允许用户输入。我遇到的问题是我不确定如何循环播放,因此在用户输入23-39以外的几周后,它会询问用户他们想要哪一周。我在考虑REPEAT .... UNTIL或WHILE ... DO ... ENDWHILE循环,但不知道是否可行

0 个答案:

没有答案