Savings interest on daily balances
A savings account at a bank in Lagos pays interest on the closing balance of each day. Statements cover a date range, and ranges can include a leap day. Your job is to compute the interest for a statement period.
The balance at the start of the first day (before any of that day's transactions) is the opening balance. Each transaction is a signed amount (deposits positive, withdrawals negative) that applies on its date. The closing balance of a day is the opening balance plus every transaction dated on or before that day. For every day in the period, both ends included, the interest for that day is max(closing, 0) * annual_rate / 100 / 365 (always divide by 365, even in a leap year, and negative balances earn nothing). No compounding inside the period. Sum the daily amounts exactly, then round once to 2 decimals, halves up (use the decimal module).
Task: read line 1 start date, line 2 end date (YYYY-MM-DD), line 3 opening balance, line 4 annual rate in percent, line 5 the number of transactions t, then t lines date amount in ascending date order, all inside the period (several can share a date). Print Interest: X and Closing balance: Y, where Y is the balance after the last day without the interest, both with 2 decimals.
Sample tests
Input
2026-03-01 2026-03-31 50000 6.5 3 2026-03-05 25000 2026-03-18 -40000.50 2026-03-18 -10000
Expected output
Interest: 271.57 Closing balance: 24999.50
Input
2028-02-20 2028-03-05 1000 10 1 2028-02-29 500
Expected output
Interest: 4.93 Closing balance: 1500.00
Your answer is also checked against 4 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
