帅兰
def func(x, y, z):
with open(x, mode='r+t', encoding='utf-8')as f:
a = f.read()
b = a.replace(y,z)
with open(x, mode='wt', encoding='utf-8')as f1:
f1.write(b)
func('a.txt', '丑', '帅')
import time
while True:
with open('access.log',mode='at',encoding='utf-8')as f:
times = time.strftime("%Y-%m-%d %H:%M:%S")
msg = f'位于{times}帅兰又变帅了\n'
f.write(msg)
time.sleep(5)
import time
with open('access.log', mode='rb') as f:
f.seek(0, 2)
while True:
line = f.readline()
if len(line) == 0:
time.sleep(1)
else:
print(line.decode('utf-8'), end='')
import time
def func(x):
with open(x, mode='rb') as f:
f.seek(0, 2)
while True:
line = f.readline()
if len(line) == 0:
time.sleep(1)
else:
print(line.decode('utf-8'), end='')
func('access.log')
def func1(x):
while True:
with open(x, mode='at', encoding='utf-8')as f1:
times = time.strftime("%Y-%m-%d %H:%M:%S")
mag = f'位于{times}帅兰又变高了\n'
f1.write(mag)
time.sleep(2)
func1('access.log')
def homepage():
while True:
print('''欢迎来到我的认证程序
1、登入
2、注册
3、退出''')
res = input('请输入指令:').strip()
if res == '1':
login()
elif res == '2':
regster()
elif res == '3':
print('已退出')
return
else:
print('请输入正确指令')
def login():
while True:
name = input('请输入用户名:').strip()
pwd = input('请输入密码:').strip()
with open('a.txt', mode='rt', encoding='utf-8')as f:
for i in f:
u, p = i.strip().split(':')
if u == name and p == pwd:
while True:
print('''登入成功
请选择服务:
1、退出''')
z = input('请输入指令').strip()
if z == '1':
print('已退回主界面')
homepage()
else:
print('请输入正确指令')
else:
print('账号密码错误')
def regster():
print('注册功能')
name1 = input('请输入用户名:')
pwd1 = input('请输入密码:')
with open('a.txt', mode='at', encoding='utf-8') as f1:
f1.write(f'{name1}:{pwd1}\n')
print('注册成功自动返回主界面')
homepage()
msg_dic = {
'apple': 10,
'tesla': 100000,
'mac': 3000,
'lenovo': 30000,
'chicken': 10,
}
dic = {}
tag = True
while tag:
wares = input('请输入商品名:').strip()
for i in msg_dic:
if wares == i:
count = input('请输入购买个数:').strip()
if count.isdigit():
count = int(count)
price = count * msg_dic[i]
print('购买成功信息如下', wares, '个数:', count, '价格:', price)
if wares in dic:
dic[wares][0] += count
dic[wares][1] += price
else:
dic.setdefault(wares, [count, price])
print('总数', dic)
break
else:
print('请输入正确的数字')
break
else:
print('请输入正确的商品名称')