livepython.net

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:

  1. Due date: and the due date (14 days after borrowing), written like Friday 28 March 2025.
  2. Days late: and how many days after the due date the book came back (0 if it came back on or before the due date).
  3. 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-DD form, print Invalid 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.

Learn this firstChapter 18 · Python datetime Module: Dates, timedelta and strftime
solution.py
# write your code here

EXPECTED OUTPUT

1Due date: Friday 28 March 2025
2Days late: 3
3Fine: 10

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.