您的位置:首页 > 编程语言 > Python开发

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

2020-02-06 08:05 459 查看

#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!)
  • 点赞
  • 收藏
  • 分享
  • 文章举报
baiyao_12 发布了8 篇原创文章 · 获赞 0 · 访问量 85 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: