Hi, how are you? As Paulo said the for loop is wrong, in fact it does not need this repetition loop to do the assignment of the pop_rate variable, doing so:
pop_rate = pop_diff/year_diff * 100
I also noticed that in your return it is like this
return("The rate of population growth "+"City_name "+" in the year is "+str(pop_rate)+" %!")
Where the City_name parameter of your function is in quotes, in the case when leaving the function you will see instead of the name of the city "City_name"
Not to mention that as you put this message in the return of the function, to view it you should use the print method in it getting like this:
print(Grow_population_rate(parm1, param2, param3, param4, param5))
To remove the need of the print method, I suggest you put it inside the body of the function, and in the return put only the pop_rate that can be used in the future and will be hidden in the output, the code would be + or - like this:
def Grow_population_rate(year_1, year_2, City_name, pop_1, pop_2):
pop_diff = pop_2 - pop_1
year_diff = year_2 - year_1
pop_rate = pop_diff/year_diff * 100:
print("The rate of population growth "+ City_name +" in the year is "+str(pop_rate)+" %!")
return pop_rate
Welcome to Stackoverflow. Please read the description of tag
revisão-de-código
, which explicitly states that the tag should only be used in codes that are working. As you are new to the site, it is normal you do not yet know the rules of the site, but precisely why I suggest you read the Stackoverflow Survival Guide in Portuguese, which will give you important instructions and information about the operation of Sopt. :)– Luiz Felipe