Python Practice Example 83
Title:Find the number of odd numbers that can be formed from 0-7.
Program analysis:
1-digit numbers: 4.
2-digit numbers: 7*4.
3-digit numbers: 7*8*4.
4-digit numbers: 7*8*8*4.
......
Program source code:
Example (Python 2.0+)
#!/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 output of the above example is:
4 32 256 2048 16384 131072 1048576 sum = 8388608Other extensions
Python 100 Examples