Why doesn’t my code work? Please look and see if you can help me

populA = 80000
populB = 200000

while populA > populB:

There is your problem, your code will not run as populA is less than populB starting off not greater than >.

Change to:

while populA < populB:

You also reset years to 0 after your years = int(input("anecesary years: ")) when you use years = 0 which I doubt is what you want.

So your code should look something like the following, remove years = 0 and make sure populA = populA + (populA * growthA) etc.. is inside the while loop:

years = int(input("anecesary years: "))

populA = 80000
populB = 200000   

growthA = 0.03
growthB = 0.015

while populA < populB:
    years += 1
    populA += populA * growthA # same as populA = populA + (populA * growthA)
    populB += populB * growthB
print("after %i years the country  A exceeded the country B :", years)
print("P A: ", populA)
print("P B: ", populB)

Leave a Comment