def create_lists(a): s=[x**2 for x in range(1,1+a) if (x%2==0 or x%3==0)] s.reverse() p=[] for i in s: if i%2==0: p.append(i) else: p.append(-i) print(p) print('sum(p)='+str(sum(p)))
pythontest
最新推荐文章于 2024-03-22 15:14:32 发布
def create_lists(a): s=[x**2 for x in range(1,1+a) if (x%2==0 or x%3==0)] s.reverse() p=[] for i in s: if i%2==0: p.append(i) else: p.append(-i) print(p) print('sum(p)='+str(sum(p)))