标签:生成 不显示 getpass模块 一个 input guess 技术分享 think ogg
1 getpass模块 设置密码不显示明文
用户名和密码输入程序:
import getpass username = input("username:") password = getpass.getpass("password:") print(username,password)
判断登录
_username = "jj" _password = ‘123456‘ username = input("username:") password = getpass.getpass("password:") if _username == username and _password==password: print(‘welcome login..‘) else: print(‘Invalid username or password‘)
猜年龄:
age_jj = 35 guess_age = int(input(‘guess age:‘)) if guess_age == age_jj: print(‘YES‘) elif guess_age > age_jj: print(‘think smaller..‘) else: print("think bogger..")
猜3次 猜对了就退出,错误次数达到3次也退出
while 条件 循环语句 如果提交为真就一直执行
age_jj = 35 count = 0 while count< 3 : guess_age = int(input(‘guess age:‘)) if guess_age == age_jj: print(‘YES‘) break elif guess_age > age_jj: print(‘think smaller..‘) else: print("think bogger..") count += 1
age_jj = 35 count = 0 while count< 3 : guess_age = int(input(‘guess age:‘)) if guess_age == age_jj: print(‘YES‘) break elif guess_age > age_jj: print(‘think smaller..‘) else: print("think bogger..") count += 1 else: print(‘you have tried too many times.. fuck you..‘)
while else"
如果while 的条件为真 就一直执行while 里面的代码
如果while的条件为假 就执行else里面的代码
Python的for循环有两种:
1 利用range()函数生成一个整数序列。
print(type(range(10))) for i in range(10): print(i)
这个序列可以转成列表
print(list(range(10)))
2 for ..in 循环列表,依次把列表中的元素迭代出来
names=[‘michael‘,‘Bob‘,‘Tracy‘] for name in names: print(name)
标签:生成 不显示 getpass模块 一个 input guess 技术分享 think ogg
原文地址:http://www.cnblogs.com/qing-chen/p/7152062.html