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

python学习——用户输入和while循环

2018-04-01 17:40 791 查看
题目参照《python编程——从入门到实践》第七章习题
7-1car = input('what kind of car do you want? ')
print('let me see if i can find you a '+car)
7-2while True: age=input('How old are you? ') if age=='quit': break else: age=int(age) if age<3: print('0 dollar') elif age>12: print('15 dollars') else: print('10 dollars')7-5
while True:
age=input('How old are you? ')
if age=='quit':
break
else:
age=int(age)
if age<3:
print('0 dollar')
elif age>12:
print('15 dollars')
else:
print('10 dollars')
7-8、7-9sandwich_orders=['egg','pastrami','pork','pastrami','tuna','pastrami']
finished_orders=[]
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
print('Pastrami sold out.')
while sandwich_orders:
sandwich=sandwich_orders.pop()
print('I made your '+sandwich+' sandwich.')
finished_orders.append(sandwich)
print(finished_orders)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: