In this program, we will find the sum of natural numbers between 1 to n.
Steps to solve the program
- Take n as the last natural number as input through the user.
- Create a variable named total and assign its value equal to 0.
- Use for loop with range function to iterate over 1-n natural numbers.
- During each iteration add that number to the total.
- Print the output.
n= int(input("Enter the last number: "))
total = 0
for i in range(1,n+1):
total += i
print(total)
Output :
55