其他分享
首页 > 其他分享> > 用户输入和while循环

用户输入和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 + ".")

标签:sandweich,三明治,用户,while,made,print,input,输入
来源: https://blog.csdn.net/qq_43688114/article/details/89434287