Python3 实现用户登陆,输入三次密码
不加注释版
#/usr/bin/python3 import readline user = "seven" passwd = "123" username = input("please the enter user:") for i in range(3): password = input("please the enter password:") if password.isdigit(): password = int(password) if username == user and password == passwd: print("logon successfull") break else: print("logon failed") else: print("logon failed")
加注释版
#/usr/bin/python3 import readline#导入readline模块,否则无法移动光标和删除 user = "seven" passwd = "123"#定义账号密码 username = input("please the enter user:")#提示用户输入账号信息 for i in range(3):#如果登陆失败允许重复输入三次 password = input("please the enter password")#提示用户输入密码 if password.isdigit():#判断输入的是否是数字 是则进行下一步 否则返回失败 password = int(password)#赋值定义密码等于输入密码 if username == user and password == passwd:#判断账号和密码是否一致 print("logon successfull")#True break else: print("logon failed")#False else: print("logon failed")#不是数字则返回False
初接触Python 欢迎大家多多提意见