Python Practice Example 45

Python 100例Python 100 Examples

Problem:Calculate the sum of numbers 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例Python 100 Examples

Other Extensions