EvilZone
		Programming and Scripting => Scripting Languages => : Sparky712  August 09, 2013, 08:28:29 PM
		
			
			- 
				well, recently, i have been following the MIT OCW for computer science, starting with 6.00. the videos are going ok, and i've been taking loads of notes. however, it's come to problem set 2, and I cannot get the program to run. No doubt I've done something stupid, but I just can't see the syntax error. 
 
 oBalance = raw_input("Please input your outstanding credit card balance: $")
 air = raw_input("Please input your annual credit card interest rate as a decimal: ")
 mmpr = raw_input("Please enter your minimum monthly payment rate as a decimal: ")
 
 currentMonth = 1
 
 x = 0
 for x in range(0,12)
 print "Month: " + currentMonth
 currentMonth = currentMonth + 1
 mmp = round(mmpr * oBalance, 2)
 interestPaid = round((air/12) * oBalance, 2)
 principalPaid = round(oBalance - principalPaid, 2)
 oBalance = round(oBalance - principalPaid, 2)
 
 print "Minimum monthly payment: $" + mmp
 print "Principal paid: $" + principalPaid
 print "Remaining Balance: $" + oBalance
 
 
- 
				Lines 7 and 8 look to be the problem. 
 
 When using "for x in range(0,10)" you don't have to give x a value before hand, so you don't need line 7 at all.
 
 Whilst inside the loop, x will take the value of whatever iteration you are on. So in the first loop it will take the value 0, then in the next loop 1, and this will continue up to 9 then exit the loop.
 
 The problem you have here is that  you haven't specified anything to do in the loop. Nothing is happening here.
 You need to put some code in the loop to execute on each iteration.
 
 Try this
 
for x in range(0,10):    # Notice the colon also
 print x
 
 -- EDIT --
 
 You changed your code whilst I was posting that :P
 
 The first thing I'm noticing here is that you're missing a colon at the end of  "for x in range(0,12)"
 Put a colon at the end and it should work.
- 
				look again Thor, looks like you saw this when i accidentally posted early
 however, it may be the colon.
 
 Ok, now it works. now, I just have a contatenation problem. >.>' I need to try and make that int a string or something?
- 
				look again Thor, looks like you saw this when i accidentally posted early
 however, it may be the colon.
 
 Ok, now it works. now, I just have a contatenation problem. >.>' I need to try and make that int a string or something?
 
 
 That's simple enough.
 print "Month: " + str(currentMonth)
 
 str(int) converts the int to a string.
 
 
 Another thing I'm noticing is this
 principalPaid = round(oBalance - principalPaid, 2)
 
 You are using the variable principalPaid before you have declared what it is. You have to initiate it with a value first, for example principalPaid = 0, and put that outside of the loop so that it doesn't get reset to 0 on every iteration.
- 
				oh no, that's just a clerical error. i am using this laptop for internet, my computer for programming. had to type it over into this one. that's me rereading a bit by accident. the program works fine now i've sorted the contatenation thing out. must try and keep that in mind.
 
 Thank you for your help.
 Have a cookie.