mercredi 5 juin 2019

Why does the code always execute the first if condition?

I'm still experimenting with if, elif and else. I don't understand why the first if condition is executed even if you don't choose blue as your favorite color.

I tried changing the indentation but I always get syntax errors.

color = input("Whats your favorite color?\n")

if color == 'blue' or 'Blue':
    print("Blue is a great color")
    print(f"{color} is your favorite color")
elif color == 'yellow' or 'Yellow':
    print(f"{color} is your color")
    print("Yellow is awesome!")
else:
    print("Choose something")

When I enter random letters, for example, 'sdfd' I should get the result "Choose a real color" but instead I get Blue is a great color sdfd is your favorite color

Aucun commentaire:

Enregistrer un commentaire