在以下代码中,我将如何按半年一次增加semi_annual_raise给出的百分比的Annual_Sal。
换句话说,我希望并且已经尝试但是失败了,每次计数器计数到6时,year_sal都会增加一定百分比。
所以第一次,如果annual_sal为60,semi_annual_raise为.5,我希望计数器达到6后,新的annual_sal为90。然后,我想在随后的迭代中重用新的annual_sal,90代码。在这种情况下,current_savings会增加。我希望仅当current_savings小于或等于预付款时才能继续执行此操作。
total_cost = float(input('Please enter the total cost of your potential new home: '))
annual_sal = float(input('Please enter your annual salary: '))
portion_saved = float(input('Please enter the percentage of your monthly salary you would like to put toward the down payment of the new house (eg: 10): '))
monthly_sal = annual_sal/12
semi_annual_raise = float(input('Please enter your semi-annual raise: '))
portion_saved_for_computing = monthly_sal*portion_saved*0.01
# the above line might be unnecessary, but I decided to add it anyways.
down_payment = total_cost * 0.25
current_savings = 0
counter = 0
while current_savings <= down_payment:
if counter == 6:
break
current_savings += current_savings*0.04/12 + portion_saved_for_computing
counter += 1
我在我正在处理的作业的pdf上附加了一个链接。我能够完成a部分,但是我陷入了b部分。这是我为a编写的代码(此代码有效)。
total_cost = float(input('Please enter the total cost of your potential new home: '))
annual_sal = float(input('Please enter your annual salary: '))
portion_saved = float(input('Please enter the percentage of your monthly salary you would like to put toward the down payment of the new house (eg: 10): '))
monthly_sal = annual_sal/12
portion_saved_for_computing = monthly_sal*portion_saved*0.01
# the above line might be unnecessary, but I decided to add it anyways.
down_payment = total_cost * 0.25
current_savings = 0
counter = 0
while current_savings <= down_payment:
current_savings += current_savings*0.04/12 + portion_saved_for_computing
counter += 1
print(counter)
此外,我正在网上学习这门课程(它是自定进度的),所以我没有教授去上课。
如果有人可以提供帮助,我将不胜感激。先感谢您!这是作业:https://drive.google.com/file/d/1DFUsekQ4BcFXy6m0BJeQsqSoAjnVU2I5/view?usp=sharing