Reputation: 1
I am doing a food chooser in python. the user will answer questions based on the list printed out. what i am trying to figure is how to print a single variable from the list based on the score from the question?
food = ['donuts', 'pancakes', 'bacon', 'waffles', 'eggs', 'bagels']
score = [0,0,0,0,0,0]
print('Please answer each question with "y" for "yes" and "n" for "no".')
user_input = input('Do you like food with holes? ')
user_input2= input('do you like stuff made from animals? ')
user_input3=input('do you like sweets')
if user_input == 'y':
score[0] = score[0] + 1
score[5] = score[5] + 1
else: user_input ='n'
score[0] = score[0]-1
score[1] = score[1]-1
if user_input2 == 'y':
score[0] = score[0] + 1
score[5] = score[5] + 1
else: user_input ='n'
score[0] = score[0]-1
score[1] = score[1]-1
if user_input == 'y':
score[0] = score[0] + 1
score[5] = score[5] + 1
else: user_input3 ='n'
score[0] = score[0]-1
score[1] = score[1]-1
Upvotes: 0
Views: 145
Reputation: 61
You can do
print(score[i])
at the end if you are on version python3 where i
is the index of the array
Upvotes: 1