今日内容:

1、 循环语句

1.1 if判断

1.2 while循环

1.3 for循环

一、if判断

语法一:

if 条件

代码块1

代码块2

代码块3

# 例:

sex='female'

age=18

height=1.70

weight=50

is_beautiful=True

if sex=='female' and age > 16 and age < 20 and is_beautiful:

print('开始表白。。')

'''

'''

法二:

if 条件:

代码块1

代码块2

代码块3

else:

代码块1

代码块2

代码块3

'''

'''

sex='female'

age=18

height=1.70

weight=50

is_beautiful=True

if sex=='female' and age > 16 and age < 20 and is_beautiful:

print('开始表白。。')

else:

print('阿姨好....')

print('other code1')

print('other code2')

print('other code3')

'''

'''

语法三:

if 条件1:

if 条件2

代码1

代码2

代码3

代码4

else:

'''

'''

sex = 'female'

age = 18

height = 1.85

weight = 100

is_beautiful = True

is_sucess=True

if sex == 'female' and age > 16 and age < 20 \

and is_beautiful and height < 1.80 and height>1.60:

print('开始表白。。')

if is_sucess:

print('在一起')

else:

print('byebye')

else:

print('阿姨好....')

print('other code1')

print('other code2')

print('other code3')

'''

'''

语法四:

if 条件1:

代码1

代码2

代码3

代码4

elif 条件2:

代码1

代码2

代码3

代码4

elif 条件3:

代码1

代码2

代码3

代码4

else:

代码1

示例:

如果:成绩>=90,那么:优秀

如果成绩>=80且<90,那么:良好

如果成绩>=70且<80,那么:普通

其他情况:很差

score = input('请输入分数》》》')

score = int(score)

if score > 90:

print('优秀')

elif score >=80 :

print('良好')

elif score >=70 :

print('普通')

else:

print('很差')

'''

二、while循环'''

语法:

while 条件:

代码1

代码2

代码3

'''

'''

结束循环的方式:

方式1:在条件改为FALSE时不会立即结束循环,

而是在下次条件判断是结束

tag = True

while tag:

name = input('please input your name')

pwd = input('please input your password')

if name == 'king' and pwd == '123':

print('login sucessful')

tag = False

else:

print('username or password err0')

print('>>>>>')# 循环结束后依然会执行

'''

'''

方式2:while+break

break 一定要放在循环体内部,一旦循环结束下面将不执行

'''

'''

while True:

name = input('please input your name')

pwd = input('please input your password')

if name == 'king' and pwd == '123':

print('login sucessful')

break

else:

print('username or password err0')

print('>>>>>')

print('>>>>>')

'''

'''

方式三:

while+continue:结束本次循环,直接进入下次循环

'''

'''

示例1:

count = 1

while count < 6:# count=6

if count == 4:

count +=1

continue

print(count)

count+=1

'''

# 示例2:

'''

while True:

name = input('please input your name')

pwd = input('please input your password')

if name == 'king' and pwd == '123':

print('login sucessful')

break

else:

print('username or password err0')

'''

'''

while + else

while 条件:

代码1

代码2

else:

在循环结束后,并且只有在while在没break打断的情况下才会执行

'''

'''

while True:

name = input('please input your name: ')

pwd = input('please input your password: ')

if name == 'egon' and pwd == '123':

print('login successful')

break

else:

print('username or password error')

print('===>>>>>')

print('===>>>>>')

'''

三、for循环

# for循环的强大之处在于循环取值

l=['a','b','c','d','e']

# i=0

# while i < len(l):

# print(l[i])

# i+=1

# for x in l: # x='b'

# print(x)

# dic={'name':'egon','age':18,'gender':'male'}

# for x in dic:

# print(x,dic[x])

#for + break

# nums=[11,22,33,44,55]

# for x in nums:

# if x == 44:

# break

# print(x)

#for + continue

# nums=[11,22,33,44,55]

# for x in nums:

# if x == 22 or x == 44:

# continue

# print(x)

#for + else

# names=['egon','kevin1111_dsb','alex_dsb','mac_dsb']

#

# for name in names:

# if name == 'kevin_dsb':

# break

# print(name)

# else:

# print('======>')

#for+ range()

'''

# range的用法

>>> range(1,5)

[1, 2, 3, 4]

>>> for i in range(1,5):

... print(i)

...

1

2

3

4

>>> range(1,5,1)

[1, 2, 3, 4]

>>> range(1,5,2) # 1 3

[1, 3]

'''

# for i in range(5): # 0 1 2 3 4

# print(i)

#for嵌套

for i in range(3):

for j in range(4):

print(i,j)

for i in [0,1,2]: # i=1

for j in [0,1,2,3]: # j=1

print(i,j)

'''

