In my python game I'm playing around with I have a menu where you can select to either play the game, load a saved game, save a game, and quit. The input of numbers works fine but when you accidentally or purposefully enter a letter or symbol it returns the error:
Choice = eval(input())
File "string", line 1, in module
NameError: name 'y' is not defined"
How would I go about fixing this issue?
Function where the error occurs:
def DisplayMenu():
print('1. Start new game')
print('2. Load game')
print('3. Save game')
print('9. Quit')
print('Please enter your choice: ')
def GetMainMenuChoice():
Choice = eval(input())
return Choice
if not (Choice in ['1','2','3','4','9']):
print("\n Invalid choice. Enter your option again. \n")
Choice = False
else:
Choice = True