0
Calculate the sum of 1 to n using loops
N = int(input()) a=0 i=1 while i<=N: a=a+i i=i+1 print (a)
3 Answers
+ 4
n = int(input())
print (sum(range(n+1)))
+ 1
You can also use this formula:
n * (n+1) // 2
N = int(input()) a=0 i=1 while i<=N: a=a+i i=i+1 print (a)