网络编程
位置:首页>> 网络编程>> Python编程>> python实操案例练习(八)

python实操案例练习(八)

作者:是数学系的小孩儿  发布时间:2021-12-17 05:51:45 

标签:python,实操,案例,练习

python实操案例练习(八)

任务1、记录用户登录日志

import time
def show_info():
? ? print('输入提示数字,执行相应操作:0退出,1查看登录日志')
# 记录日志
def write_logininfo(username):
? ? with open('log.txt','a')as file:
? ? ? ?s=f'用户名{username},登录时间:{time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))}'
? ? ? ?file.write(s)
? ? ? ?file.write('\n')
?#读取日志
?def read_logininfo():
? ? ?with open('log.txt','r')as file:
? ? ? ? ?while True:
? ? ? ? ? ? ?line=file.readline()
? ? ? ? ? ? ?if line==' ':
? ? ? ? ? ? ? ? ?break
? ? ? ? ? ? ?else:
? ? ? ? ? ? ? ? ?print(line,end='\t')
if __name__ == '__main__':
? ? username=input('请输入用户名:')
? ? pwd=input('请输入密码:')
? ? 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()
? ? ? ? ? ? ? ? num = int(input('输入操作数字:'))
? ? else:
? ? ? ? print('对不起,用户名或密码不正确!!!')
? ? '''print(time.time()) ? ?#秒
? ? print(time.localtime(time.time()))
? ? print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))'''

任务2、模拟淘宝客服自动回复

python实操案例练习(八)

python实操案例练习(八)

python实操案例练习(八)

来源:https://blog.csdn.net/qq_51082388/article/details/122774529

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com