I'm a complete beginner to programming and I have recently completed a course on Intro to Python so I set out to practice my fundamentals on CodeWars. I wanted to use Recursion in the below problem but it kept returning None instead of the count. I want to know whats the error.
In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants?
My code is:
def nb_year(p0, percent, aug, p):
global count
if p0 >= p:
return count
p0 = p0 + (p0*(percent/100))+aug
count = count + 1
nb_year(p0,percent,aug,p)