>>> apr_interest(10000.0, 0.05, 3) 1618.223072263547 >>> apr_interest(10000.0, 0.05, 1) 512.6749646744732 >>> apr_interest(0.5, 0.05, 3) 0.08091115361317736 >>> apr_interest(10000.0, 0.06, -4) Traceback (most recent call last): ... ValueError: number_of_y
(
principal: float,
nominal_annual_percentage_rate: float,
number_of_years: float,
)
| 78 | |
| 79 | |
| 80 | def apr_interest( |
| 81 | principal: float, |
| 82 | nominal_annual_percentage_rate: float, |
| 83 | number_of_years: float, |
| 84 | ) -> float: |
| 85 | """ |
| 86 | >>> apr_interest(10000.0, 0.05, 3) |
| 87 | 1618.223072263547 |
| 88 | >>> apr_interest(10000.0, 0.05, 1) |
| 89 | 512.6749646744732 |
| 90 | >>> apr_interest(0.5, 0.05, 3) |
| 91 | 0.08091115361317736 |
| 92 | >>> apr_interest(10000.0, 0.06, -4) |
| 93 | Traceback (most recent call last): |
| 94 | ... |
| 95 | ValueError: number_of_years must be > 0 |
| 96 | >>> apr_interest(10000.0, -3.5, 3.0) |
| 97 | Traceback (most recent call last): |
| 98 | ... |
| 99 | ValueError: nominal_annual_percentage_rate must be >= 0 |
| 100 | >>> apr_interest(-5500.0, 0.01, 5) |
| 101 | Traceback (most recent call last): |
| 102 | ... |
| 103 | ValueError: principal must be > 0 |
| 104 | """ |
| 105 | if number_of_years <= 0: |
| 106 | raise ValueError("number_of_years must be > 0") |
| 107 | if nominal_annual_percentage_rate < 0: |
| 108 | raise ValueError("nominal_annual_percentage_rate must be >= 0") |
| 109 | if principal <= 0: |
| 110 | raise ValueError("principal must be > 0") |
| 111 | |
| 112 | return compound_interest( |
| 113 | principal, nominal_annual_percentage_rate / 365, number_of_years * 365 |
| 114 | ) |
| 115 | |
| 116 | |
| 117 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected