Hi I’m writing a program currently I’m pretty new to python,
what I’m wanting is for the user to select from two options like so
1. Easy Mode
2. Hard Mode
and then once selected at the end it will display
Username (inputted username)
Difficulty (option chosen)
but every time I write the code the difficulty displays as either a 1 or 2 and not Easy Mode or Hard Mode any help?
Code so far
Choice = int(input("Select your difficulty: "))
if (Choice == 1):
print("Easy Mode")
elif (Choice == 2):
print("Hard Mode")
print ("Role: " ,Choice )
>Solution :
You set Choice = int(...), so Choice is still 1 or 2, so when you print it it’ll show up as 1 or 2. Instead, you could set a variable mode depending on which if statement is entered:
Choice = int(input("Select your difficulty: "))
mode = "Invalid choice" # Set a default value
if (Choice == 1):
mode = "Easy Mode"
elif (Choice == 2):
mode = "Hard Mode"
print ("Role: " , mode)
Of course, this doesn’t account for the case when the user’s input isn’t one of these choices, but that’s a different question: Asking the user for input until they give a valid response