One reasonably simple approach:
n = 5
s = sum(range(n+1))
for i in range(n):
s -= i
print(s)
15
14
12
9
5
1
solved Sum from 1 to n, 2 to n, … n in python
One reasonably simple approach:
n = 5
s = sum(range(n+1))
for i in range(n):
s -= i
print(s)
15
14
12
9
5
1
solved Sum from 1 to n, 2 to n, … n in python