【发布时间】:2016-12-03 23:14:47
【问题描述】:
所以我目前正在学习如何使用 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循环
标签: python loops if-statement