Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sum of 1 to n number in python

#1 + 2 + 3 + 4 + ........... + n = ?
l = int(input("Enter the range = "))
sum = 0
for x in range(1, l+1):
    sum += x
    if x != l:
        print(x, "+ ", end='')
    else:
        print(x, end='')

print(" =", sum)
 
PREVIOUS NEXT
Tagged: #sum #number #python
ADD COMMENT
Topic
Name
5+4 =