trying to make a code that simulates a predator prey relationship in python, however for some...

60.1K

Verified Solution

Question

Programming

trying to make a code that simulates a predator preyrelationship in python, however for some reason my code will notshow the plot, i cant find any issues with syntax or anything else,please help.

import matplotlib.pyplot as plt
predatorcount = []
preycount = []   

def simulate(initialpred, initialprey, preygrowth,predationrate, predshrink, predbirthrate):

predatorcount.append(initialpred)
preycount.appened(initialprey)
i=0;
prey = 1
predator = 1
while True:
prey =preycount[i]*(1+(preygrowth-predationrate*predatorcount[i]))
predator =predatorcount[i]*(1-(predshrink+predbirthrate*preycount[i]))
if prey <= 0 or predator <=0:  
break;
else:  
preycount.append(prey)
predatorcount.append(predator)
i = i+1
  
simulate(50, 1000, 0.25, 0.01, 0.05, 0.00002)
print(preycount[35])
plt.plot(range(35), predatorcount[35])
plt.plot(range(35), preycount[35])
  
plt.show()

Answer & Explanation Solved by verified expert
4.5 Ratings (829 Votes)
UPDATEDCODEimport matplotlibpyplot as pltimport numpy as nppredatorcount    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students