用户输入和while循环

第七章

while循环
7-1

cars = input("What kind of car would you like to rent?")
print("Let me see if can find you a " + cars)

7-2

number = input("How many people are there in your party?")
number = int(number)
if number > 8:
    print("There is no empty table")
else:
    print("Come in, please")

7-3

number = input("Please input a number: ")
number = int(number)
if number % 10 == 0:
    print(str(number) + " 是10 的整数倍")
else:
    print(str(number) + "bushi")

7-4

prompt = "\nPlease enter the ingredients you want to add: "
prompt += "\nEnter 'quit' to end the program. "
dosing = ""
while dosing != 'quit':
    dosing = input(prompt)
    if dosing != 'quit':
        print(dosing)

7-5

age = input("请输入你的年龄: ")
age = int(age)
while age < 3:
    print("免费观影")
    break
while age < 12:
    print("10美元")
    break
while age >12:
    print("15美元")
    break

7-6

prompt = "\nPlease enter the ingredients you want to add: "
prompt += "\nEnter 'quit' to end the program. "
while True:
    dosing = input(prompt)
    if dosing == 'quit':
        break
    else:
        print("peilaoshi " + dosing)
age = input("请输入你的年龄: ")
age = int(age)
while age < 3:
    print("免费观影")
    break
if age < 12:
        print("10美元")
else:
        print("15美元")

7-7无限循环

x = 1
while x <= 5:
    print(x)
    break

7-8

sandweich_orders = ['金枪鱼三明治', '印度咖喱鱼排三明治', '酱牛肉番茄三明治']
finished_sandweich = []
while sandweich_orders:
    sanweizhi = sandweich_orders.pop()
    print("I made your tuna: " + sanweizhi)
    finished_sandweich.append(sanweizhi)
print("\nThe following sandweich have been made: ")
for sanweizhi in finished_sandweich:
    print(sanweizhi)
I made your tuna: 酱牛肉番茄三明治
I made your tuna: 印度咖喱鱼排三明治
I made your tuna: 金枪鱼三明治

The following sandweich have been made: 
酱牛肉番茄三明治
印度咖喱鱼排三明治
金枪鱼三明治

7-9

sandweich_orders = ['金枪鱼三明治', 'pastrani', '印度咖喱鱼排三明治', 'pastrani','酱牛肉番茄三明治','pastrani']
print("pastrani yijingmaiwan")
while 'pastrani' in sandweich_orders:
    sandweich_orders.remove('pastrani')
finished_sandweich = []
while sandweich_orders:
    sanweizhi = sandweich_orders.pop()
    print("I made your tuna: " + sanweizhi)
    finished_sandweich.append(sanweizhi)
print("\nThe following sandweich have been made: ")
for sanweizhi in finished_sandweich:
    print(sanweizhi)
pastrani yijingmaiwan
I made your tuna: 酱牛肉番茄三明治
I made your tuna: 印度咖喱鱼排三明治
I made your tuna: 金枪鱼三明治

The following sandweich have been made: 
酱牛肉番茄三明治
印度咖喱鱼排三明治
金枪鱼三明治

7-10

favorite_place = {}
polling_active = True
while polling_active:
    name = input("\nwhat in your name? ")
    place = input("Which place would you like to visit ? ")
    favorite_place[name] = place
    repeat = input("would you like to let anther personrespond?(yes/no)")
    if repeat == 'no':
        polling_active = False
print("\n---places----")
for name,place in favorite_place.items():
    print(name + "would like to trive " + place + ".")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值