简体   繁体   English

程序没有给出想要的 output

[英]program not giving desired output

I am new to programming and I am stuck with one of my programming assignments.我是编程新手,我被我的一项编程任务困住了。 please evaluate the given code and let me know the mistakes I have made.请评估给定的代码并让我知道我所犯的错误。 the code is expected to output the number of months required to save up to buy a new house...代码预计为output 最多攒下买新房所需的月数...

total_cost = float(input("cost of house:"))
portion_down_payment= 0.25
current_savings = 0.0
r = .04
annual_salary = float(input("your annual salary is:"))
portion_saved = float(input("portion of income saved:"))   
months = 0

while current_savings <= portion_down_payment*total_cost:
   current_savings = current_savings*r/12 + portion_saved*annual_salary/12
   months = months+1
   
print("To buy your dream house you gotta wait for",months, "months")

You likely want to add to your savings, not overwrite them:您可能希望增加储蓄,而不是覆盖它们:

current_savings = current_savings*r/12 + portion_saved*annual_salary/12

should be:应该:

current_savings = current_savings + current_savings*r/12 + portion_saved*annual_salary/12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM