所以我目前正在学习如何使用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循环 –