设为首页 加入收藏

TOP

python学习第一天 -----2019年4月15日(五)
2019-05-23 16:08:28 】 浏览:72
Tags:python 学习 第一 -----2019年 4月 15日
\Python 3.6.6\python.exe" G:/practise/oldboy/day1/getpass.py
Name:chenjisong
Password:chenjisong123
Welcome user chenjisong login ...

Process finished with exit code

逻辑判断:当输入的值等于变量中存储的值的时候,打印欢迎登陆成功,反之,返回错误的用户名和密码。

多重逻辑判断:

#!/usr/bin/env python 
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: guess.py
@time: 2019/04/16
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
Name_Of_Oldboy = 56
guess_age = int(input("please input your guess number:"))
if guess_age == Name_Of_Oldboy:
print("Yes,you got it.")
elif guess_age > Name_Of_Oldboy:
print("think smaller.")
else:
print("think bigger.")
=====================================================================================
三种判断结果:

1、小于实际数值

"G:\Python 3.6.6\python.exe" G:/practise/oldboy/day1/guess.py
please input your guess number:55
think bigger.

Process finished with exit code 0

2、等于实际数值

"G:\Python 3.6.6\python.exe" G:/practise/oldboy/day1/guess.py
please input your guess number:56
Yes,you got it.

Process finished with exit code 0

3、大于实际数值

"G:\Python 3.6.6\python.exe" G:/practise/oldboy/day1/guess.py
please input your guess number:57
think smaller.

Process finished with exit code 0

第一周-第12章节-Python3.5-while 循环 

while死循环,恒成立:

#!/usr/bin/env python 
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: while.py
@time: 2019/04/16
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
count = 0
while True:
print(count)
count = count + 1
死循环:当条件成立的时候,永久的执行下去的循环,无法跳出循环

当条件成立时候退出循环,否则一直循环下去:
#!/usr/bin/env python 
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: guess.py
@time: 2019/04/16
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
Name_Of_Oldboy = 56

while True:
guess_age = int(input("please input your guess number:"))
if guess_age == Name_Of_Oldboy:
print("Yes,you got it.")
break
elif guess_age > Name_Of_Oldboy:
print("think smaller.")
else:
print("think bigger.")

三次循环计数,如果三次猜不对就退出,如果猜对了立马退出
#!/usr/bin/env python 
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: guess.py
@time: 2019/04/16
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
Name_Of_Oldboy = 56
count = 0
while True:
if count == 3: ####三次计数
break ####错误就退出
    guess_age = int(input("please input your guess number:"))
if guess_age == Name_Of_Oldboy:
print("Yes,you got it.")
break
elif guess_age > Name_Of_Oldboy:
print("think smaller.")
else:
print("think bigger.")
count += 1 ####每循环一次,计数器加1
#!/usr/bin/env python 
#-*- coding:utf-8 _*-
"""
@author:chenjisong
@file: guess.py
@time: 2019/04/16
url:https://www.liaoxuefeng.com
functions:
Software:JetBrains PyCharm 4.5.3
"""
Name_Of_Oldboy = 56
count = 0
while count < 3: #当次数大于3次的时候退出
guess_age = int(input("please input your guess number:"))
if guess_age == Name_Of_Oldboy:
print("Yes,you got it.")
break
elif guess_age > Name_Of_Oldboy:
print("think smaller.")
else:
print("think bigger.")
count += 1 #每循环一次
首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇周末学习笔记——day01(函数,函.. 下一篇数据结构(三):队列

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目