Calculatrice d'Intérêts Simples
Calculez les intérêts simples, le montant total et les intérêts gagnés avec Principal × Taux × Temps.
Questions Fréquentes
Implémentation du Code
def simple_interest(principal: float, rate: float, time: float) -> dict:
"""
Calculate simple interest.
principal: initial amount
rate: annual interest rate as percentage (e.g. 5 for 5%)
time: time in years
"""
interest = principal * (rate / 100) * time
total = principal + interest
return {
"principal": principal,
"interest": interest,
"total": total,
"rate": rate,
"time": time,
}
# Example
result = simple_interest(principal=1000, rate=5, time=3)
print(f"Principal: ${result['principal']:,.2f}")
print(f"Interest: ${result['interest']:,.2f}")
print(f"Total: ${result['total']:,.2f}")
# Compare with compound interest
def compound_interest(principal: float, rate: float, time: float, n: int = 1) -> float:
"""n = compounding periods per year."""
return principal * (1 + rate / 100 / n) ** (n * time)
ci_total = compound_interest(1000, 5, 3)
print(f"\nCompound interest total: ${ci_total:,.2f}")
print(f"Difference (CI - SI): ${ci_total - result['total']:,.2f}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.