-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturnbook.py
More file actions
53 lines (35 loc) · 1.34 KB
/
Copy pathreturnbook.py
File metadata and controls
53 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from datetime import datetime
from utisils import issued
def return_book(library):
print("\n----- Return Book -----")
bookid = input("Enter Book ID: ")
username = input("Enter your name: ")
for record in issued:
if record["bookid"] == bookid and record["user"] == username:
due_date = datetime.strptime(record["due_date"], "%Y-%m-%d")
return_date = datetime.now()
late_days = (return_date - due_date).days
if late_days <= 0:
return 0
total_fine = 0
for day in range(1, late_days + 1):
week = (day - 1) // 7 + 1 # week number
# factorial logic
fact = 1
for i in range(1, week + 1):
fact *= i
daily_fine = 10 * fact
total_fine += daily_fine
return total_fine
for book in library:
if book["id"] == bookid:
book["quantity"] += 1
book["status"] = "Available"
issued.remove(record)
print("Book returned successfully!")
if fine > 0:
print(f"Late return! Fine: ₹{fine}")
else:
print("No fine!")
return
print("Record not found!")