credit.py 743 B

12345678910111213141516171819202122232425262728
  1. import datetime
  2. import calendar
  3. balance = 10000
  4. interest_rate = 13 * .01
  5. monthly_payment = 1000
  6. today = datetime.date.today()
  7. days_in_current_month = calendar.monthrange(today.year, today.month)[1]
  8. days_till_end_month = days_in_current_month - today.day
  9. start_date = today + datetime.timedelta(days=days_till_end_month + 1)
  10. end_date = start_date
  11. while balance > 0:
  12. interest_charge = (interest_rate / 12) * balance
  13. balance += interest_charge
  14. balance -= monthly_payment
  15. balance = round(balance, 2)
  16. if balance < 0:
  17. balance = 0
  18. print(end_date, balance)
  19. days_in_current_month = calendar.monthrange(end_date.year, end_date.month)[1]
  20. end_date = end_date + datetime.timedelta(days=days_in_current_month)