Artificial Mouse population satisfying the following conditions :
i. Two mouses are born one by one in 1st and 2nd months respectively. This newly born pair of mice build the initial population.
ii. These mice can mate at the age of 2nd month such that this mice pair brings another pair of mice in the 3rd month. So, in this way the mouses produced in a particular month will be equal to sum of mouses produced in the previous 2 months.
iii. If the a and b are produced in the 1st and 2nd months to form an initial population there will be a + b mouses in the 3rd month.
iv. These mice are immortal. They will not die.
Write a python function population-series(a, b, n) which takes the population as a ,b and a
positive integer number 'n' as number of months and returns no. of mouses produced in each month till the nth month in string format using recursion.
def population_series(a, b, n):
if n == 1:
print(f'Growth over the past months: {a}')
print(f'Growth for this month: {b}')
print(f'Total mice: {a+b}')
else:
if a <= 1:
n -= 1
print(f'Growth over the past months: {a}')
print(f'Growth for this month: {b}')
a = a+b
b = a
population_series(a, b, n)
else:
n -= 1
print(f'Growth over the past months: {a}')
print(f'Growth for this month: {b}')
a, b = a+b, a
population_series(a, b, n)
def main():
a = 0
b = 1
n = 4
population_series(a, b, n)
if __name__ == '__main__':
main()
Comments
Leave a comment