Artificial Mouse Population satisfying the following conditions:
Write a function gen_population_series (x, y, n) which takes initial population as x, y and a positive integer number n as number of months and returns number of mouses produced in each month till 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