《Python编程 从入门到实践》第七章课后习题

7-1

car = input("What kind of car would you like to lease? \n")
print("Let me see if I can find you a " + car)

7-2

user_num = input("How many people would like to have dinner?\n")
if int(user_num) > 8:
    print("There is no vacant tables.")
else:
    print("Here is a vacant table.")

7-3

num = input("Please input a number.\n")
if int(num) % 10:
    print("It is not divisible by 10.")
else:
    print("It is divisible by 10.")

7-4

while True:
    ingredient = input('Please input an ingredient of pizza, or input "quit".\n')
    if(ingredient == 'quit'):
	break
    else:
	print("I would add " + ingredient +" to the pizza.")

7-5

while True:
    age = input('How old are you?\n')
    if int(age) < 3:
	print("Free.")
    elif int(age) > 12:
	print("15 dollars, please.")
    else:
	print("10 dollars, please.")

7-6

# use condition testing
age = input('How old are you?\n')
while age != "quit":
    if int(age) < 3:
        print("Free.")
    elif int(age) > 12:
        print("15 dollars, please.")
    elif int(age) >= 3 and int(age) <= 12:
        print("10 dollars, please.")
    age = input('How old are you?\n')
# use variable "active"
active = 1
while active:
    age = input('How old are you?\n')
    if age == "quit":
	active = 0
    else:
	if(int(age) < 3):
       	    print("Free.")
	elif(int(age) > 12):
	    print("15 dollars, please.")
	else:
	    print("10 dollars, please.")
# use "break" statement
active = 1
while active:
    age = input('How old are you?\n')
    if age == "quit":
	break
    if(int(age) < 3):
	print("Free.")
    elif(int(age) > 12):
	print("15 dollars, please.")
    else:
	print("10 dollars, please.")
7-7
while True:
    print("Gosick_Geass_Gate")

7-8

sandwich_orders = ['pepperoni', 'durian', 'bacon']
finished_sandwiches  = []
for order in sandwich_orders:
    print("I made your " + order +" sandwich. ")
    finished_sandwiches.append(order)
print(finished_sandwiches)

7-9

sandwich_orders = ['pepperoni', 'pastrami', 'durian', 'pastrami','bacon', 'pastrami']
print("Pastrami has sold out. ")
finished_sandwiches  = []
for order in sandwich_orders:
    if order == 'pastrami':
	continue
    print("I made your " + order +" sandwich. ")
    finished_sandwiches.append(order)
print(finished_sandwiches)

7-10

places = []
while True:
    place = input("If you could visit one place in the world, where would you go?\n")
    if place == "quit":
    	break
    places.append(place)
for place in places:
    print(place)
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值