Mar-30-2020, 11:48 PM
Hey, I'm pretty new to python so the answer to this might be obvious, but I made this code for an assignment, and while the code is working I don't think the final answer it's producing is correct. Here is my code:
annual_salary = float(input("Enter your annual salary")) total_cost = float(input("Enter the cost of the home")) percent_saved = float(input("Enter the percent saved")) current_savings = 0 months = 0 r = 0.04 portion_saved = percent_saved * annual_salary/12 down_payment = total_cost*0.25 while current_savings<down_payment: current_savings+=(portion_saved + current_savings*r/12) months+=1 print("The amount of months it will take to afford the down payment on the house is:",months)Here is the result of running the code:
Enter your annual salary120000 Enter the cost of the home1000000 Enter the percent saved.1 The amount of months it will take to afford the down payment on the house is: 183When I look at an example it seems that my result (183 months) is too high, however my code seems to me as if it should be correct. Again I'm sorry if the answer is obvious but I don't have much experience.