Latest web development tutorials

Python includes exercises 83

Python 100 Li Python 100 Li

Title: Find the number that can be composed of an odd number of 0-7.

Program Analysis: None.

Source Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    sum = 4
    s = 4
    for j in range(2,9):
        print sum
        if j <= 2:
            s *= 7
        else:
            s *= 8
        sum += s
    print 'sum = %d' % sum

The above example output is:

4
32
256
2048
16384
131072
1048576
sum = 8388608

Python 100 Li Python 100 Li