Below is the code snippet to print the sum of number from 1 to 100 in Python.
Check the indents.
#END OF THE PROGRAM
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
Comments
Post a Comment
Thanks for Your time . we appreciate your feedback. Comment here!