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

anyone online right now working on problem set 1? Credit Card Problem? I am stuck on how to start tackling this...I have gotten beyond the raw_input issue, but now I find myself trying to get WAY TO CUTE with the way I am going about building the solution...how should I be thinking about solving this problem? FYI, just for S&G, I built this in excel to get a sense for how the logic should feel, but am having a very hard time translating that into python...Any advice would be appreciated.

OpenStudy (anonymous):

One first step would be to think what happens in one month: 1. For starters just do the math for the first and the second month by hand. 2. Think about, what you have done and how you would do the same in python. If you lack the python knowledge for this, look it up or watch the lectures again. 3. Then try to put the values into variables and build a loop to repeat the months. You should end up with a program that does what you would do to compute the interest by hand, but goes in loops through any number of months that you want it to. 4. If you have that, you might want to try this programm against numbers that are small enough that you can compute them by yourself.

OpenStudy (anonymous):

Thanks for the feedback... I am not challenged by the math . I understand the logic behind how to solve what is a simple amortization exercise...I am able to identify which objects need to relate to the others in moving forward each month. I am stuck on syntax errors now....very frustrating...grrrr...looks like I just need to go back and review syntax structure for these loops.

OpenStudy (e.mccormick):

What version of Python do you have installed? See, the instruction on the site are for the 2.x line. If you installed the 3.x line, things like print can trip you up.

OpenStudy (anonymous):

can you give a specific example? i.e. i was stuck on the correct syntax to cast raw_input as float type. i found the solution — encasing the entire raw_input line in () like so : float(raw_input ('enter your outstanding balance due:')). where are you stuck? --and unlike you, i'm walking baby steps through the math!

OpenStudy (anonymous):

-- oh, great idea to work it out in excel!

OpenStudy (anonymous):

I found the same solution for the raw_input piece. Where I was getting stuck was on the output for the raw_input data. I could not get the output to print in the following format: Month 1: (I could get this) Min Monthly Payment: $96.0 What I ended up with was Month 1: Min Monthly Payment: 96.0 I could not get both on the same line and could not get the $ in front of the 96.0 without getting syntax error after syntax error. I dont have python installed on my machine. It is my work computer, and we have extremely strict security protocols, so I cant install anything. I am using http://repl.it/languages/Python and working it out on the cloud based version of the language. Perhaps that is the problem.

OpenStudy (anonymous):

ahh.. yes, i had to puzzle that out. for the example you gave, are you able to paste your code here? this is mine—add COMMA, then VARIABLE after print 'string' : print 'Minimum monthly payment: $', round(min_mo_pay, 2). cheers, mazal btw, i discovered repl.it, and love it!

OpenStudy (e.mccormick):

When you start http://repl.it/languages/Python it says on the right: Python 2.7.2 (default, Jul 20 2011, 02:32:18) [GCC 4.2.1 (LLVM, Emscripten 1.5, Empythoned)] on linux2 So you are fine version wise.

OpenStudy (e.mccormick):

Ah, if you do multiple prints, it does each one on a separate line by default. print "abc" print 123 If you try: print "abc" + "123" print "abc", "123" print "abc", 123 print "abc" + 123 You will find the first three give results, but with slight differences. However, the 4th gives an errors. This is because in the first two I have strings alone and in the third I use a comma to print them as different items, but in the 4th I try to add numbers to letters and that just does not work. If I do a little type casting, I can fix this: print "abc" + str(123)

OpenStudy (anonymous):

That is exactly where I was running into errors. once I switched to a comma, the problem was solved...Thanks!

OpenStudy (e.mccormick):

Oh, and here are a few ways to share code. Here, a ``` above and below blocks: ``` print "abc" + "123" print "abc", "123" print "abc", 123 print "abc" + 123 ``` This formats it and makes it copy and paste properly. However, it is not great for longer blocks. On the other hand, these do great for longer blocks: http://dpaste.com/ http://pastebin.com/

OpenStudy (e.mccormick):

Oh, and a single \(\text{`}\) before and after code in a line does an inline code section. `print "La di da"`. And if you wonder how I escaped the single \(\text{`}\), I used \(\LaTeX\) support.

OpenStudy (anonymous):

@e.mccormick.. thanks! was wondering if there was an "overstack" style of posting code. so, test.. test.. ``` print 'Minimum monthly payment: $', round(min_mo_pay, 2) ``` : )

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!