Python program to calculate sum of n natural numbers
In this example we will learn how to calculate sum of n natural numbers
1. Python program for sum of n numbers using While Loop
#Python program to calculate the addition of 1 to 10 using While Loop
n=int ( input( ” Enter any number : ” ) )
if (n < 0):
  print(” Please Enter positive number “)
else:
   sum = 0
   while( n > 0):
     sum += n
     n -= 1
   print(‘Addition of all numbers = ‘,sum)
Enter any number : 10
Addition of all numbers = 55
2. Python program for sum of n numbers using For Loop
#Python program to calculate the addition of 1 to 10 using For Loop
n=int ( input( ” Enter any number : ” ) )
if (n < 0):
print(” Please Enter positive number “)
else:
sum = 0
for i in range (n+1):
sum += i
print(‘Addition of all numbers = ‘,sum)
Enter any number : 10
Addition of all numbers = 55
Python Program to add two numbers
Python program to find Area of Square
Python program to find Area of Triangle
Python program to swap two variables
Python program to convert Celsius to Fahrenheit
Python program to generate Random Number
Python program to convert Miles to Kolometers
Python program to find Largest of 2 numbers
Python program to check if number is Odd or Even
Python program to check if number is Positive Negative or Zero
Python program to check Leap Year
Types of Loop in Python
Python program to check Prime Number
Python program to Calculate Sum of N Natural Numbers
Python program to find sum of All Even Number between 1 to 10
Python program to find sum of All Odd Number between 1 to 10
Python program to check Armstrong Number