Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 45

Python Exercise Example 45

Python 100 Examples Python 100 Examples

**Problem:** Calculate the sum from 1 to 100.

**Program analysis:** None

Program source code:

Example

#!/usr/bin/python

-- coding: UTF-8 --

tmp

=

0

for

i

in

range

(

1

,

101

)

:

tmp

+=

i

print

(

'

The sum is %d

'

%

tmp

)

The output of the above example is:


The sum is 5050

Python 100 Examples Python 100 Examples