import time
def show_info():
print('输入提示数字,执行相应操作:0-退出 1-查看登陆日志:')
def write_loginfo(username):
with open('log.txt','a') as file:
s = f'用户{username},登陆时间:{time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))}\n'
file.write(s)
file.write('\n')
def read_loginfo():
with open('log.txt','r') as file:
while True:
line = file.readline()
if line == '':
break
else:
print(line,end='')
if __name__ == '__main__':
'''print(time.time()) #得到秒,如:1651741732.5487921
print(time.localtime(time.time())) #将s转为时间格式 如:time.struct_time(tm_year=2022, tm_mon=5, tm_mday=5, tm_hour=17, tm_min=8, tm_sec=52, tm_wday=3, tm_yday=125, tm_isdst=0)
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) #得到正常的时间:2022-05-05 17:11:41
'''
user_name = input('请输入用户名:')
user_pwd = input('请输入密码:')
if user_name == 'abc' and user_pwd == '123':
print('登陆成功!')
write_loginfo(user_name)
show_info()
num = int(input('请输入操作的数字:'))
if num == 0:
print('退出成功')
elif num == 1:
print('查看登陆日志')
read_loginfo()
num = int(input('输入操作数字:'))
else:
print('您输入的数字有误!')
show_info()
else:
print('对不起,用户名或密码不正确!')
def find_answer(question):
with open('replay.txt','r',encoding='UTF-8') as file:
while True:
line = file.readline()
if not line:
break
keyword = line.split('|')[0]
replay = line.split('|')[1]
if keyword in question:
return replay
return False
if __name__ == '__main__':
question = input('Hi,您好,请问您有啥问题呢?')
while True:
if question == 'bye':
break
replay = find_answer(question)
if not replay:
question = input('我不清楚您问的是啥,你可以提问关于订单、物流、账户、支付问题!')
else:
print(replay)
question = input('您还可以继续问关于订单、物流、账户、支付的问题(退出请输入bye!)')
print('再见!')