Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 14 Online
OpenStudy (anonymous):

Hello all~ On problem set 1, problem 1a, the following part of the solution is confusing me: # Initialize state variables numMonths = 1 totalAmtPaid = 0 I know the problem has to be 'initialized', but can someone explain to me how one would get to 1 and 0, respectively? Also, the "+=" means??? thanks!

OpenStudy (gamer56):

what are you asking?

OpenStudy (anonymous):

I believe on the initialize part, they are just assigning values 1 and 0 to variables numMonths and totalAmtPaid. If on the second line you wrote numMonths = 9, then variable numMonths would have value 9. The "+=" operator means to increase the variable by the value next to the equal sign. To illustrate better "month +=1" is the same as "month = month +1" Hope this helps.

OpenStudy (e.mccormick):

x = x + 1 means x += 1 means x++ x = x + 5 means x += 5 It is shorthand. For adding 1, it is so common there is a really short version, the ++.

OpenStudy (rsmith6559):

AFAIK, the ++ is not supported in Python, just the +=.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!