Calculate the sum of odd numbers from 1-100

In this program, we will calculate the sum of odd numbers from 1-100.

Steps to solve the program
  1. Create a variable to calculate the sum and assign its value equal to 0.
  2. Use for loop to iterate over all numbers between 1-100.
  3. If the number is odd then add it to the variable created.
  4. Print the output.
				
					total = 0

for i in range(1,101):
    if i%2 != 0:
        total += i
        
print("Sum of odd numbers: ",total)
				
			

Output :

				
					Sum of odd numbers:  2500
				
			

Calculate the electricity bill

numbers which are divisible by 5 in 0-100

Leave a Comment