Below is the code snippet to print the sum of number from 1 to 100 in Python.
Check the indents.
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+=iprint(sum,'\n') #Once Printed Sum Now Break The While Loop break #End Of Program
#END OF THE PROGRAM
Where is the program?
LikeLike
Here is it:
Copy and paste it in Python Interpreter or IDLE
sum=0
for i in range (1,101):
while((sum+i)<100):
sum+=i
print(sum,’\n’)
break
#End Of Program
LikeLike