存款买房python
from decimal import Decimalimport mathtotal_cost = float(input())# total_cost为当前房价annual_salary = float(input())# 年薪portion_saved = float(input()) / 100# 月存款比例,输入30转为0.30(即30%)# 根据首付款比例计算首付款down_payme
·
from decimal import Decimal
import math
total_cost = float(input()) # total_cost为当前房价
annual_salary = float(input()) # 年薪
portion_saved = float(input()) / 100 # 月存款比例,输入30转为0.30(即30%)
# 根据首付款比例计算首付款down_payment,根据月存款比例计算月存款额monthly_deposit
# =======================================================
down_payment = Decimal(total_cost * 0.3).quantize(Decimal('0.01'), rounding='ROUND_HALF_UP')
monthly_deposit = Decimal(annual_salary / 12 * portion_saved).quantize(Decimal('0.01'), rounding='ROUND_HALF_UP')
# =======================================================
print(f'首付 {down_payment} 元')
print(f'月存款 {monthly_deposit} 元')
# 计算多少个月才能存够首付款,结果为整数,不足1月按1个月计算,即向上取整
# =======================================================
number_of_months = math.ceil(down_payment/monthly_deposit)
# =======================================================
print(f'需要{number_of_months}个月可以存够首付')
更多推荐
已为社区贡献3条内容
所有评论(0)