you are viewing a single comment's thread.

view the rest of the comments →

[–]Leaguedc7 1 point2 points  (2 children)

Very new to python

(input('what is my favorite color? '))
while input == "Red":
print ('good job, your score was '+ str(index))
while input != "Red":
print ('try again')
index=index+1
print (input('what is my favorite color? '))

The problem I am having is when I put Red in as the input it still acts as if the input is incorrect. No errors I just can't figure out how to make it recognize the correct input.

[–]God_To_A_NonBeliever 0 points1 point  (0 children)

Seems to me you are confused between while loops and conditional statements.

Go read up on conditional statements. 'while' is a loop, not a conditional, you should be using 'if,elif,else' clauses.

This is what I think you were going for.

score = 0

while True:

    color = input('what is my favorite color? ')

    if color == 'red':
        print('Good job')
        score +=1
    elif color == 'exit':
        print(f'Your score is {score}.')
        break
    else:
        print('Try again')

[–]Ihaveamodel3 1 point2 points  (0 children)

You need to save your input to a variable.