python编程 从入门到实践 第七章 动手试一试参考答案 含运行结果-分支(选择结构)、循环语句

print("7-1")
message =  input("let me see if I can find you a: ")
print(message)

#7-2
print("7-2")
message = input("how many persons have lunch:")
message = int(message)
if message > 8:
    print("sorry,no table.")
else:
    print("Yes, we have table.")

 

 

print("7-3")
message = input("please input a number: ")
message =int(message)
if message % 10 == 0:
    print('the right number')
else:
    print('no the number')

 

print('7-4')
prompt = '\n please input some pizza meterial:'
prompt += "\nEnter 'quit' to end the program."
message = " "
while  message != 'quit':
    message = input(prompt)
    #print("we will put " + message + " in the pizza")

    if message !='quit':
        print(message)

 

#7-5
print('7-5')
active =True
while active:
    edg = int(input("please input edg"))
    if edg < 3:
        print('free')

    elif edg >= 3 and edg <=12:
        print('$10')

    else:
        print('$15')

 


print('7-6-1')
active =True
while active:
    edg = input("please input edg")

    if edg == 'quit':
        break

    if int(edg) < 3:
        print('free')

    elif int(edg) >= 3 and int(edg) <=12:
        print('$10')

    else:
        print('$15')

print('7-7')
x = 1
while x <= 5:
    print(x)
print('7-8')
sandwich_orders = ["beef","poke","tomato"]
# 创建空列表
finish_sandwiches = []
#循环,直到列表的元素空了
while sandwich_orders:
    # 函数pop每次以一个的方式从末尾删除元素
    sandwich_order = sandwich_orders.pop()
    # 显示删除的元素
    print("I made your " + sandwich_order)
    #将删除的元素移动到新的列表
    finish_sandwiches.append(sandwich_order)
#输出新列表
print("\nfinish_sandwiche:")
for finish_sandwiche in finish_sandwiches:
    print(finish_sandwiche)

print("7-9")
sandwich_orders = ["beef","poke","tomato","pastrami","pastrami","pastrami"]
print(sandwich_orders)
print("pastrami have been solded out!")
#循环
while 'pastrami' in sandwich_orders:
   sandwich_orders.remove('pastrami')

print(sandwich_orders)

 

print('7-10梦想的度假胜地')
#创建一个空字典
responses = {}
#设置一个标志,指出调查是否继续
polling_active = True
while polling_active:
    name = input("\nWhat is your name?")
    response = input("if you could visit one place in the world, where would you go ?")
#将答案存在字典中,name 是key,response是value,responses{name:response}
    responses[name] = response

#看看是否还有人要参加调查
    repeat = input("would you like to let another person respond?(yes / no)")
    if repeat == 'no':
        polling_active = False

#调查结果,显示结果
print("\n --- Poll Results ---")
for name,responses in responses.items():
    print(name + " want to go " +responses +'.' )

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值