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

Hello. A newbie is a little (very) confused on problem set 1 question 1, "Credit Card Debt." I watched lectures 1, 2 and the first recitation, and feel as if I understand them, so I may not know the necessary information. I'm actually a little confused...on where to start. This is my godawful attempt at starting the problem: x = float(raw_input('Enter current balance ')) y = float(raw_input('Enter annual interest rate ')) z = float(raw_input('Enter minimum monthly payment rate ')) for i in range(1,13): t = x * z p = (y/12.0) * x r = t - p b = x - r

OpenStudy (anonymous):

x = b x = x print x I have no clue... before yesterday, the highest level programming I've done was on a TI-84...

OpenStudy (anonymous):

The user raw input code looks good, and I did the for loop as well in this problem. Using the test case 1, after the 3 user inputs, they printed out "Month: 1", "Min monthly payment: " etc... So.. for i in range(1,13): print 'Month: ', i t = x * z print 'Minimum monthly payment: ', t etc.. all the equations in the loop look good, but I would change the last one, var b. Rather than using var b, I just used something like x = x - r So the balance changes itself. This is just the approach I took to the problem and I'm sure there are many ways to get the same results.

OpenStudy (anonymous):

i isn't used at all

OpenStudy (anonymous):

Ok your code seems good, but you don't need to do: x = b x = x print x That's unnecessary, you just put after the for loop, "print b" or with some text to be more understandable for you and others, something like: print 'resultado:',b You can improve the for loop, you want to run over 12 times, just use: for i in range(12); When I started I confused putting the limits :$

OpenStudy (anonymous):

Ask as many as you want, is better if you use less variables, cuz the less line code the better, but if your variables are like, rates, balance, etc; in that case where you would update them, will be usefull have each one in variables, is up to you most of the time. If you make x = 10.0/3; x = 3.3333333333, to round, just use: round(x,#ofDigits) -> round(x,2) = 3.33

OpenStudy (anonymous):

Kay. Thanks :D!

OpenStudy (anonymous):

you're welcome

OpenStudy (anonymous):

you might want to consider using variable names that give an idea about what they are used for. "balance" instead of "x", "interest_rate" instead of "y". it makes it easier to read and troubleshoot, both for you and those trying to help.

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!