python input and while循环
2018-04-01 11:30
155 查看
#7-2 餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过 8 人,就打印一条消息,指出没有空桌;否则指出有空桌。
#中添加这种配料。
#7-7 无限循环 :编写一个没完没了的循环,并运行它(要结束该循环,可按 Ctrl +C ,也可关闭显示输出的窗口)。
#表 sandwich_orders ,对于其中的每种三明治,都打印一条消息,如 I made your tuna sandwich ,并将其移到列表 finished_sandwiches 。所有三明
#治都制作好后,打印一条消息,将这些三明治列出来。
#7-9 五香烟熏牛肉( pastrami )卖完了 :使用为完成练习 7-8 而创建的列表 sandwich_orders ,并确保 'pastrami' 在其中至少出现了三次。在程序开头附近添加
#这样的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个 while 循环将列表 sandwich_orders 中的 'pastrami' 都删除。确认最终的列
#表 finished_sandwiches 中不包含 'pastrami' 。
dinnerNums = input("how many people will go to dinner?") if int(dinnerNums)>8: print("sorry, there is no enough disk") else: print('ok,please come!')#7-4 比萨配料 :编写一个循环,提示用户输入一系列的比萨配料,并在用户输入 'quit' 时结束循环。每当用户输入一种配料后,都打印一条消息,说我们会在比萨
#中添加这种配料。
while True: message = input("what do you want in you peasa?") if(message == 'quit'): break else: print("OK , "+message +' add to peasa')
#7-7 无限循环 :编写一个没完没了的循环,并运行它(要结束该循环,可按 Ctrl +C ,也可关闭显示输出的窗口)。
number = 10 while (number%2==0): print(number) number +=2#7-8 熟食店 :创建一个名为 sandwich_orders 的列表,在其中包含各种三明治的名字;再创建一个名为 finished_sandwiches 的空列表。遍历列
#表 sandwich_orders ,对于其中的每种三明治,都打印一条消息,如 I made your tuna sandwich ,并将其移到列表 finished_sandwiches 。所有三明
#治都制作好后,打印一条消息,将这些三明治列出来。
sandwich_orders = ['beef','va','meet'] finished_sandwiches = [] while sandwich_orders: sandwich = sandwich_orders.pop() print("I made your "+sandwich+" sandwich ") finished_sandwiches.append(sandwich) for sandwich in finished_sandwiches: print(sandwich)
#7-9 五香烟熏牛肉( pastrami )卖完了 :使用为完成练习 7-8 而创建的列表 sandwich_orders ,并确保 'pastrami' 在其中至少出现了三次。在程序开头附近添加
#这样的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个 while 循环将列表 sandwich_orders 中的 'pastrami' 都删除。确认最终的列
#表 finished_sandwiches 中不包含 'pastrami' 。
sandwich_orders = ['beef',"pastrami"'va',"pastrami",'meet',"pastrami"] print("pastrami sandwich sold out") while 'pastrami' in sandwich_orders: sandwich_orders.remove("pastrami") for sandwich in finished_sandwiches: print(sandwich)
相关文章推荐
- python语言if判断,for,while循环,自编的小例子,规范版
- 笨方法学Python 习题 33: While 循环
- Python input and output
- Python 3基础教程5-while循环语句
- python-----运算符及while循环
- Python while循环语法
- python3 - while循环控制语句
- Python基础入门-While循环
- python中如果在while循环中return会导致循环中断
- python笔记5 - 字符串格式化表达式,while语句嵌套,for循环,break,continue,死循环
- Python学习日志 - 7.用户输入和while循环(习题解答)
- The Python Tutorial 7——Input and Output
- 笨办法学Python习题33:while循环
- 零基础学python-12.1 while循环
- python for和while循环详解
- 全面解析Python的While循环语句的使用方法
- python中for、while循环、if嵌套的使用
- python学习:while循环,输出1到10,除了7
- 用户输入和while循环(python)
- Python While 循环语句