I'm having a problem regarding the output of my function. Here are my codes:
def rrecursive(pop,n,r,K):
if n==1:
return pop
else:
popu=rrecursive(pop,n-1,r,K)
y= popu+r*(1-popu/K)*popu
if y>9.9:
print("It will take",n*10,"years for the population to reach 9.9 billion")
return 0
return y
rrecursive(7,40,0.11,10)
All I'm trying to do here is display how many years It takes for the population to exceed 9.9 billion. My codes does work when pop is greater than 5 and n is greater than 40 but when it's below it prints nothing. If I call the function like rrecursive(5,40,0.11,10) it prints nothing. I tried using:
print(rrecursive(5,40,0.11,10))
it worked but when I plug print(rrecursive(7,40,0.11,10))
it prints out: output:
It will take 340 years for the population to reach 9.9 billion
0.0
I don't want the "0.0"