`
陈三许
  • 浏览: 7979 次
  • 性别: Icon_minigender_1
文章分类
社区版块
存档分类
最新评论

python笔记5_用户输入和while循环 exercises

阅读更多
###用户输入和while循环#exercise
#餐厅订位
customer=input('How many people have dinner,please?')
customer=int(customer)
if customer>=7:
print("Sorry,there aren't empty table and wecome to you next time!")
else:
print("There are empty table!")
#10的整数倍
number=input("Enter the number, I'll tell you if It can be divided by 10:")
number=int(number)
if number%10==0:
print('It can be divided by 10')
else:
print("It cann't be divided by 10")
#披萨配料
prompt=('Enter some pizza toppings that your wants,and I will respeat it back to you!')
prompt=("Enter 'quit' to end the program.")
while True:
topping=input(prompt)
if topping=='quit':
break
print('\nWe will add '+topping+' to pizza.')
#电影票票价
##测试条件与字符串“quite”相冲突时,可参考以下格式
prompt=('\nEenter your age,and I will respeat it back to you!')
prompt+=('\nEnter "quit" to end the program')
while True:
age=input(prompt)
if age !='quit':
if int(age)<=3:
print("You don't cost money on ticket.")
elif int(age)<=12:
print("You need to cost $10 on ticket.")
else:
print('You need to cost $15 on ticket.')

else:
break
#披萨店(移动列表元素)
pizza_orders=['pepper_pizza','pineapple_pizza','cheese_pizza','beef_pizza']
finished_pizza=[]
while pizza_orders:
making_pizza=pizza_orders.pop()
print('I made your '+making_pizza+'.')
finished_pizza.append(making_pizza)

for pizza in finished_pizza:
print("It's finished pizza:"+pizza)
#奶酪披萨卖完了
pizza_orders=['pepper_pizza','cheese_pizza','pineapple_pizza','cheese_pizza','beef_pizza','cheese_pizza']
finished_pizza=[]
if 'cheese_pizza' in pizza_orders:
print('Sorry,the cheese_pizza is sold!')
while 'cheese_pizza' in pizza_orders:
pizza_orders.remove("cheese_pizza")
while pizza_orders:
making_pizza=pizza_orders.pop()
print('I made your '+making_pizza+'.')
finished_pizza.append(making_pizza)

for pizza in finished_pizza:
print("It's finished pizza:"+pizza)
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics