Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview In this question, you will simulate a population of foxes and rabbits. You will be required to implement and use functions in your code.

Overview
In this question, you will simulate a population of foxes and rabbits.
You will be required to implement and use functions in your code.
Simulation Math
Imagine a population of Foxes and Rabbits living in an enclosed space. Each
year, some animals are born and some die. Foxes will cause some of the rabbits
to die. If the number of rabbits is too small, some foxes will die from starvation.
This problem can be modeled by writting a program.
At the start of recorded time, there are a starting number of Foxes and Rabbits.
For example, at year 0
r =5891
f =16
After one year passes, the number of animals will change. We need to compute
the birth-death amount for the year.
The number of rabbits that survive until the next year is given by the follow
formula.
r + br (A B f)c
where
A =0.04
B =0.0005
The symbol bxc means the floor of x. This means we round all values down to
the nearest integer. There is no such thing as 0.5 of a fox or rabbit.
Notice that the current number of foxes changes the number of births and deaths.
A similar formula can be created for the foxes. It is affected by the number of
rabbits.
f bf (G S r)c
where
1
G =0.2
S =0.00005
The values of A, B, S, and G are based on experimental data.
After 1 year, the population looks will have
5891+ b5891(0.040.000516)c =6079
16 b16(0.20.000055891)c =18
After 1 year, we have 6079 rabbits and 18 foxes.
Required Functions
You are required to make and use the following functions in your submission.
def getInteger(question): Takes as its input parameter a question as a
string. Repeatedly asks the question until it get a positive non-zero integer as
input. Return the integer the user entered when successful.
def nextRabbits(foxes, rabbits). Given a number of foxes and rabbits, returns the number of rabbits in the next year. For example,
nextRabbits(10,1000) will return 1035.
def nextFoxes(foxes, rabbits). Given a number of fixes and rabbits, returns
the number of foxes in the next year. For example, nextFoxes(10,1000) will
return 9.
Main Script
Your main program will ask the user for three integers. They cannot be negative
or zero. If the user enters an invalid input, your program will ask again. It will
only continue when given a valid input.
The three integers are:
The number of rabbits before the start of the simulation (Year Zero)
The number of foxes before the start of the simulation (Year Zero)
The number of years to simulate.
Once you have received the valid inputs, print a table showing the number of
rabbits and foxes over all the years the user asked for. Your table should be well
formatted.
Note: Your table does not need to exaclty match the examples below. You may
change the visuals slightly, but it must be an easy to read and well formatted output.
Example 1
Enter Number of Rabbits: 1000
Enter Number of Foxes: 10
Enter Years to Simulate: 1
| Years | Foxes | Rabbits |
|-------|-------|-------|
|0|10|1000|
|1|9|1035|
Example 2
Enter Number of Rabbits: 5891
Enter Number of Foxes: 16
Enter Years to Simulate: 10
| Years | Foxes | Rabbits |
|-------|-------|-------|
|0|16|5891|
|1|18|6079|
|2|20|6267|
|3|23|6455|
|4|26|6638|
|5|30|6817|
|6|35|6987|
|7|41|7144|
|8|48|7283|
|9|56|7399|
|10|66|7487|
Example 3
Enter Number of Rabbits: Hats
Invalid Input
Input must be an positive non-zero integer
Enter Number of Rabbits: 0
Invalid Input
Input must be an positive non-zero integer
Enter Number of Rabbits: -2
Invalid Input
Input must be an positive non-zero integer
Enter Number of Rabbits: 999
Enter Number of Foxes: ghosts
Invalid Input
Input must be an positive non-zero integer
Enter Number of Foxes: 12
Enter Years to Simulate: nine
Invalid Input
3
Input must be an positive non-zero integer
Enter Years to Simulate: 14
| Years | Foxes | Rabbits |
|-------|-------|-------|
|0|12|999|
|1|11|1032|
|2|10|1067|
|3|9|1104|
|4|8|1143|
|5|7|1184|
|6|7|1227|
|7|7|1271|
|8|7|1317|
|9|7|1365|
|10|7|1414|
|11|7|1465|
|12|7|1518|
|13|7|1573|
|14|7|1630|

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions