我正在为一个菜单系统设计一个模板,我已经为初学者很好地整理了它。在过去的几天里,我通过 stackoverflow 得到了一些很好的帮助,我想我会问这里出了什么问题。
这是代码:
# Multitasker
# Allows User to Pick an Item that is Defined.
# This is the initial screen.
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X DEMO MULTITASK DEMO X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X MULTITASKING X
X -------------------- X
X MAIN MENU SYSTEM X
X FOR GAME PLATFORMS X
X -------------------- X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PRESS 'ENTER' TO CONTINUE""",end=" ")
# Input used to prevent the Multitask Selector Menu from Appearing at First!
input(" ")
# Defining Task 1
def task1():
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X YOU HAVE CHOSEN TO DISPLAY TASK 1 X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end=" ")
# Defining Task 2
def task2():
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X YOU HAVE CHOSEN TO DISPLAY TASK 2 X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end=" ")
# Defining Task 3
def task3():
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X YOU HAVE CHOSEN TO DISPLAY TASK 3 X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end=" ")
# Defining Task 4
def task4():
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X YOU HAVE CHOSEN TO DISPLAY TASK 4 X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end=" ")
# If the Player Selected an innappropriate task number greater than 4, this will display.
def notatask():
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X THAT IS NOT A POSSIBLE CHOICE. X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end=" ")
# Starts choice off as having no selection.
choice = None
playername = " "
# While the variable 'choice' is not '0', it will continue to display the menu below
while choice != "0":
print(
"""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X MULTITASK SELECTION X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X 0 - Quit X
X 1 - Task 1 X
X 2 - Task 2 X
X 3 - Task 3 X
X 4 - Task 4 X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end=" ")
choice = int(input("\n\t\tPick a Task Between 0-4:\t#"))
print()
# Exit
if choice == int('0'):
print("""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X DEMO MULTITASK DEMO X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X MULTITASKING X
X -------------------- X
X MAIN MENU SYSTEM X
X FOR GAME PLATFORMS X
X -------------------- X
X X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
""", end="")
print("\t\t", playername, end="")
print("""
PRESS 'ENTER' TO CONTINUE""", end=" ")
input(" ")
# Task 1
elif choice == int('1'):
task1()
# Task 2
elif choice == int('2'):
task2()
# Task 3
elif choice == int('3'):
task3()
# Task 4
elif choice == int('4'):
task4()
# Not a Correct Selection
elif choice > int('4'):
notatask()
# Enter Key
elif choice == ('ENTER'):
notatask()
所以,我不明白的是,当有人按下 0、1、2、3 或 4 以外的键时,我需要做些什么才能让它调用 notatask()。
任何人都可以引导我朝着正确的方向前进吗?
提前致谢。
最好的,
史蒂文