2018-11-21 18:23:56

print('pass语句')
for letter in 'Runoob':
if letter=='o':
pass
else:
print(letter) score = int(input('请输入您的分数:'))
if score >=90:
print('A')
if score >=80 and score<90:
print('B')
if score<80:
print('C')
'以上两端代码的效果相等'
if score>=90:
print('A')
elif score>80:
print('B')
else:
print('C') print('计算1到100的和***************************************************************') sum = 0
n = 1
while n <= 100:
sum = sum + n
n = n + 1
print('1到100的和为:',sum) print('while无线循环***************************************************************')
var = 1
while var == 1:
num = int(input('请输入一个整数:'))
print('您输入的数字为:',num) print('while循环使用else语句***************************************************************')
flag = 1
while (flag):print('欢迎访问菜鸟教程!') print('while循环使用else语句***************************************************************') num =0
while num<5:
print('您输入的数小于5',num)
num = num +1
else:
print('您输入的数大于5',num) print('使用for遍历列表中的数据***************************************************************')
sites = ['Google','Baidu','Taobao','Runoob']
for mysite in sites:
print('在呢:',mysite) print('在列表中找到循环对象后停止***************************************************************')
'如果未找到循环对象提示未找到循环对象,如果已找到循环对象提示已找到循环对象' sites = ['Google','Baidu','Runoob','Taobao']
for i in sites:
if i =='Runoob':
print('菜鸟教程:',i)
break
else:
print('不是菜鸟教程哦:',i) print('用for遍历range()生成的一个数列*******************************************************')
for i in range(5):
print(i) print('用for遍历range()生成的一个指定区间的数列**************************************************')
for ii in range(5,10):
print(ii) print('用for遍历range()生成的一个指定区间、步长的数列*********************************************')
for iii in range(5,10,2):
print(iii) print('用for结合range()和len()遍历一个序列的索引***************************************************')
sites2 = ['Google','Baidu','Runoob','Taobao']
i = 0
for i in range(len(sites2)):
print(i,sites2[i])
i = i+1
else:
print('遍历结束') print('使用range()创建一个列表*********************************************************************')
newlist = list(range(5))
print(newlist) print('break语句跳出for循环体***********************************************************************')
'找到一个字符中的某个字母时跳出循环体'
for letter in 'Runoob':
if letter == 'b':
print('找到了;',letter)
break
else:
print('这不是目标:',letter) print('break语句跳出while循环体*********************************************************************')
'从10开始倒序输出,遇到7时跳出循环体'
i =10
while i <=10:
if i ==7:
print('找到了:',i)
break
else:
print('这不是我要的:',i)
i = i-1 print('continue跳过for循环块中的剩余语句************************************************************')
'遇到Runoob中的o时跳过不输出'
for letter in 'Runoob':
if letter == 'o':
continue
print('我是被忽略的:',letter)
else:
print('我不是被忽略的:',letter) print('continue跳过while循环块中的剩余语句********************************************************888')
'*遇到10、9、、、0中的7时跳过不输出'
i = 10
while i > 0:
i = i - 1
if i ==7:
continue
print('我是被忽略的:',i)
else:
print('我不是被忽略的:',i) '''
循环语句可以有 else 子句,它在穷尽列表(以for循环)或条件变为 false (以while循环)导致循环终止时被执行,但循环被break终止时不执行。
如下实例用于查询质数的循环例子:
''' print('pass是空语句,一般用作占位语句************************************************************')
while True:
pass print('end的应用及使用效果对比*******************************************************************')
for i in range(5):
print(i) for i in range(5):
print(i,end='') for i in range(5):
print(i,end=' ') for i in range(5):
print(i,end=',')

17-Python3 循环语句的更多相关文章

  1. Python3 循环语句

    Python3 循环语句 转来的  很适合小白   感谢作者   Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中wh ...

  2. 【python】Python3 循环语句

    [python]几种常见的循环 注意:如果涉及到程序中print语句中含有%d,%s,那么要在脚本最开始写语句:#coding=utf-8,才能够正常输出想要的数字或者字符串. Python3 循环语 ...

  3. Python3循环语句

    Python3 循环语句 Python中的循环语句有for和while. 循环语句控制结构图如下: 一.while循环 ①循环结构 while 判断条件: 执行语句 实例: n = int(input ...

  4. python013 Python3 循环语句

    Python3 循环语句本章节将为大家介绍Python循环语句的使用.Python中的循环语句有 for 和 while.Python循环语句的控制结构图如下所示: while 循环Python中wh ...

  5. python3循环语句while

    Python的循环语句有for和while语句,这里讲while语句. Python中while语句的一般形式: while 条件判断 : 语句 需要注意冒号和缩进.另外,注意Python中没有do. ...

  6. Python3 循环语句(十)

    Python中的循环语句有 for 和 while. Python循环语句的控制结构图如下所示: while 循环 Python中while语句的一般形式: while 判断条件: 语句 同样需要注意 ...

  7. (四)Python3 循环语句——for

    for循环的一般格式如下: for <variable> in <sequence>: <statements> else: <statements> ...

  8. (三)Python3 循环语句——while

    while语句的一般形式: while 判断条件: 语句 同样需要注意冒号和缩进.另外,在 Python 中没有 do..while 循环. 以下实例使用了 while 来计算 1 到 100 的总和 ...

  9. 17.for循环语句

    for循环: 语法: for(表达式1;表达式2;表达式3){ java语句; } 表达式1是最初始化表达式:最先执行,只执行一次 表达式2必须是boolean 类型的表达式.结果为ture或者fal ...

  10. Python系列:三、流程控制循环语句--技术流ken

    Python条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非 ...

随机推荐

  1. WordOperate

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  2. ie9 form submit 请求参数问题替代办法

    //隐藏表单 <input id="hdPeriod" name="period" type="hidden" value=" ...

  3. Vue 数据响应式原理

    Vue 数据响应式原理 Vue.js 的核心包括一套“响应式系统”.“响应式”,是指当数据改变后,Vue 会通知到使用该数据的代码.例如,视图渲染中使用了数据,数据改变后,视图也会自动更新. 举个简单 ...

  4. Hive之变量和属性

    首先看一下hive cli工具对于变量的定义规定的几项功能: $ bin/hive -h usage: hive -d,--define <key=value>          Vari ...

  5. python3写入csv文件时中文为乱码

    今天修改李万的爬虫时把页面上的中文写入csv文件时,中文总是乱码.通过上网搜索得到解决.解决的办法是打开文件是需加参数 encoding='utf-8-sig' .感谢博客园的菜鸟Alex.他相关博客 ...

  6. monit安装配置

    环境centos5(32bit),monit-5.17.1,下载地址 https://bitbucket.org/tildeslash/monit/downloads/ 1.tar zxvf moni ...

  7. saltstack安装配置使用记录

    安装 参考 http://docs.saltstack.cn/topics/installation/index.html#installation 选择对应的OS 配置 环境如下: master:1 ...

  8. [knowledge] netmap

    900MHz的单核处理10GB的包收/发. netmap has been implemented in FreeBSD and Linux and Gbit/s network adapters. ...

  9. LeetCode 812 Largest Triangle Area 解题报告

    题目要求 You have a list of points in the plane. Return the area of the largest triangle that can be for ...

  10. Delphi 打开网址

    1. 通过iexplore.exe打开:ShellExecute(0, 'open', 'iexplore.exe', PChar('http://www.100xuekao.com'), '', S ...