python(0用户登录日志输出)

# Author: Sooele

import time

def show_info():
    print('请输入提示数字,执行相应操作:0.t推出 1查看日志')

def write_logininfo(username):
    with open('logs.txt','w',encoding='utf-8') as file:
        s=f'用户名{username},登录时间:{time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))}'
        file.write(s)
        # print(s)


def read_logininfo():
    with open('logs.txt','r',encoding='utf-8') as file:
        while True:
            line=file.readline()
            if line=='':
                break
            else:
                print(line)

if __name__=='__main__':
    username=input('请输入ss')
    pwd=input('pwd')
    if 'admin'==username and 'admin'==pwd:
        print('登录成功')
        write_logininfo(username)  ##记录日志
        show_info()
        num=int(input('请输入数字'))
        while True:
            if num==0:
                print('推出成功')
                break
            elif num==1:
                print('查看日志')
                read_logininfo()
                num=int(input('请输入数字'))
            else:
                print('输入有误')
                show_info()

    else:
        print('密码不正确')

# print(time.time())
# print(time.localtime(time.time()))
# print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())))