Python program to find the sum of natural numbers.

In this python basic program, we will find the sum of natural numbers defined by the user.

Steps to solve the program
  1. Take the last number up to which you want to find the sum as input through the user.
  2. Create a variable to store the sum and assign its value equal to 0.
  3. Use for loop with the range function to iterate over natural numbers defined by the user.
  4. During iteration add the respective natural number to the variable that we have created to find the sum.
  5. Print the output.
				
					num = int(input("Enter a number up to which you want to find sum: "))
total = 0

for i in range(1,num+1):
    total += i
    
print("Total: ",total)
				
			

Output :

				
					Enter a number up to which you want to find sum: 10
Total:  55
				
			

convert Decimal to Binary.

Program to find HCF

Leave a Comment