Sum of natural number in python
Example
Input
5
Output
15
Explanation
- Take the range as input from the user.
- Initialize the total as 0, which will later be used in the for loop.
- Start the for loop which will go up to the mentioned range and do the summation within the for loop.
- Now print the summation that is done within the for loop.
Program
range = int(input("enter the range"))
sum = 0
for i in range(1,range+1):
sum = sum + i
print(sum)