Answered step by step
Verified Expert Solution
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
r
f
After one year passes, the number of animals will change. We need to compute
the birthdeath amount for the year.
The number of rabbits that survive until the next year is given by the follow
formula.
r br A B fc
where
A
B
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 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 rc
where
G
S
The values of A B S and G are based on experimental data.
After year, the population looks will have
bc
bc
After year, we have rabbits and foxes.
Required Functions
You are required to make and use the following functions in your submission.
def getIntegerquestion: Takes as its input parameter a question as a
string. Repeatedly asks the question until it get a positive nonzero integer as
input. Return the integer the user entered when successful.
def nextRabbitsfoxes rabbits Given a number of foxes and rabbits, returns the number of rabbits in the next year. For example,
nextRabbits will return
def nextFoxesfoxes rabbits Given a number of fixes and rabbits, returns
the number of foxes in the next year. For example, nextFoxes will
return
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
Enter Number of Rabbits:
Enter Number of Foxes:
Enter Years to Simulate:
Years Foxes Rabbits
Example
Enter Number of Rabbits:
Enter Number of Foxes:
Enter Years to Simulate:
Years Foxes Rabbits
Example
Enter Number of Rabbits: Hats
Invalid Input
Input must be an positive nonzero integer
Enter Number of Rabbits:
Invalid Input
Input must be an positive nonzero integer
Enter Number of Rabbits:
Invalid Input
Input must be an positive nonzero integer
Enter Number of Rabbits:
Enter Number of Foxes: ghosts
Invalid Input
Input must be an positive nonzero integer
Enter Number of Foxes:
Enter Years to Simulate: nine
Invalid Input
Input must be an positive nonzero integer
Enter Years to Simulate:
Years Foxes Rabbits
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started