python学习——python编程从入门到实践(7)

第 7 章 用户输入和while循环

课后题
在这里插入图片描述

# 7-1
message = input("What kind car do you need? ")
print("Let me see if I can find you a "+message)

#7-2
message = input("How many people have the dinner? ")
message = int(message)
if message > 8:
    print("There is no empty table.")
else:
    print("There are some tables.")

#7-3
number = input("Enter a number: ")
number = int(number)
if number%10 == 0:
    print(str(number) + " is integer multiple of 10")
else :
    print(str(number) + " isn't integer multiple of 10")

# 7-4
prompt = "\nPizza's Burden: "
prompt += "\nEnter 'quit' to end the program: "
message =''
while message != 'quit':
    message = input(prompt)
    print("We will add "+message)

#7-5
age = input("Age: ")
age = int(age)
if age<3:
    print("FREE")
elif age>=3 and age<12 :
    print("$10")
else:
    print("$15")

#7-6
prompt = "\nPizza's Burden: "
prompt += "\nEnter 'quit' to end the program "

active = True
while active:
    message = input(prompt)

    if message == 'quit':
        active = False
    else:
        print("We will add "+message+".")

prompt = "\nPizza's Burden: "
prompt += "\nEnter 'quit' to end the program "

active = True
while active:
    message = input(prompt)

    if message == 'quit':
        break
    else:
        print("We will add "+message+".")

#7-8
sandwich_orders = ['A','B','C','D']
finished_sandwiches = []
while sandwich_orders:
    finished_sandwich = sandwich_orders.pop()
    print("I made your " + finished_sandwich.title()+" sandwich")
    finished_sandwiches.append(finished_sandwich)
print("I have finished sandwiches: ")
for finished_sandwich in finished_sandwiches:
    print('\t'+finished_sandwich)

#7-9
print("Pastrami have sold out.")
sandwich_orders = ['A','B','C','D','pastrami','pastrami','pastrami']
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
print(sandwich_orders)

#7-10
places = {}
polling_active = True
while polling_active:
    name = input('\nWhat is your name? ')
    place = input("If you could visit one place in the world,where would you go? ")

    places[name]=place

    repeat = input("Would you like to let another person respond?(yes/no) ")
    if repeat == 'no':
        polling_active = False

print('\n=== Poll Results ===')
for name,place in places.items():
    print(name + " would visit one place is "+ place +'.')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值