2 posts were split to a new topic: How do I Update the january_to_june_rainfall
Variable?
I think there is supposed to be some code that initially shows up that I’m meant to edit, but I only get the code carrying over from previous exercises. When I click the link to the exercise at the top of the forum page it takes me to a version of the exercise with a bunch of predefined variables. Help?
It sounds like you were able to troubleshoot an issue, I don’t run into the problem myself when i transition between the exercises
i can not figure out what is wrong with my code on exercise 7 updating variables
here is my 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
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
CAN SOMEONE PLEASE TELL ME WHAT I AM DOING WRONG?..WONT LET ME GO ON.
@net3229678455, I reset the workspace here, and pasted your code in. It worked fine, producing the magic yellow “Next” button. So I don’t know what the problem is.
Have you tried the reset?
why does this work
annual_rainfall += november_rainfall + december_rainfall + october_rainfall + september_rainfall
and this doesn’t work
annual_rainfall = november_rainfall + december_rainfall + october_rainfall + september_rainfall
wouldn’t that be fine too?
i was learning JavaScript not too long ago and i was sticking to that for a little while and for variables this seems a little similar to JavaScript as far as variable go just you don’t need to define what type of variable like var or let.
usually if i wanted to add variables (num) together it would be this
let i = 1
let t = 2
let s = 3
let it = i + t + s
but for python it would be this
i = 1
t = 2
s = 3
it += i + t + s right?
i might be making this a little complicated for no reason
those two ways are very different, here:
annual_rainfall += november_rainfall + december_rainfall + october_rainfall + september_rainfall
you add the rainfall of 4 months to annual_rainfall. Don’t forget that +=
is a shorthand for:
annual_rainfall = annual_rainfall + november_rainfall + december_rainfall + october_rainfall + september_rainfall
in the second code example, you overwrite the value already store in annual_rainfall and set it to the result of the sum.