Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
I'm having issues with my code for PS2 question 2 it saying that there's an error on my else statement.
 one year ago
 one year ago
I'm having issues with my code for PS2 question 2 it saying that there's an error on my else statement.
 one year ago
 one year ago

This Question is Open

shims506Best ResponseYou've already chosen the best response.0
balance=4213 annualInterestRate=.2 factor=0 #How much paid total x=0 #Lowest payment variable y=0 #Range for one year of paying minimum 12 months in a year while balance >= 0: factor+=1 for n in range(1,13): x=str(factor)*(10*str(n)) balance=(balance(10*str(factor)))*(1+(annualInterestRate/12) else: y=str(factor)*10 #Print Lowest Payment print('Lowest Payment: '+str(round(y,1)))
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
You're getting an "invalid syntax" error?
 one year ago

shims506Best ResponseYou've already chosen the best response.0
yes would like to know whats the reason before i procede on fixing the rest of the code
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Looks like you're missing a parenthesis on this line: balance=(balance(10*str(factor)))*(1+(annualInterestRate/12)
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
That looks to be the first problem, it's expecting a ")" to close (1+(annualInterestRate/12)
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
On this line: " x=str(factor)*(10*str(n)) " You are trying to obtain a number, correct? the "str(x)" method converts the argument into a string.
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Yeah, close the parenthesis, then run the code. You should encounter another error...
 one year ago

shims506Best ResponseYou've already chosen the best response.0
Always the small things that gets me, thanks. Also for that section of code I am aiming at getting a number value is str() not the function? Another issue i seem to see is that shouldn't i have a void loop on the calculation of balance part because if the first time the payment isn't right and i go to check the next factor of 10 the balance will be altered do to previous run.
 one year ago

shims506Best ResponseYou've already chosen the best response.0
Yea got the TypeError: can't multiply sequence by nonint of type 'str' Will change that part and others like that asap.
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Yeah, you're working with numbers. Checkout here: http://docs.python.org/library/string.html
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
There you can see methods/functions for string in python. str(x) converts the argument x to a string
 one year ago

shims506Best ResponseYou've already chosen the best response.0
For str() i would need to convert to int because the error it shows now is TypeError: can't multiply sequence by nonint of type 'str' since working in which month and factors of ten i can change that into int() right?
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
yeah, basically you can't multiply strings together...
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
factor is already a number luckily
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
You shouldn't need to have anything as a string to begin with. I think you are making it more complicated than it is. just leave everything as numbers. you don't even have to convert to str to print it.
 one year ago

shims506Best ResponseYou've already chosen the best response.0
I deleted all str() and still have an error at where i have my "else:" statement error is invalid syntax
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
hm, did you put in that parenthesis at the end?
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
You are trying to do a while ... else .... there is no such thing, just while or if..else
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Can you direct to me the assignment via link?
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
But, @msmithhnova is right, your current solution may be more complicated than necessary and hence combining programing designs. if : .. else: clauses exists in python. a while: ... else: block does not exist.
 one year ago

shims506Best ResponseYou've already chosen the best response.0
you have to be logged in to view assignment i can send the summary of it though I change my "while" to "if" and still has same error at same location im double checking all my parenthesis
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Paste your current code here please, that'll help
 one year ago

shims506Best ResponseYou've already chosen the best response.0
balance=4213 annualInterestRate=.2 factor=0 #How much paid total x=0 #Lowest payment variable y=0 if balance > 0: factor+=1 #Range for one year of paying minimum 12 months in a year for n in range(1,13): x=factor*(10*n) balance=(balance(10*factor)*(1+(annualInterestRate/12)) else: y=factor*10 #Print Lowest Payment print('Lowest Payment: '+str(round(y,1)))
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Yep, missing a parenthesis: balance=(balance(10*factor)*(1+(annualInterestRate/12)) < ) need
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
Here's some pseudocode that might help set payment guess loop check guess if guess not right increase guess end loop
 one year ago

shims506Best ResponseYou've already chosen the best response.0
Yupp that did the trick thank you dpflan :) now time to fix the algebra part msmithhnova will that pseudo code fix the issue with balance being overwritten to a new value when increasing the guess.
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
No, you will want to create a new variable equal to balance to either work with or keep track of original amoiunt.
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
Another note is from the pseudocode you are looking at one while loop with everything in it. The only thing that would end up outside the loop is the print statement with your final answer.
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
An issue with your code above also is that your guess (x) should be changed outside the for as the for loop is the 'check' part of the pseudocode
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Try to state the goal of the problem, from there, write out your solution in pseudocode, and create the mathematical relationship among variables
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
BTW, dpflan, the basics of the problem is make guesses in increments of 10 that it will take to pay off balance in 1 year including interest. Once a guess makes the balance less than 0 you're done.
 one year ago

