\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 #每循环一次