Answer to Question #293982 in Python for Michael

Question #293982

Artificial Mouse Population satisfying the following conditions:

  1. Two mouses are born, one by one in first and second month respectively. This newly born pair of mice build the initial population.
  2. These mice can mate at the age of second month such that this mice pair brings another pair of micein thethird month. So, in this way the mouses produced in a particular month will be equal to sum of mouses produced in the previous two months.
  3. If the x and y mouse are produced in first and second months to form a initial population, there will be x+y mouses in the third month.
  4. These mice are immortal. They will not die.

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.


1
Expert's answer
2022-02-05T02:04:01-0500
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS