forked from NBHS-STEM/library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
88 lines (58 loc) · 2.11 KB
/
library.py
File metadata and controls
88 lines (58 loc) · 2.11 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import json
def open_library(filename):
# Create empty dictionaries just in case the library file is empty
students = {}
books = {}
# Open the library file encoded in JSON and load it into the data object
# We use the with keyword so we don't have to explicitly close the file
# later.
#
# Alternatively you could use:
#
# f = open(filename)
# data = json.load(f)
# f.close()
#
# and accomplish the same thing.
with open(filename) as f:
data = json.load(f)
# If there are students or books in the library,
# overwrite the empty dictionaries we created
if data['students'] != {}:
students = data['students']
if data['books'] != {}:
books = data['books']
# Return the data we loaded from the file
return students, books
def add_book(filename, isbn, title, author):
# Here's a start
students, books = open_library(filename)
# Now how can we add books to the data?
# In the space below, write code that adds the key isbn
# and the value {'title':title, 'author':author}
# to the books object.
# Finally, write code that writes the new data to the library
# Do we need to return anything?
pass
def remove_book(filename, isbn):
students, books = open_library(filename)
# How can we *remove* an item from a dictionary?
# Write code to delete the book keyed by isbn in the space below
# Now write code that saves the new version of the data to your library
pass
def check_out(filename, isbn, s_id):
students, books = open_library(filename)
# Find a way to mark a book as checked out. Be sure to associate
# the book with the student who borrowed it!
# And again save the data here
pass
def return_book(filename, isbn):
students, books = open_library(filename)
# Now ensure that the book is no longer checked out and save the changes
# to the library.
pass
def status(filename):
students, books = open_library(filename)
# Print out two lists - one of all books currently checked out,
# and one of all available books.
pass