Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python, display user choice from list

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading