【Python 练习实例11】古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
1 2 3 4 5 6 7 8 9 |
list = [1] for mon in range(10): for i in range(len(list)): if list[i]<3: list[i] += 1 count = int(list.count(3)) for a in range(count): list.append(1) print(len(list),end=' ') |
输出:
1 |
1 2 3 5 8 13 21 34 55 89 |