I’m working on a template for a menu system and I have it sorted out quite well for a beginner. I’ve had some good help through stackoverflow in the past few days and figured I’d ask what’s wrong here.
Here’s the Code:
# 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()
So, what I don’t understand is what I need to do to make it call notatask() when someone hits a key other than 0, 1, 2, 3, or 4.
Can anybody lead me in the right direction?
Thanks in Advance.
Best,
Steven
After the
eliffor Task 4, just use anelse.