mercredi 24 mai 2017

If-statements Not Regonizing User Input

I'm new to Python and coding in general. I'm trying to create a fill-in-the-blank quiz to practice. The first part asks the user to choose a difficulty. Once entered, the code appends an empty list. I'll use the list to load questions and answers. However, the issue I'm running into is the if-statements won't recognize user input. I want to make sure the user only inputs easy, medium, or hard. To see if the code worked, I used a print function. However, my code goes right to the else-statement and prints 'Try again.' Any ideas?

Here is my code.

choice = []

new_choice = raw_input('Select your quiz difficulty: Easy, Medium, Hard: ')
choice.append(new_choice)
print choice

if choice == 'easy':
    print 'True'
elif choice == 'medium':
    print 'True'
elif choice == 'hard':
    print 'True'
else:
    print 'Try again.'

Aucun commentaire:

Enregistrer un commentaire