Python编程:从入门到实践 动手试一试 7.1-7.10

#7.1 car tental

car = input("What brand of car would you like to rent?")
print("\nLet me see if I can find you a " + car + ".")

#7.2 reservation of diner
number_of_people = input("How many people would you like to come together?")
number_of_people = int(number_of_people)

if number_of_people > 8:
    print("Sorry, there is no vacant table available for you now.")
else:
    print("Congratulation! You can reserve a table for your meal")

#7.3 10 multiple

number = int(input("Please enter a number and I will check if it is the multiple of 10: "))

if number % 2 == 0:
    print("Yes, " + str(number) + " is the multiple of 10")
else:
    print("No, " + str(number) + " is not the multiple of 10")

#7.4 ingredients of pizza

prompt = '\nPlease select the ingredient you want!'
prompt += '\nEnter "quit" when you are finished.'

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

    if ingredient == "quit":
        break
    else:
        print("We will add your " + str(ingredient) + " to your pizza!")

#7.5 tickets of cinema

age = ""
active = True
while age != 'quit':
    age = input('Hello, please enter your age: ')

    if age == 'quit':
        active = False

    elif int(age) < 3:
        print('Your ticket is $0.')
    elif int(age) <= 12:
        print('Your ticket is $10.')
    elif int(age) > 12:
        print('Your ticket is $15.')

#7.6 three ways:

age = ''
active = True
while active:
    age = int(input("Please enter your age: "))
    if age == "quit":
        break
    elif age < 3:
        print("You are free to enjoy the movie")
    elif 3 < age < 12:
        print("Your ticket is $10.")
    else:
        print("Your ticket is $15.")

#7.7 endless loop

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

#7.8 grocery store

sandwich_orders = ['chicken sandwich', 'beef sandwich', 'lamb sandwich', 'pork sandwich']
finished_orders = []
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    print("I made your " + sandwich.title())
    finished_orders.append(sandwich)

print("\nFinished sandwich: ")
for finished_sandwich in finished_orders:
    print(finished_sandwich.title())

#7.9 the pastrami is sold out

sandwich_orders = ['pastrami', 'chicken sandwich', 'beef sandwich',
                   'pastrami', 'lamb sandwich', 'pork sandwich', 'pastrami'
                   ]

print("We're sorry to tell you that the pastrami sandwich is sold out.")
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
    finished_orders = sandwich_orders

print(finished_orders)

#7.10 the dreaming resorts

place_to_go = []
active = True
while active:
    place = input("If you could visit one place in the world, where would you go? : ")
    place_to_go.append(place)

    ask = input("Keep investigating? (yes/no)")
    if ask == 'no':
        break

print(place_to_go)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值