python入门-WHILE循环
1 使用while循环
current_number=
while current_number <= :
print(current_number)
current_number +=
2 让用户选择退出
prompt = "tell me somthing, and i will repeat it back to you"
prompt = "\nEnter 'quit' to end the program" message = ""
while message != 'quit':
message=input(prompt) if message!='quit':
print(message)
3 使用标志
prompt = "tell me somthing, and i will repeat it back to you"
prompt = "\nEnter 'quit' to end the program" active = True
while active:
message = input(prompt) if message == 'quit':
active = False
else:
print(message)
4 使用break退出循环
prompt = "\nPlease enter the name of a city you have visited:"
prompt += "\n(enter 'quit' when you are finished.)" while True:
city = input(prompt) if city == 'quit':
break
else:
print("I'd love to go to" + city.title() + "!")
5 在循环中使用continue
current_number =
while current_number < :
current_number +=
if current_number % ==:
continue print(current_number)
6 使用while循环来处理列表和字典
unconfirmed_users = ['alice','brian','candace']
confirmed_users = [] while unconfirmed_users:
current_user = unconfirmed_users.pop() print("verifying user:" + current_user.title())
confirmed_users.append(current_user) print("\n the following users have been confirmed:")
for confirmed_user in confirmed_users:
print(confirmed_user.title())
7 删除特定的列表元素
pets = ['dog','cat','dog','goldfish','cat','rabbit','cat']
print(pets) while 'cat' in pets:
pets.remove('cat') print(pets)
8使用用户输入来填充字典
responses = {}
polling_active = True
while polling_active:
name = input("\n what is your name?")
response = input("which mountain would you like to climb someday")
responses[name] = response
repeat = input("would you like to let another person respond?(yes or no")
if repeat == 'no':
polling_active = False
print("\n --poll results--")
for name,response in responses.items():
print(name + "would like to climb" + response + ".")
python入门-WHILE循环的更多相关文章
- python入门10 循环语句
两种循环: 1 for in 2 while #coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 循环语句 ...
- 05 . Python入门值循环语句
一.Python循环语句 程序一般情况下是按照顺序执行的 编程语言提供了各种控制结构,允许更复杂的执行路径 Python中的循环语句有for和while但没有do while 循环语句允许我们执行一个 ...
- Python入门9 —— 循环
一:问号三连 1.什么是循环? 循环就是重复做一件事 2.为何要用循环? 为了让计算机能够像人一样去重复做事情 3.如何用循环 while循环,又称之为条件循环 for循环 二:循环 1.while循 ...
- Python入门-分支循环结构
编写代码的过程中,除了基本的变量,数据类型,在实际开发中,大量代码是根据判断条件,进而选择不同的的向前运行方式. 这些向前的运行方式基本分为两种:分支结构,循环结构 1.分支结构 if单分支结构 # ...
- python入门(11)条件判断和循环
python入门(11)条件判断和循环 条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: ag ...
- python入门学习:6.用户输入和while循环
python入门学习:6.用户输入和while循环 关键点:输入.while循环 6.1 函数input()工作原理6.2 while循环简介6.3 使用while循环处理字典和列表 6.1 函数in ...
- Python趣味入门5:循环语句while
跟着小牛叔,找准正确编程入门姿势,每天只要阅读10分钟. 任何语言都有循环语句,在Python里循环更是变化无穷,有基本的循环,有循环else语句,引伸出来的还有迭代器.推导式,咱们先学习最简单的一种 ...
- 大爽Python入门教程 3-3 循环:`for`、`while`
大爽Python入门公开课教案 点击查看教程总目录 for循环 可迭代对象iterable 不同于其他语言. python的for循环只能用于遍历 可迭代对象iterable 的项. 即只支持以下语法 ...
- 大爽Python入门教程 1-3 简单的循环与判断
大爽Python入门公开课教案 点击查看教程总目录 这里只初步认识下循环和判断,以便于我们去实现一些简单的计算. 循环和判断的详细知识和细节,我们将在后面的章节(大概是第三章)展开阐述. 1 初步了解 ...
随机推荐
- 利用WebApplicationInitializer配置SpringMVC取代web.xml
对于Spring MVC的DispatcherServlet配置方式,传统的是基于XML方式的,也就是官方说明的XML-based,如下: <servlet> <servlet-na ...
- HDU 2072 单词数 详细解答
题目 单词数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- Elasticsearch 索引的全量/增量更新
Elasticsearch 索引的全量/增量更新 当你的es 索引数据从mysql 全量导入之后,如何根据其他客户端改变索引数据源带来的变动来更新 es 索引数据呢. 首先用 Python 全量生成 ...
- harbor helm 仓库使用
harbor 已经支持helm 私服仓库了,还是比较方便的 安装 下载在线安装包 wget https://storage.googleapis.com/harbor-releases/release ...
- How Distributed Outer Joins on PostgreSQL with Citus Work
转自: https://docs.citusdata.com/en/v7.5/articles/outer_joins.html SQL is a very powerful language for ...
- 【转】Linux的五个查找命令:find,locate,whereis,which,type
原文网址:http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html 最近,我在 ...
- spring boot 项目文件结构
启动类建议放在RootPackage的原因: 根据SpringBoot的内置实现,Spring默认从@ComponentScan注解所在的位置开始向后扫描,也就是说,只要我们将组件放在启动类所在的Ro ...
- Angular 4 组件的生命周期
1.组件的生命周期
- Microsoft Dynamics CRM 2011 如何导入组织
一.首先备份数据库,还原数据库(前面SQL server 2008数据库的备份与还原(转)已经说明),这里就不说明了. 二.怎么删除组织? 先要在组织管理器里禁用组织,然后删除组织,再从数据库里删除. ...
- SqlBulkCopy(批量复制)使用方法
SqlBulkCopy提供了一种将数据复制到Sql Server数据库表中高性能的方法.SqlBulkCopy 包含一个方法 WriteToServer,它用来从数据的源复制数据到数据的目的地. Wr ...