Skip to content
Snippets Groups Projects
Commit 3469532b authored by majidrouhanintnu's avatar majidrouhanintnu
Browse files

upd

parent 08c9c44e
No related branches found
No related tags found
No related merge requests found
class Book:
def __init__(self, title=None, edition=None, price=None, currency=None):
# instance attributes
self.title = title
self.authors = []
self.chapters = []
self.edition = edition
self.price = price
self.currency = currency
# Getters and setters for instance attributes
def get_title(self):
return self.title
def set_title(self, title):
self.title = title
def get_pages(self):
return self.pages
def set_pages(self, pages):
self.pages = pages
def add_author(self,author):
self.authors.append(author)
def add_chapter(self,chapter):
self.chapters.append(chapter)
def get_edition(self):
return self.edition
def set_edition(self, edition):
self.edition = edition
def get_price(self):
return self.price
def set_price(self, price):
self.price = price
def get_currency(self):
return self.currency
def set_currency(self, currency):
self.currency = currency
# Magic methods
def __str__(self):
return f'{self.title}, {self.authors}, {self.edition}, {self.price:0.2f} {self.currency}, {self.chapters}'
\ No newline at end of file
%% Cell type:code id: tags:
``` python
from Book import Book
sowp_akademika = Book(title="Starting out with Python", edition='4th')
sowp_akademika.set_price(739)
sowp_akademika.set_currency('NOK')
sowp_akademika.add_author('Tony Gaddis')
sowp_akademika.set_pages(896)
sowp_akademika.add_chapter('Introduction to Programming')
sowp_akademika.add_chapter('Introduction to Python')
sowp_akademika.add_chapter('Control Statements')
sowp_akademika.add_chapter('Functions')
sowp_amazon = Book(title="Starting out with Python", edition='4th')
sowp_amazon.set_price(126.65)
sowp_amazon.set_currency('USD')
sowp_akademika.add_chapter('Introduction to Programming')
sowp_akademika.add_chapter('Introduction to Python')
sowp_akademika.add_chapter('Control Statements')
sowp_akademika.add_chapter('Functions')
print(sowp_akademika)
print(sowp_amazon)
print(str(sowp_akademika))
print(repr(sowp_akademika))
sowp_akademika(price=896*1.1, edition='5th')
print(sowp_akademika)
```
%% Output
Starting out with Python, ['Tony Gaddis'], 4th, 739.00 NOK, ['Introduction to Programming', 'Introduction to Python', 'Control Statements', 'Functions', 'Introduction to Programming', 'Introduction to Python', 'Control Statements', 'Functions']
Starting out with Python, [], 4th, 126.65 USD, []
Starting out with Python, ['Tony Gaddis'], 4th, 739.00 NOK, ['Introduction to Programming', 'Introduction to Python', 'Control Statements', 'Functions', 'Introduction to Programming', 'Introduction to Python', 'Control Statements', 'Functions']
Title = Starting out with Python, Auhor = ['Tony Gaddis'], Edition = 4th, Price = 739, Currency = NOK
Starting out with Python, ['Tony Gaddis'], 5th, 985.60 NOK, ['Introduction to Programming', 'Introduction to Python', 'Control Statements', 'Functions', 'Introduction to Programming', 'Introduction to Python', 'Control Statements', 'Functions']
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment