1 getpass模块 设置密码不显示明文
用户名和密码输入程序:
import getpassusername = 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 = 35guess_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
while 条件 循环语句 如果提交为真就一直执行
age_jj = 35count = 0while 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 = 35count = 0while 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 += 1else: print('you have tried too many times.. fuck you..')
while else"
如果while 的条件为真 就一直执行while 里面的代码
如果while的条件为假 就执行else里面的代码
for
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)