Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

PhilipY

  • 2 years ago

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.

  • This Question is Closed
  1. PhilipY
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. slotema
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  3. PhilipY
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  4. slotema
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    You're welcome.

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.