Python学习之路—————day04
今日内容:
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的更多相关文章
- python学习之路---day04
一:元组 元组案例:tuple=("张三","李四","王五","小六","大七",["1 ...
- python学习之路-day2-pyth基础2
一. 模块初识 Python的强大之处在于他有非常丰富和强大的标准库和第三方库,第三方库存放位置:site-packages sys模块简介 导入模块 import sys 3 sys模 ...
- Python学习之路-Day2-Python基础3
Python学习之路第三天 学习内容: 1.文件操作 2.字符转编码操作 3.函数介绍 4.递归 5.函数式编程 1.文件操作 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个 ...
- Python学习之路-Day2-Python基础2
Python学习之路第二天 学习内容: 1.模块初识 2.pyc是什么 3.python数据类型 4.数据运算 5.bytes/str之别 6.列表 7.元组 8.字典 9.字符串常用操作 1.模块初 ...
- Python学习之路-Day1-Python基础
学习python的过程: 在茫茫的编程语言中我选择了python,因为感觉python很强大,能用到很多领域.我自己也学过一些编程语言,比如:C,java,php,html,css等.但是我感觉自己都 ...
- python学习之路网络编程篇(第四篇)
python学习之路网络编程篇(第四篇) 内容待补充
- Python学习之路【第一篇】-Python简介和基础入门
1.Python简介 1.1 Python是什么 相信混迹IT界的很多朋友都知道,Python是近年来最火的一个热点,没有之一.从性质上来讲它和我们熟知的C.java.php等没有什么本质的区别,也是 ...
- python 学习之路开始了
python 学习之路开始了.....记录点点滴滴....
- python学习之路,2018.8.9
python学习之路,2018.8.9, 学习是一个长期坚持的过程,加油吧,少年!
随机推荐
- github 遇到Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts问题解决
刚开始使用github的时候不是很了解,新手一般的都会遇到这个问题Permanently added the RSA host key for IP address '192.30.252.128' ...
- 在Sublime中配置JsFormat
JsFormat配置文件: { // exposed jsbeautifier options "indent_with_tabs": false, // 保留换行符 " ...
- keystone系列三:网关协议
一 静态页面和动态页面 在了解了http协议后,我们知晓,一个web server的本质就是 浏览器发送一个HTTP请求: 服务器收到请求,生成一个HTML文档: 服务器把HTML文档作为HTTP响应 ...
- day95
Linux基本部署配置及常见扩展应用 Linux软件包安装方法 1. 安装: 整个安装过程可以分为以下几步: 1) 取得应用软件:通过下载.购买光盘的方法获得: 2)解压缩文件:一般tar包,都会再做 ...
- windows 命令行操作 Mysql 数据库
1 前言 有接手一个新项目,项目中到了 Mysql 数据库 ,这里总结下 windows 命令行操作 Mysql 数据库. 2 Cmd操作数据库 2.1 连接Mysql服务器,命令如下:(root用户 ...
- 线程GIL锁 线程队列 回调函数
----------------------------------无法改变风向,可以调整风帆;无法左右天气,可以调整心情.如果事情无法改变,那就去改变观念. # # ---------------- ...
- vue 生产环境 background 背景图不显示原因
通常我们使用img标签引入文件,npm run build 打包后 ,因为img为html标签,打包后他的路径是由index.html开始访问的,他走static/img/'图片名'是能正确访问到图片 ...
- Python中的鸡肋多线程
作者:DarrenChan陈驰链接:https://www.zhihu.com/question/23474039/answer/269526476来源:知乎著作权归作者所有.商业转载请联系作者获得授 ...
- 使用 Markdown编辑
作用: 学习笔记,整理日志, 发布日记,杂文,所见所想 撰写发布技术文稿(代码支持) 撰写发布学术论文(LaTeX 公式支持) sublime text3插件 输入 Shift + Ctrl + P, ...
- CentOS 7.2 yum安装LAMP环境
https://www.linuxidc.com/Linux/2016-11/136766.htm 详见以上链接,用yum安装方便省事. 尤其注意,mysql数据要设置远程连接.