Question on 6.00SC, problem set 1 question 1. This is the "Paying Off Credit Card Debt" problem. I initially ask the user to input their numbers. Then I used a for loop to run the 12 months. My first question is, how do I print a string and a float or integer on the same line? I'm getting an error message that you cannot concatenate separate types. For example, I am using this print code in my for loop: print 'Month: ' + x I designated x to be the number within the range of my for loop.
My other question is.. How do I keep track of the total amount paid? My outstanding balance is within my for loop and the variable is constantly changing with each month. What I initially tried to do was to save the original outstanding balance by giving it another variable that I would save until the end. But I would get an error when trying to do this.
With regard to your first question: if you want to print several variables on the same line, they can be seperated by a comma. So `print 'Month: ', x` should do the trick. (See: http://en.wikibooks.org/wiki/Python_Programming/Variables_and_Strings#Combining_Numbers_and_Strings) I'm not sure I fully understand your second question. Keeping track of something over a loop is best done with a seperate variable. Not sure if that's what you mean, though.
Great thank you slotema. For the second question, I created a new variable = 0 and added it within my loop and got my total at the end. Thanks for your help!
You're welcome.
Join our real-time social learning platform and learn together with your friends!