-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.py
More file actions
70 lines (59 loc) · 1.77 KB
/
book.py
File metadata and controls
70 lines (59 loc) · 1.77 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
#
# Instances of this class represent books. A description of a book includes
#
# title, author, subject, and optional URL of the book's description
#
class Book:
def __init__ (self, t="", a="", s="", u=""):
#
# Create an instance of Book
#
self.title = t
self.last_name = []
self.first_name = []
self.set_author (a)
self.subject = s
self.url = u
def set_author(self, new_author):
#
# Author's name is in "last_name, first_name" format
#
if new_author:
names = new_author.split(",")
self.last_name.append ((names[0]).strip())
self.first_name.append ((names[1]).strip())
else:
self.last_name = []
self.first_name = []
def set_title (self, new_title):
self.title = new_title
def set_subject (self, new_subject):
self.subject = new_subject
def set_url (self, new_url):
self.url = new_url
def display (self):
print("Title : " + self.title)
i = 0
while i < len (self.first_name):
print ("Author : " + self.first_name[i] + " " + self.last_name[i])
i = i + 1
print ("Subject: " + self.subject)
print ("URL : " + self.url)
#
# Code to test this class
#
if __name__ == '__main__':
print ("**** Test 1 ****")
b = Book()
b.set_author ("Gann, Ernest")
b.set_title ("Fate is the Hunter")
b.set_subject ("General Aviation")
b.display ()
print ("*** Test 2 ****")
b = Book ("Fate is the Hunter", "Gann, Ernest")
b.display ()
print ("*** Test 3 ****")
b = Book ("Some book", "First, Author")
b.set_author ("Seconf, Author")
b.display ()
print ("*** Finish ***")