python编程 从入门到实践 第七章 课后习题(7-1~7-10)

## 动手试一试
# 7-1 汽车租赁
car=input("let me see if i can find you a sybaru.")
print(car)

# 7-2 餐厅订位
food=input("how many people? ")
food=int(food)
if food>8:
    print("there are not enough seats .")
else:
    print("there are seats. ")

# 7-3 10的整数倍
number=input('please enter a number: ')
number=int(number)
if number % 10 == 0:
    print(str(number)+" yes 10 ! ")
else:
    print(str(number)+" no,10 ! ")

##  动手试一试
#7-4 披萨配料
prompt="please enter a kind pizza"
prompt+="\n quit to end :"
while True:
    message = input(prompt)
    if message=="quit":
        break
    else:
        print("we will put the "+message)

# 7-5 电影票
prompt="please enter your age: "
while True:
    message=int(input(prompt))
    if message<3:
        print("your ticket is free. ")
    elif message<=12 and message>=3:
        print("your ticket is $10. ")
    elif message>12:
        print("your ticket is $15. ")
    else:
        print("wrong input")
        break
#7-6 三个出口

#7-7 无限循环
x=1
while x<=3:
    print(x)

##动手试一试
#7—8 熟食店
sandwich_orders=['apple','banana','pear']
finished_sandwiches=[]
while sandwich_orders:
    current_order=sandwich_orders.pop()
    print("i made your "+current_order+' sandwich . ')
    finished_sandwiches.append(current_order)
for finished_sandwich in finished_sandwiches:
    print(finished_sandwich)

# 7-9 五香烟熏牛肉
sandwich_orders=['apple','pastrami','banana','pastrami','pear','pastrami',]
print("the pastrami has been sold out. ")
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
print(sandwich_orders)

# 7-10 梦想的度假胜地

 

你可能感兴趣的:(Python)