Why isn't the 'And' in my python script work

Viewed 19

I am a beginner at programming and I am trying to get my program to work. In my program I ask two questions from the user and if both answers == "1", then my variable A should change to "Blue" However, it's not working. Could someone tell me why?

Thanks.

print("Q1")

A = input(">>>")

if A == "1":
    A = "Red"

print("Q2")

B = input(">>>")

if B == "1":
    B = "Red"

if A == "1" and B == "1":
        A = "Blue"

print(A)
1 Answers

You are setting the variable A to red then you check if A == 1 essentially comparing RED == 1 which will always be false. Try changing the name of the variable you assign RED and BLUE to

##test ##

print("Q1")

A = str(input(">>>"))

if A == "1": A_result = "Red"

print("Q2")

B = input(">>>")

if B == "1": B_result = "Red"

if A == "1" and B == "1": A_result = "Blue"

print(A_result)
Related