#7-4 披萨配料:
代码:
#7-4 披萨配料
"""
mushrooms
pepperoni
extra cheese
"""
while True:
message = 'Which Pizza ingredient would you add?'
message += "\n(Enter 'quit' to end): "
ingredient = input(message)
if ingredient == 'quit':
break;
else:
message = '\nWe will add ' + ingredient + ' in the Pizza. \n'
print(message)
输出:pass
#7-5 电影票:
代码:
#7-5 电影票
while True:
message = 'Dear gentleman or lady, How old are you?'
message += "\n(Enter 'q' to end): "
year = input(message)
if year == 'q':
break;
else:
year = int(year)
if year < 3:
message = 'You are free admission!'
elif year <=12:
message = 'You have to pay 10 dollars for the ticket!'
elif year > 12:
message = 'You have to pay 15 dollars for the ticket!'
print(message+'\n')
输出:pass
#7-7 无限循环:
代码:
#7-7 无限循环
#可以尝试,没什么大碍的
while True:
num = list(range(1, 10**4))
输出:pass
#7-8 熟食店:
代码:
#7-8 熟食店
sandwich_orders = ['Reuben sandwich', 'Club sandwich', 'Doner sandwich']
sandwich_orders.append('Hamburger')
finished_sandwiches = list()
while sandwich_orders:
sandwich = sandwich_orders.pop()
message = 'I made your ' + sandwich + '.'
finished_sandwiches.append(sandwich)
print(message)
while finished_sandwiches:
print(finished_sandwiches.pop())
输出:
I made your Hamburger.
I made your Doner sandwich.
I made your Club sandwich.
I made your Reuben sandwich.
Reuben sandwich
Club sandwich
Doner sandwich
Hamburger
#7-9 五香烟熏牛肉(pastrami)卖完了 :
代码:
#7-9 五香烟熏牛肉(pastrami)卖完了
sandwich_orders = ['Reuben sandwich', 'Club sandwich', 'Doner sandwich']
sandwich_orders.append('Hamburger')
for a in range(0,3):
sandwich_orders.append('pastrami')
message = 'Sorry. We are out of pastrami.\n'
print(message)
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
while sandwich_orders:
print(sandwich_orders.pop())
输出:
Sorry. We are out of pastrami.
Hamburger
Doner sandwich
Club sandwich
Reuben sandwich