Issue with Updating Variables (7/14) in Learn Python - agr!


#1

https://www.codecademy.com/courses/learn-python/lessons/python-syntax/exercises/update-variables?action=resume_content_item

Hi, I am currently stuck on this exercise. I have the following code

september_to_december_rainfall = 5.16 + 7.20 + 5.06 + 4.06
annual_rainfall = september_to_december_rainfall

july_rainfall = 1.05
annual_rainfall += july_rainfall

august_rainfall = 4.91
annual_rainfall += august_rainfall

september_rainfall = 5.16
annual_rainfall += september_rainfall

october_rainfall = 7.20
annual_rainfall += october_rainfall

november_rainfall = 5.06
annual_rainfall += november_rainfall

december_rainfall = 4.06
annual_rainfall += december_rainfall

september_rainfall = 5.16
october_rainfall = 7.20
november_rainfall = 5.06
december_rainfall = 4.06

I am getting the response:

Did you add all of the remaining months to the variable annual_rainfall?

I’m completely lost as I thought I added the remaining months (sept-dec) as I followed suit from July and Aug…


#2

Hi there.

I suspect that the script which runs in the background to check the validity of your code is simply checking whether annual_rainfall has the value we expect it to have.

In this case, look at what you’re doing. We’re asked to calculate the annual rainfall, and you’re starting with September - December:

september_to_december_rainfall = 5.16 + 7.20 + 5.06 + 4.06
annual_rainfall = september_to_december_rainfall

and then adding to that the rainfall for July, August, September, October, November, and December:

july_rainfall = 1.05
annual_rainfall += july_rainfall

august_rainfall = 4.91
annual_rainfall += august_rainfall

september_rainfall = 5.16
annual_rainfall += september_rainfall

october_rainfall = 7.20
annual_rainfall += october_rainfall

november_rainfall = 5.06
annual_rainfall += november_rainfall

december_rainfall = 4.06
annual_rainfall += december_rainfall

september_rainfall = 5.16
october_rainfall = 7.20
november_rainfall = 5.06
december_rainfall = 4.06

So we have, in effect, recorded September - December twice, but have no data for January to June.

The editor should have given you when you began the exercise a variable called january_to_june_rainfall with the values for that period. If you’re not seeing that variable, the original code for the exercise is:

Original Starting Code
january_to_june_rainfall = 1.93 + 0.71 + 3.53 + 3.41 + 3.69 + 4.50
annual_rainfall = january_to_june_rainfall

july_rainfall = 1.05
annual_rainfall += july_rainfall

august_rainfall = 4.91
annual_rainfall += august_rainfall

september_rainfall = 5.16
october_rainfall = 7.20
november_rainfall = 5.06
december_rainfall = 4.06

Does that help?


#3

Sort of.

I think the question confused me and I read too much into it. All I actually needed to do was add

september_rainfall = 5.16
annual_rainfall += september_rainfall

october_rainfall = 7.20
annual_rainfall += october_rainfall

november_rainfall = 5.06
annual_rainfall += november_rainfall

december_rainfall = 4.06
annual_rainfall += december_rainfall

But, what I still don’t understand is

annual_rainfall = january_to_june_rainfall

But the final figure calculates all months Jan-Dec, but why isn’t it giving me total rainfall for Jan-June as that’s what stated in the annual_rainfall value?


#4

Oh, I see now. It’s printed the annual rainfall because each month states annual_rainfull below on the second line.

Okay, I’ve answered my own question.

Thanks!


#5

Glad you figured it out. :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.