Python program to print and add numbers starting 1 onwards till the sum of them is less than 100

Below is the code snippet to print the sum of number from 1 to 100 in Python.
Check the indents.

#Declaring Variable 

sum=0 

#Now Running For Loop from 1 to 100

 

#range(0,n) take 0 and leave the last element 'n' 

 

for i in range (1,101): 

#Checking weather sum is less than 100 or not

      while((sum+i)<100):

          sum+=i

          print(sum,'\n')

          #Once Printed Sum Now Break The While Loop

          break

#End Of Program

#END OF THE PROGRAM

2 thoughts on “Python program to print and add numbers starting 1 onwards till the sum of them is less than 100

Leave a reply to Ratnam Cancel reply