write a for loop to add 1 to 100 and print the sum in python

main.py
sum = 0
for i in range(1, 101):
    sum += i
print(sum)
56 chars
5 lines

In the above code, we initialize a variable sum to 0. We then use a for loop to iterate from 1 to 100 using the range() function. For each iteration, the value of i is added to sum. Finally, the value of sum is printed to the console using the print() function. This will output 5050, the sum of numbers from 1 to 100.

gistlibby LogSnag