Programming (en)

Fibonacci’s ideal rabbit generation, in Python ?


QUID ? >>>
print ('The story begins with a single pair of newly born rabbits...')
print ('they are able to mate at the age of one month...')
print ('and to reproduce at the age of two...')
print ('and to do so every month...')

month, newborns, mating, rabbits = (1, 1, 0, 1)
while month < 13:
    rabbits = mating + newborns
    print ("month #{0}: newborns = {1} mating = {2} rabbits = {3}".format(month,newborns,mating,rabbits))
    month, newborns, mating = (month+1, mating, mating + newborns)

print ('In 12 months the first pair has generated {0} rabbits'.format(rabbits))

# program: Fibonacci's ideal rabbit generation
# implementation in Python 3.x: A.-P. Gaspar
image_print

Leave a Reply

Your email address will not be published. Required fields are marked *

, ,

English - Programming (en)