jeudi 24 décembre 2020

I expected to be able to use AND or OR to include an extra Value in my if statement? [duplicate]

planets = ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "cow"]

for planet in planets:    
if planet == "pluto":
    print(f"{planet.title()} is NOT a planet!")
else:
    print(f"{planet.title()} is a planet!")

In the code above I thought to add the value "cow" onto the if statement I would simply use 'and' or maybe 'or' e.g.

if planet == "pluto" or "cow":

output using or:

Mercury is NOT a planet!
Venus is NOT a planet!
Earth is NOT a planet!
Mars is NOT a planet!
Jupiter is NOT a planet!
Saturn is NOT a planet!
Uranus is NOT a planet!
Neptune is NOT a planet!
Pluto is NOT a planet!
Cow is NOT a planet!

output using and:

Mercury is a planet!
Venus is a planet!
Earth is a planet!
Mars is a planet!
Jupiter is a planet!
Saturn is a planet!
Uranus is a planet!
Neptune is a planet!
Pluto is NOT a planet!
Cow is a planet!

Aucun commentaire:

Enregistrer un commentaire