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!
what are you asking?
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.
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 ++.
AFAIK, the ++ is not supported in Python, just the +=.
Join our real-time social learning platform and learn together with your friends!