i am new to python and i am trying the following code. The problem is that even after one of the conditions are met in the if statment and a is set to false it goes back to the beginning of the function setting a to true therefore never ending.
def secColor():
a = True
while a:
c1 = input("Enter the first color (red,blue,yellow)").lower()
c2 = input("Enter the second color (red,blue,yellow)").lower()
if c1 == "red" and c2 == "blue" or c1 == "blue" and c2 == "red":
print("Purple")
a = False
elif c1 == "red" and c2 == "yellow" or c1 == "yellow" and c2 == "red":
print("Orange")
a = False
elif c1 == "blue" and c2 == "yellow" or c1 == "yellow" and c2 == "blue":
print("Green")
a = False
elif c1 == c2:
print("Error! You must enter two different colors")
else:
print("Error! The color must be one of the following (red,blue,yellow)")
secColor()
Aucun commentaire:
Enregistrer un commentaire