python从入门到实践 第七章习题 (高级编程技术 week4-1)
2018-03-27 09:54
465 查看
python从入门到实践 第七章习题 (高级编程技术 week4-1)
这一节课主要讲的是在python中用户输入的处理以及while循环的编写。7.1 函数input()
需要注意的一点是,input()函数获取的用户输入一般都是字符串形式的,需要对数据进行进一步的处理(如课本示例中的int()函数将字符串转成数字)。7-1 汽车租赁
print('Whick kind of cars do you want?') car=('please enter the car you want : ') print('Let me see if I can find you a Subaru')
7-3 10的整数倍
number = input('Please enter an number : ') number = int(number) if number % 10 == 0: print(number, ' is not an integer multiple of ten.') else: print(number, ' is an integer multiple of ten.')
7.2 while循环的编写
在这一张,出现了三个新的关键字:while,break,continue7-4 披萨配料
message = '' while 1: message = input('Please enter ingredients for pizza') if message == 'quit' break else: print('We will add this ingredients in pizza!')
7-5 电影票
active = True while active: age = input('Please enter your age : ') age = int(age) if age < 3: print('You are free!') elif 3 <= age && age <= 12: print('Your fee is ten dollars') else: print('Your fee is fifteen dollars')
7.3 使用while循环处理列表和字典
笔记:for循环是一种遍历列表的有效方式,但在for循环中不应修改列表,否则将导致Python难以跟踪其中的元素。要在遍历列表的同时对其进行修改,可使用while循环。通过将while循环同列表和字典结合起来使用,可收集、存储并组织大量输入,供以后查看和显示。7-8 熟食店
sandwich_orders = ['sandwich1','sandwich2', 'sandwich3'] finished_sandwiches = [] while sandwich_orders: make_sandwich = sandwich_orders.pop() print('I made your ', make_sandwich,'.') finished_sandwiches.append(make_sandwich) for finished_sandwich in fornished_sandwich: print(finished_sandwich, ' has finished.')
7-10 梦想的度假胜地
result = {} active = True while active: name = input('Please enter your name') respone = input('If you could visit on place in the world, where would you go?') result[name] = respone q = inpur('Quit? /Y') if q == 'Y' break for name, respone in result.items(): print(name.title(), ' : ', respone)
相关文章推荐
- python从入门到实践 第八章习题(高级编程技术 week4-2)
- python 从入门到实践第四章习题 (高级编程技术 week2-2)
- python从入门到实践 第十章习题(高级编程技术 week5-2)
- python从入门到实践 第六章习题 (高级编程技术 week3-2)
- python从入门到实践第三章习题(高级编程技术 week2-1)
- python从入门到实践 第九章习题(高级编程技术 week5-1)
- python从入门到实践第七章的练习题作业
- 【《Python编程: 从入门到实践》习题答案--第七章:<用户输入和while 循环>】
- 《Python编程——从入门到实践》第七章部分习题解
- Python 从入门到实践 6-7 课后习题
- Python 从入门到实践 7-4 课后习题
- python 从入门到实践 第五章习题 (高级编程技巧 week3-1)
- Python 从入门到实践 6-1 课后习题
- 《Python编程 从入门到实践》第七章课后习题
- python从入门到实践,习题15-5重构
- 《Python编程-从入门到实践》第七章及第八章习题训练
- Python编程从入门到实践:习题6-7~6-12
- Python编程从入门到实践:习题4-13
- Python 从入门到实践 5-1 课后习题
- Python 从入门到实践 5-3 课后习题