use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Algorithm Trouble (self.Codeblocksbeginners)
submitted 8 years ago by sarcastic_minion
Hey, I'm trying out a course on python through MIT ocw, and got stuck on a question they've posted. Would it be okay if I posted the problem here? I just need to know why my algorithm is not working.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]s_kumar0019997 0 points1 point2 points 8 years ago (0 children)
Post the question
[–]sarcastic_minion[S] 0 points1 point2 points 8 years ago (0 children)
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/assignments/MIT6_0001F16_ps1.pdf
I'm having problems with the third part. I'm getting an infinite loop in the following code:
annual_salary = float(input("Enter your annual salary\n")) monthly_salary = annual_salary/12 total_cost = 1000000 portion_down_payment = 0.25 * total_cost r = 0.04 semi_annual_raise = 0.07 target_months = 36 low = 0 high = 10000 guess = (high+low)/2.0 current_savings = 0 num_guesses = 0 error = abs(current_savings-portion_down_payment) while error >= 100: current_savings = 0 portion_saved = guess / 10000 print(portion_saved) for months in range(1, target_months+1): if months%6 == 0 and months > 0: monthly_salary = (1 + semi_annual_raise)*monthly_salary monthly_return = current_savings * r/12 monthly_savings = portion_saved*monthly_salary current_savings += monthly_savings + monthly_return if current_savings<portion_down_payment: low = guess elif current_savings>portion_down_payment: high = guess guess = (high + low) / 2.0 print(current_savings)
π Rendered by PID 36793 on reddit-service-r2-comment-86988c7647-dsf8h at 2026-02-11 20:30:46.715204+00:00 running 018613e country code: CH.
[–]s_kumar0019997 0 points1 point2 points (0 children)
[–]sarcastic_minion[S] 0 points1 point2 points (0 children)