Python 标准模块 设置密文密码
Import getpass
语法写法:password=getpass.getpass("password:")#密文
#Author :Davial chan
#import getpass#调出模块 getpass
"""_username='chen'
_password='123123'
username=input("username:")
#password=getpass.getpass("password:")#密文
password=input("password:")
if _username == username and _password == password:
print ("欢迎%s登录"%(username))
else
print("用户名或者密码错误")"""
"""
_username="chen" #这里“和'没区别
_password="123123"
username=input("username:")
password=input("password:")
if _username==username and _password==password:
#print("欢迎亲爱的%s登录"%(username)) #s表示占位符,下面使用了{}的链接格式
#对应.format()
print("欢迎亲爱的{}登录" .format(username)) #if *****: else: 的格式
else:
print("用户名或密码错误")
#强制缩进 缩进有上下级关系,也可以说是子集的关系。父集顶格写
print("haha")"""
——————————————
4.if 语句
if 语句后面要加: 并且缩进,pycharm会自动缩进。
if 可以嵌套 if
elif else
while 语句,一般设置计数 while 条件后面执行
else 条件不成立执行
for 语句 例如:for i in range(0,10,3) 从0 开始,步长为3 555猜年龄的小游戏代码
guess_age_of_chen=int("23")
count=0
while count <4:
guess_age=int(input("guess age:"))
if guess_age_of_chen==guess_age:
print("恭喜你猜对了")
break
elif guess_age_of_chen>guess_age:
print("你猜小了")
else:
print("你猜大了")
count+=1
if count==4:
guess_countinue=input("你还想继续吗?(输入n即可以退出)")
if guess_countinue!="n":
count=0
else:
print("谢谢参与,再见")
#else:
#print("你的机会用完了")
========= age_of_chen=int("23")
for i in range(4): #i是临时变量
guess_age = int(input("guess age:"))
if age_of_chen == guess_age:
print("恭喜你你猜对了")
break
elif age_of_chen > guess_age:
print("你猜小了")
else:
print("你猜大了")
else:
print("sorry you have failed")