Python 练习范例 83
求 0—7 所能组成的奇数个数
#!/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
以上 Python 代码输出结果如下
4 32 256 2048 16384 131072 1048576 sum = 8388608