169. Python Program to Make a Library Due Date and Fine Calculator
Harddatetime
Overview
Put the whole chapter together: two modules, date maths, formatting and error handling.
Problem Statement
A library lends books for 14 days. Read the date a book was borrowed, then the date it came back, one per line, as YYYY-MM-DD. Print:
Due date:and the due date (14 days after borrowing), written likeFriday 28 March 2025.Days late:and how many days after the due date the book came back (0if it came back on or before the due date).Fine:10 for every started week late. 1 to 7 days late is 10, 8 to 14 days is 20, and so on.
For example, for 2025-03-14 and 2025-03-31:
Due date: Friday 28 March 2025
Days late: 3
Fine: 10
Two special cases, each printed alone:
- If either line isn't a real date in
YYYY-MM-DDform, printInvalid date. - If the return date is before the borrow date, print
Return date is before borrow date.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
Two dates, one per line. Example:
2025-03-14
2025-03-31
Output
The output for that example:
Due date: Friday 28 March 2025
Days late: 3
Fine: 10
The tests try 6 different inputs.