if语句

# 5-3
alien_color = 'green'

if alien_color == 'green':
    print("You get 5 points")

# 5-4
alien_color = 'green'

if alien_color == 'green':
    print("You get 5 points")
else:
    print("You get 10 points")

# 5-5
alien_color = 'red'

if alien_color == 'green':
    print("You get 5 points")
elif alien_color == 'yellow':
    print("You get 10 points")
else:
    print("You get 15 points")

# 5-6
age = 3

if age < 2:
    print("This is a baby!")
elif (age >= 2) and (age < 4):
    print("He is toddling!")
elif (age >= 4) and (age < 13):
    print("He is a child!")
elif (age >= 13) and (age < 20):
    print("He's a teenager!")
elif (age >= 20) and (age < 65):
    print("He's an adult!")
else:
    print("He is an old man!")

# 5-7
favorite_fruits = ['bananas', 'apple', 'watermelon', 'orange', 'pear']

if 'bananas' in favorite_fruits:
    print("You really like banans")
if 'strawberry' in favorite_fruits:
    print("You really like strawberry")
if 'apple' in favorite_fruits:
    print("You really like apple")
if 'watermelon' in favorite_fruits:
    print("You really like watermelon")
if 'orange' in favorite_fruits:
    print("You really like orange")
You get 5 points
You get 5 points
You get 15 points
He is toddling!
You really like banans
You really like apple
You really like watermelon
You really like orange

你可能感兴趣的:(if语句)