I am trying to write a predator-prey model where I take the input for the amount of rabbits, foxes, and years. Then output the final number of rabbits and foxes after that amount of years. I am able to return an amount of rabbits and foxes, but I am not getting the correct values. The algorithm for the foxes and rabbits after one year are:
F1yr = F0yr – Floor(F0yr * (G-S * R0yr))
R1yr = R0yr + Floor( R0yr * (A-B * F0yr))
Where A = 0.04, B = 0.0005, G = 0.2, and S=0.00005
For a starting input of 5891 rabbits and 16 foxes after 99 years, it should return 6484 rabbits and 144 foxes, but I am getting 4682 rabbits and 189 foxes.
This is the code that I have so far, I feel like I am close to the answer, but not fully there:
def bunnies(rabbits,foxes,years):
if __name__ == '__main__':
if years == 0:
tot = []
tot.append(rabbits)
tot.append(foxes)
return tot
else:
a = 0.04
b = 0.0005
g = 0.2
s = 0.00005
rabbits = rabbits + math.floor(rabbits * (a-b * foxes))
foxes = foxes - math.floor(foxes * (g-s * rabbits))
return bunnies(rabbits,foxes,years-1)
rabbits = int(input('Enter Initial Rabbit Population:\n'))
foxes = int(input('Enter Initial Fox Population:\n'))
years = int(input('Enter Number of Years to Simulate:\n'))
print(bunnies(rabbits,foxes,years))