Python program to print sum of 1 to 100. (Concept to learn: Python while loop)
# Python program to print sum of 1 to 100 (1+2+3+...+100) using while loop.
Program code:
sum = 0
num = 1
while(num <= 100):
sum = sum + num
num = num + 1
print("The sum is", sum)
Output of program:
The sum is 5050
No comments:
Post a Comment