Python编程:从入门到实践 动手试一试 5.1-5.11

#5.1 condition test

cars = ['subaru', 'bmw', 'jaguar', 'mercedes']
car = "toyota"
if car not in cars:
    print("Sorry, you're wrong about the guess!")

print(23>21 and 21<12)
print(23/2 >10 or 23<12)
print('subaru' in cars)
print('toyota' not in cars)
print('toyota' in cars)

#5.2 more conditional tests

#skip it, unnecessary work.

#5.3 the color of alien_1

alien_color = 'green' or 'yellow' or 'red'
if alien_color is 'green':
    print("You've made 5 points!")

if alien_color is 'pink':
    print("You didn't earn the point!")

#5.4 the color of alien_2

if alien_color is "green":
    print("You've earned 5 points!")
else:
    print("You've earned 10 points!")

#5.5 the color of alien_3

if alien_color is "green":
    print("You've earned 5 points!")
elif alien_color is "yellow":
    print("You've earned 10 points!")
else:
    print("You've earned 15 points!")

#5.6 the different ages of life

age = 26
if age < 2:
    print("He is a baby.")
elif 2 <= age < 4:
    print("He is learning to walk.")
elif 4 <= age < 13:
    print("He is a child.")
elif 13 <= age < 20:
    print("He is a teenager.")
elif 20 <= age < 65:
    print("He is a adult.")
else:
    print("He is an old man.")

#5.7 favorite fruits

fruits = ['apple', 'orange', 'banana', 'grape', 'pineapple', 'peach', 'waxberry']
favorite_fruits = fruits[0:3]
if 'apple' in favorite_fruits:
    print("You really like apple!")
if 'orange' in favorite_fruits:
    print('You really like orange!')
if 'waxberry' in favorite_fruits:
    print("You really like waxberry!")
if "grape" in favorite_fruits:
    print("You really like grape!)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值