0 0

0 1

0 2

0 3

1 0

1 1

1 2

1 3

2 0

2 1

2 2

2 3

'''

Python学习之路—————day04的更多相关文章

  1. python学习之路---day04

    一:元组 元组案例:tuple=("张三","李四","王五","小六","大七",["1 ...

  2. python学习之路-day2-pyth基础2

    一.        模块初识 Python的强大之处在于他有非常丰富和强大的标准库和第三方库,第三方库存放位置:site-packages sys模块简介 导入模块 import sys 3 sys模 ...

  3. Python学习之路-Day2-Python基础3

    Python学习之路第三天 学习内容: 1.文件操作 2.字符转编码操作 3.函数介绍 4.递归 5.函数式编程 1.文件操作 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个 ...

  4. Python学习之路-Day2-Python基础2

    Python学习之路第二天 学习内容: 1.模块初识 2.pyc是什么 3.python数据类型 4.数据运算 5.bytes/str之别 6.列表 7.元组 8.字典 9.字符串常用操作 1.模块初 ...

  5. Python学习之路-Day1-Python基础

    学习python的过程: 在茫茫的编程语言中我选择了python,因为感觉python很强大,能用到很多领域.我自己也学过一些编程语言,比如:C,java,php,html,css等.但是我感觉自己都 ...

  6. python学习之路网络编程篇(第四篇)

    python学习之路网络编程篇(第四篇) 内容待补充

  7. Python学习之路【第一篇】-Python简介和基础入门

    1.Python简介 1.1 Python是什么 相信混迹IT界的很多朋友都知道,Python是近年来最火的一个热点,没有之一.从性质上来讲它和我们熟知的C.java.php等没有什么本质的区别,也是 ...

  8. python 学习之路开始了

    python 学习之路开始了.....记录点点滴滴....

  9. python学习之路,2018.8.9

    python学习之路,2018.8.9, 学习是一个长期坚持的过程,加油吧,少年!

随机推荐

  1. 移走mysql data目录,及常见mysql启动问题

    一般mysql安装在/usr/local/下,现以将/usr/local/mysql/data目录移动到/home/mysql下为例 首先保证/home/mysql目录是存在的,本例中使用了mysql ...

  2. Luogu P1776 宝物筛选_NOI导刊2010提高(02)(多重背包模版)

    传送门 多重背包板子题, 多重背包就是每种东西有好几个,可以把它拆分成一个一个的01背包 优化:二进制拆分(拆成1+2+4+8+16+...) 比如18=1+2+4+8+3,可以证明18以内的任何数都 ...

  3. jvm调优-从eclipse开始

    一.概述 什么是jvm调优呢?jvm调优就是根据gc日志分析jvm内存分配.回收的情况来调整各区域内存比例或者gc回收的策略:更深一层就是根据dump出来的内存结构和线程栈来分析代码中不合理的地方给予 ...

  4. ADO.NET 中可以发送包含多个SQL语句的批处理脚本到SQL Server,但是用MySQL的ODBC驱动不行

    众所周知,我们在ADO.NET中可以使用NuGet包System.Data.SqlClient来操作SQL Server,并且ADO.NET是支持向SQL Server发送包含多个SQL语句的批处理脚 ...

  5. 体验usually.js的管道函数——pipe函数

    体验usually.js的管道函数——pipe函数 usually.js 是一个面向现代 Web 开发的 JavaScript 函数库,基于 ES6 开发.最新版本2.4.1,最新版本usually. ...

  6. Django Rest framework基础使用之Request/Response

    1.Request restframework提供了一个Request对象(rest_framework.request.Request) Request对象继承了Django默认的HttpReque ...

  7. SQL SERVER按多字段查找重复的数据并删除只保留一条

    由于一次操作失误,给表中插入了多条重复的数据,所以就需要删除重复的数据只保留一条,一时想不到好方法,各种查资料,终于找到了,特意写到这里,方便以后自己用~ 查询: select A.n_PatentI ...

  8. C#中委托,匿名函数,lamda表达式复习

    一.委托 1.就给类比较,类用class声明,委托用delegate声明. 2.委托要指向一个真正的方法. 3.委托的签名,要和指向的方法一样. //1.声明一个委托 public delegate ...

  9. Python学习第十一篇——for 的本质及如何正确修改列表

    假如现在有一个列表:magicians_list = ['mole','jack','lucy'],现在想通过一个函数来实现,在列表的每个元素前面加上“the Great”的字样.现在通过一个函数来实 ...

  10. iOS原生实现二维码拉近放大

    http://www.cocoachina.com/ios/20180416/23033.html 2018-04-16 15:34 编辑: yyuuzhu 分类:iOS开发 来源:程序鹅 8 300 ...