在我輸入 5 后,它繼續回圈并且沒有到達 if 陳述句
def facility():
global user
while user != 1 and user != 2 and user != 3 and user != 4:
user =input("please choose between this four number. \n[1/2/3/4]\n")
if user == 1:
y = ("PBl Classroom")
elif user == 2:
y = ("meeting room")
elif user == 3:
y =("Workstation Computer Lab,ITMS")
elif user == 4:
y = ("swimming pool")
print("you have choose",y)
user = int(input("please choose your facility..\n "))
uj5u.com熱心網友回復:
您int(input(...))在第一次呼叫時使用,但input(...)在函式中使用。因此,這些值是字串,而不是整數,您的比較將失敗。
這是一個帶有小改進的修復:
def facility():
user = int(input("please choose your facility..\n "))
while user not in (1,2,3,4):
user = int(input("please choose between this four number. \n[1/2/3/4]\n"))
if user == 1:
y = ("PBl Classroom")
elif user == 2:
y = ("meeting room")
elif user == 3:
y =("Workstation Computer Lab,ITMS")
elif user == 4:
y = ("swimming pool")
print("you have chosen", y)
facility()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/377731.html
