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!)
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Python编程从入门到实践动手试一试习题 15-1至15-5
- Python编程:从入门到实践 动手试一试 8.1-8.14
- Python编程:从入门到实践 动手试一试 8.1-8.14
- Python编程:从入门到实践 动手试一试 7.1-7.10
- Python编程:从入门到实践 动手试一试 7.1-7.10
- Python编程:从入门到实践 动手试一试 6.1-6.12
- Python编程:从入门到实践 动手试一试 6.1-6.12
- Python学习 第二天任务 (二:【基于Python编程从入门到实践】第二章 数字和注释 书本及动手试一试)
- Python入门与实践 Chapter 6 动手试一试
- Python入门与实践 Chapter 8 动手试一试
- Python入门与实践 Chapter 7 动手试一试
- Python学习 第二天任务 (一:【基于Python编程从入门到实践】第二章 变量和字符串 书本及动手试一试)
- Python学习 第一天任务 (四:【基于Python编程从入门到实践】动手试一试)
- Python入门与实践 Chapter 5 动手试一试
- Python入门与实践 Chapter 4 动手试一试
- python 编程 入门到实践 第四章 列表操作和元祖 (课后题加原书)
- python编程从入门到实践 第九章 知识点总结
- Python编程:从入门到实践 第3章 列表简介
- Python编程从入门到实践 393页,394页和396页 urls.py以及views.py 有误修改
- Python编程从入门到实践笔记——变量和简单数据类型