# 四位验证码
"""四位数验证码""" code="" for i in range(4): print(i) index = random.randrange(4) #0-3 中随机取一个数 if index != i and index + 1 != i: code +=chr(random.randint(97,122)) #小写字母 elif index + 1 == i: code +=chr(random.randint(65,90)) #大写字母 else: code +=str(random.randint(1,9)) print(code)
登录写入日志,读取日志
#显示功能界面 def show(): print(" q 退出登录 1 查看登录日志" ) while True: code = input("输入选项:") if code == "q": break elif code == "1": read_log() break else: print("输入错误重新输入") #登录日志查看 import time def write_log(username): """写入日志""" """打开一个文件""" """日志格式 用户名 : 日期 ,登录是否成功""" with open('info', 'a') as f: login_rizhi = "用户名:{} 登录时间: {} ".format(username,time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) f.write(login_rizhi) def read_log(): """读取日子文件""" with open('info','r') as f: while True: line = f.readline() if line == "": break print(line) user_passwd = {"xiao":"123","long":"1234","cui":"34"} def login(): """用户登录 """ """进行判断""" username = input("输入用户名:") if username in user_passwd.keys(): passwd = input("输入密码:") if passwd == user_passwd[username]: print("登录成功") write_log(username) show() else: print("密码错误") else: print("用户名不存在") login()
查看是不是闰年
while True: code=int(input("输入年份:")) if code == 0: break elif (code % 4 == 0 and code % 100 !=0) or code % 400 == 0: print("{} 年时闰年".format(code)) else: print("{} 年不是闰年".format(code))
画五角星
#画五角星 import turtle import time turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) turtle.right(144) turtle.forward(100) time.sleep(2)