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}个月可以存够首付')

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