shims506Best ResponseYou've already chosen the best response.0
Never thought about doing a pseudo code seems like an easier cleaner route ill try that and let you know what other issues i run into. Thanks for the all the help so far.
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
The goal is to find the factor such that the balance becomes 0 within 12 iterations
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
You need to start each examination with balance at the starting balance.
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
A simple debugging technique is add print statements in your code, for instance it might help to print the values you are working with, like the balance and the factor
 one year ago

shims506Best ResponseYou've already chosen the best response.0
that makes life so much easier thank you i seem to getting some numbers displayed printed out hopefully they are the right numbers.
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
If not lets us know. Pseudocode is a wonderful thing it allows you to think about the logic and coding seperately instead of doing both at the same time. Once you think you have your logic (pseudocode) figured out then it is just a matter of turning that into actual code. When you do, you sometimes realize your logic (pseudocode) was a little off of your translation to code was and one or both have to be modified. This is where the print statements help immensely to show you where the flaw is.
 one year ago

dpflanBest ResponseYou've already chosen the best response.1
Yeah, feel free to share your solution when reach one. We can check out your code like we've just done and give you some help. What course is this from? An MIT OCW course, the MOOC course,...?
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
Edx MIT 600 course
 one year ago

shims506Best ResponseYou've already chosen the best response.0
so far this is what i have in my code, added a few things to make up for the override my answer is 140 but i should be getting 310 with the current balance and interest rate i put in i will need to look more into pseudo code is there any site that teaches the concept well?
 one year ago

shims506Best ResponseYou've already chosen the best response.0
one thing that helped answer is i deleted "x" in my while statement but im still $30 off
 one year ago

shims506Best ResponseYou've already chosen the best response.0
balance=3329 annualInterestRate=.2 factor=0 #How much paid total x=0 #Lowest payment variable y=0 balance1=balance while balance1 >= 0: factor+=1 x=0 balance1=balance #Range for one year of paying minimum 12 months in a year for n in range(1,13): print('What Factor im on:'+str(factor)) print('Which month im on:'+str(n)) x=factor*10*n print(str(x)) balance1=(balance1(10*factor)*(1+(annualInterestRate/12))) print('Balance so far:'+str(balance1)) amiclose=balance1x #print(str(amiclose)) y=factor*10 #Print Lowest Payment print('Lowest Payment:'+str(y)) #actual Lowest payment should be 310
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
Just headed home, will take a look when I get there if someone else hasn't by then.
 one year ago

TuringTestBest ResponseYou've already chosen the best response.0
you have a lot of extra variables...
 one year ago

shims506Best ResponseYou've already chosen the best response.0
in my new code i use those variables to check where im at and print out values if you d like i can update the code i noted what each variable does
 one year ago

TuringTestBest ResponseYou've already chosen the best response.0
x=factor*10*n this line is strange, why should the minimum payment be proportional to which number month of the year you are in?
 one year ago

shims506Best ResponseYou've already chosen the best response.0
that line states how much have i paid off the debt in which factor and this given month so i could check my math
 one year ago

shims506Best ResponseYou've already chosen the best response.0
aleluja i was missing a ')' and since it was following mathematical rules PEMDAS it didnt work out at first now everything seems good :) thanks all for the help
 one year ago

TuringTestBest ResponseYou've already chosen the best response.0
ok, still, n is the number month you are in this code is saying that you pay factor*10*2 in february, and factor810*3 in march i.e. you pay more in march then february, how does that make sense?
 one year ago

shims506Best ResponseYou've already chosen the best response.0
the thing is how much total have i paid up to that month you know
 one year ago

TuringTestBest ResponseYou've already chosen the best response.0
it makes sense that the total you have paid my march is more than in february, but you code says that you pay more for *that* particular month than the one before
 one year ago

TuringTestBest ResponseYou've already chosen the best response.0
I mean, if you get the right answer then okay, but I don't see how...
 one year ago

shims506Best ResponseYou've already chosen the best response.0
hmmm im not understanding your question their but i did submit my code and it was right thanks guys :)
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.1
Glad you got it to work.
 one year ago

EcrestBest ResponseYou've already chosen the best response.0
What is wrong with this code: balance = 4213 annualInterestRate = 0.2 monthlyPaymentRate = 0.4 month = 1 balance = (balance  (balance*monthlyPaymentRate))*(1+(annualInterestRate/12)) while month < 13: print "Month: " + str(month) print "Minimum monthly payment: " + str(round(minimum_payment_rate, 2)) print "Remaining balance: " + str(round(balance, 2)) month += 1
 one year ago

Chris2332Best ResponseYou've already chosen the best response.0
where do you calculate your balance in the loop? It will remain the same. You just incrementing the month and you don't touch the min payment or the balance!
 one year ago
See more questions >>>
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
 Engagement 19 Mad Hatter
 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.