forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise11.py
More file actions
29 lines (22 loc) · 856 Bytes
/
Copy pathexercise11.py
File metadata and controls
29 lines (22 loc) · 856 Bytes
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
class Author:
def __init__(self, full_name, email):
self.full_name = full_name
self.email = email
class Book:
def __init__(self, title, authors, price, copies):
self.title = title
self.authors = authors
self.price = price
self.copies = copies
def print_full_title(self):
authors_names = [author.full_name for author in self.authors]
print("'" + self.title + "' by ", end="")
print(", ".join(authors_names))
def add_author(self, author):
self.authors.append(author)
p1 = Author("Bob Paterson", "bob@pcookbook.com")
p2 = Author("James McConan", "james@pcookbook.com")
b = Book("The Ultimate Python Cookbook", [p1,p2], 18.25, 43)
b.print_full_title()
b.add_author(Author("Tom Rossbow", "tom@pcookbook.com"))
b.print_full_title()