所以我目前正在學習如何使用Python,並試圖解決我的問題,我有一個if語句,當輸入了錯誤的值時,我想它重新啓動並再次提出問題。Python - 重新啓動if語句,如果輸入的值不正確
我相信需要一個while循環或for循環,但是在尋找一段時間之後,我只是不確定如何使用這段代碼來實現它,因此如果有人知道我希望看到如何。
x = int(input("Pick between 1,2,3,4,5: "))
if x == 1:
print("You picked 1")
elif x == 2:
print("You picked 2")
elif x == 3:
print("You picked 3")
elif x == 4:
print("You picked 4")
elif x == 5:
print("You picked 5")
else:
print("This is not a valid input, please try again")
#Want to go back to asking the start question again
感謝,
利亞姆
你需要使用一個while循環 –