'''Scene:
There is a pair of rabbits. From the third month after birth, they will give birth to one pair of rabbit every month.
When the little rabbits grows to the third month, they will give birth to another pair of rabbits every month.
Assuming that all rabbits are immortal, what is the total number of rabbits in each month within 30 months.
'''# After draw the chart, find out the rabbits number per month follows the Fibonacci sequence rules.import time
# add timer to calculate the performance# Basic performance###############################################################
start = time.time()
fib1 =1
fib2 =1#output the number of the first month and the second monthprint('{} {}'.format(fib1,fib2),end=' ')
i =3# set the loopfor i inrange(3,31):
fib = fib1+fib2
print(fib,end =' ')#output the amount of each monthif i%12==0:print()# warp the result around after 12 month
fib1=fib2
fib2=fib
i +=1
end = time.time()print("The Basic Runtime is {0}".format((end-start)))# Better performance###############################################################
start = time.time()
fib1 =1
fib2 =1
i =1for i inrange(16):print('{} {}'.format(fib1,fib2),end=' ')if i %6==0:print()
fib1 = fib1+fib2
fib2 = fib1+fib2
i=+1
end = time.time()print("The Better Runtime is {0}".format((end-start)))
Output
112358132134558914423337761098715972584418167651094617711286574636875025121393196418317811514229832040 The Basic Runtime is0.00100111961364746111235813213455891442333776109871597258441816765109461771128657463687502512139319641831781151422983204013462692178309 The Better Runtime is0.0