I'm trying to compress all the if statements using a while loop but I don't know if there is a better way to do this. the program works without the while loop but I am just trying to make it shorter. I am new to Python please let me know if you think there is a better way to implement this.
value1=3
value2=3
value3=2
value4=4
#three same
while True:
print("three same")
if value1 == value2 == value3 != value4:
break
elif value2 == value3 == value4 != value1:
break
else:
print("not the same")
This is the code working without while loop (I just want to know if there is a way to avoid printing ("three same") twice)
value1=3
value2=3
value3=2
value4=4
#three same
if value1 == value2 == value3 != value4:
print("three same")
elif value2 == value3 == value4 != value1:
print("three same")
else:
print("not the same")
Aucun commentaire:
Enregistrer un commentaire