【发布时间】:2017-10-03 21:24:30
【问题描述】:
我目前正在使用try except 工具创建一个菜单。我正在尝试创建它,因此如果用户不输入任何内容(按 ENTER)输出:
您还没有输入任何内容,请输入一个介于 1 和 4 之间的数字
这是我到目前为止所做的:
def Menu():
print("""
Hello, please enter a number 1 - 4
1 - Compliment
2 - Fact
3 - Insult
4 - Quit
""")
try:
UserInput_INT = int(input("> "))
except ValueError:
UserInput_STR = (UserInput_INT)
if len(UserInput_STR) == 0:
print("You have entered nothing. Please enter a number between 1 and 4")
print("You entered a character. Please enter a number between 1 and 4")
Menu()
if UserInput_INT not in range (1, 5):
print("Invalid input please enter a whole number between 1 and 4")
UserInput_STR = (str(UserInput_INT))
if UserInput_STR == '1':
print(" You look horrible today!")
elif UserInput_STR == '2':
print("Sam Birkenshaw & Jordan Ives can code better than Mr Bath. ")
elif UserInput_STR == '3':
print("You are bad at coding ")
elif UserInput_STR == '4':
quit()
Menu()
【问题讨论】:
-
你想在
UserInput_STR = (UserInput_INT)做什么?
标签: python python-3.x