与用户交互(8)
与用户交互
# 输入: inpurt() 替代品
# 替代品 # 输入 # 阻塞
# e.g 例如 用户名和密码 ↓
username_db = 'nick' pwd_db = '123' username = input('\033[31m请输入你的用户名:') # input让用户输入,与用户交互 pwd = input('\033[41m请输入你的密码:]') if username == username_db and pwd == pwd_db: print('登录成功') else: print('登录失败')
# eval的使用方法
定义:会把引号去掉
升级版(超纲)
import random # 导入随机函数 count = 0 username_db = 'nick' pwd_db = '123' code = random.randint(1000,9999) #随机数字 code = f'{code}{chr(random.randint(97,117))}{chr(random.randint(97,117))}{chr(random.randint(97,117))}' #随机验证码 while count < 3: print(code) # input让用户输入,与用户交互 ↓ username = input('\033[31m请输入你的用户名:\033[m') pwd = input('\033[32m请输入你的密码:\033[m') code_db = input('\033[33m请输入验证码:\033[m') if username == username_db and pwd == pwd_db and code == code_db: print('登录成功,欢迎来到实力至上主义的教室!!!') elif username != username_db and pwd == pwd_db and code == code_db: print('登录失败,啥子!!!用户名都记不得') elif username == username_db and pwd != pwd_db and code == code_db: print('登录失败,啥子!!!密码都能忘') elif username == username_db and pwd == pwd_db and code != code_db: print('登录失败,啥子!!!验证码都看不到') elif username != username_db and pwd != pwd_db and code == code_db: print('用户名和密码都能忘,除了看验证码你还能干嘛?') elif username != username_db and pwd == pwd_db and code != code_db: print('就知道个密码,哎!眼干啥用的验证码都瞅不见!!') elif username == username_db and pwd != pwd_db and code != code_db: print('就知道个账号,有鸡巴用!还能记住啥?') else: print('什么都不记得,你还能干啥') count += 1

浙公网安备 33010602011771号