Learn about Python Program to Find Sum of N Natural Numbers using For loop in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.
Sum of natural number N as given as sum = 1+2+3+4+5+….+(N-1)+N.
Python Program to Find Sum of N Natural Numbers using For loop
Initially, we read the input number from the user. Then iterate over a for loop to calculate the total sum and print the value.
# Python program to find sum of n natural numbers # input number num = int(input('Enter a number: ')) # find sum of natural number sum = 0 for x in range (1, num+1): sum += x # print result print('The sum of natural number =', sum)
Enter a number: 4 The sum of natural number = 10
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to Find Sum of N Natural Numbers