Skip to content

Instantly share code, notes, and snippets.

@guidanoli
Created March 9, 2025 03:57
Show Gist options
  • Save guidanoli/129d4073725c348db0e4228c436ef2fd to your computer and use it in GitHub Desktop.
Save guidanoli/129d4073725c348db0e4228c436ef2fd to your computer and use it in GitHub Desktop.
Calculate discount of equal installments with zero interest
YEARLY_INTEREST = 0.1375
MONTHLY_INTEREST = ((1 + YEARLY_INTEREST) ** (1/12)) - 1
NUM_INSTALLMENTS = 12
print("+--------------+----------+")
print("| Installments | Discount |")
print("+--------------+----------+")
installments = [1.0]
for num_installments in range(1, NUM_INSTALLMENTS + 1):
print("| {:12d} | {:7.3f}% |".format(num_installments, 100 * (1 - sum(installments) / num_installments)))
installments.append(installments[-1] / (1 + MONTHLY_INTEREST))
print("+--------------+----------+")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment