第七章 用户输入和while循环

7-1汽车租赁:

#7-1
car = input('What kind of car would you like to rent: ') print('Let me see if I can find you a '+car)

7-2餐馆定位:

#7-2
message = input('请输入就餐人数:') if int(message)>8: print('抱歉,没有空桌') else: print('有空桌')

7-3 10的整倍数:

#7-3
message =input('请输入一个数字: ') if int(message) %10 == 0: print('这个数字是十的倍数') else: print('这个数字不是十的倍数')

7-4比萨配料:

#7-4
peiliao = ('请输入你需要添加的比萨配料:')
peiliao +=('\n当你输入quit,将停止添加配料。')
pizzas = ' '
while pizzas !='quit':
    pizzas=input(peiliao)
    if pizzas !='quit':
        print('你的比萨添加'+pizzas+'成功\n')

7-5电影票:

#7-5
prompt ='\nPlease enter your age:' prompt +='\nenter quit to end the progrom.' while True: age=input(prompt) if age == 'quit': break else: age=int(age) if age<3: print('free') elif age<12: print('The ticket price is 10 dollars.') else: print('The ticket price is 15 dollars.')

7-6三个出口:

#7-6
peiliao = ('请输入你需要添加的比萨配料:')
peiliao +=('\n当你输入quit,将停止添加配料。')
active = True
while active:
    pizzas =input(peiliao)
    
    if pizzas !='quit':
        print('你的比萨添加'+pizzas+'成功\n')
    else:
        break

7-7无限循环:

number =2
while number>0:
    print(number)

7-8熟食店:

 

#7-8
sandwich_orders=['Pice','Noy','Torta']
finished_sandwiches=[]
while sandwich_orders:
    finished_sandwiche =sandwich_orders.pop()
    print('I made your '+str(finished_sandwiche))
    finished_sandwiches.append(finished_sandwiche)
for finished_sandwiche in finished_sandwiches:
    print(finished_sandwiche)

 

7-9五香烟熏牛肉卖完了:

#7-9
sandwich_orders=['Pice','pastrami','Noy','pastrami','Torta','pastrami']
finished_sandwiches=[]
print('The pastrami has been sold.')
while 'pastrami'in sandwich_orders:
    sandwich_orders.remove('pastrami')
while sandwich_orders:
    finished_sandwiche =sandwich_orders.pop()
    finished_sandwiches.append(finished_sandwiche)
for finished_sandwiche in finished_sandwiches:
    print(finished_sandwiche)

7-10梦想的度假胜地:

#7-10
responses=[]
active =True
while active:
    dream_places=input('If you could visit one place in the world,where would you go?')
    responses.append(dream_places)
    repeat=input('Would you want to input another place?(yes/no)')
    if repeat =='no':
        active = False
for response in responses:
    print('The '+response+' you want to go!')

  

 

  

posted @ 2020-05-26 21:26  猫山思  阅读(137)  评论(0)    收藏  举报