付款的Python脚本

2024-10-04 05:28:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一组顾客,他们每个月要付一笔钱。但事实上,有些客户每月支付的金额为零,或者只有其中的一部分。如何使用python计算他们一年的支付度?百分比是描述支付程度的最佳方式吗,“支付程度”这个词用得对吗?你知道吗

示例:

customer X should pay 275 each month 
payments = [jan : 200, feb : 0, march: 150, april : 275, may : 275, jun : 20, july : 275, aug : 186, sep : 0, oct : 20, nov : 275, dec : 200 ]

Tags: 示例客户方式customer金额payjanfeb
1条回答
网友
1楼 · 发布于 2024-10-04 05:28:27
payments = {
    "jan": 200, "feb":   0, "mar": 150, "apr": 275,
    "may": 275, "jun":  20, "jul": 275, "aug": 186,
    "sep":   0, "oct":  20, "nov": 275, "dec": 200
}

MONTHLY = 275

paid = sum(payments.values())
should_be = MONTHLY * len(payments)

pct = (paid / should_be) * 100.0

print("Customer paid {:0.1f}% of their bill".format(pct))

结果

Customer paid 56.8% of their bill

相关问题 更多 >