sum first 100 integers in python 1

sum first 100 integers in python

mysum = 0
for nextnumber in range(1, 101):
    mysum += nextnumber
print mysum

Here is what the above code is Doing:
1. The first line creates a variable called mysum and assigns it the value 0.
2. The second line is a for loop that iterates over the numbers 1 through 100.
3. The third line adds the next number to mysum.
4. The fourth line prints the value of mysum.

Similar Posts