import time
def outter(func):
def wrapper(*args,**kwargs):
t = time.strftime('%Y-%m-%d %H:%M:%S')
with open('log.txt', mode='at', encoding='utf-8') as f:
log_data=f'{t} {func.__name__} run \n'
f.write(log_data)
res = func(*args, **kwargs)
return res
return wrapper
@outter
def f1():
pass
f1()
f1()
f1()
f1()
f1()
str1='aberv,b'
str1_iterator = str1.__iter__()
while True:
try:
res= str1_iterator.__next__()
print(res)
except StopIteration:
break
l1=[1,2,3,4]
l1_iterator = l1.__iter__()
while True:
try:
res1=l1_iterator.__next__()
print(res1)
except StopIteration:
break
tu1=(1,2,3,4)
tu1_iterator=tu1.__iter__()
while True:
try:
res2=tu1_iterator.__next__()
print(res2)
except StopIteration:
break
d1={'egon':111,'alex':222,'ayca':333}
d1_iterator =d1.__iter__()
while True:
try:
res3=d1_iterator.__next__()
print(res3)
except StopIteration:
break
s1={'egon',1,4,6,'aaa'}
s1_iterator=s1.__iter__()
while True:
try:
res4=s1_iterator.__next__()
print(res4)
except StopIteration:
break
with open ('log.txt','r',encoding='utf-8') as f:
f_iterator=f.__iter__()
while True:
try:
res5=f_iterator.__next__()
print(res5)
except StopIteration :
break
def my_range(start,stop,step):
while start<stop:
yield start
start+=step
g=my_range(1,5,2)
print(g)
res1=next(g)
print(res1)
res2=next(g)
print(res2)
==================== 本周选做作业如下 ====================
编写小说阅读程序实现下属功能
0 账号注册
1 登录功能
2 充值功能
3 阅读小说
2.1、账号注册
- 针对文件db.txt,内容格式为:"用户名:密码:金额" 完成注册功能
2.2、充值功能
{"0":{"0":["倚天屠狗记.txt",3],"1":["沙雕英雄转.txt",10]},"1":{"0":["令人羞耻的爱.txt",6],"1":["二狗的妻子与大草原的故事.txt",5]},}
3.1、用户登录成功后显示如下内容,根据用户选择,显示对应品类的小说编号、小说名字、以及小说的价格
"""
0 玄幻武侠
1 都市爱情
2 高效养猪36技
"""
3.2、用户输入具体的小说编号,提示是否付费,用户输入y确定后,扣费并显示小说内容,如果余额不足则提示余额不足