def myfunc(n):
ls=[]
# we are going to append all the number from n to 2n
# and return their sum
# since 2n is also included, therefore end point of loop must be 2n+1
if n<0:
for i in range(n,2*n-1,-1):
ls.append(i)
else:
for i in range (n,2*n+1):
ls.append(i)
return sum(ls)
1条答案
按热度按时间ttp71kqs1#