|
| 1 | +# Copyright (C) Deepali Srivastava - All Rights Reserved |
| 2 | +# This code is part of Python course available on CourseGalaxy.com |
| 3 | + |
| 4 | +class Book: |
| 5 | + def __init__(self,isbn, title,author,publisher,pages,price,copies): |
| 6 | + self.isbn = isbn |
| 7 | + self.title = title |
| 8 | + self.author = author |
| 9 | + self.publisher = publisher |
| 10 | + self.pages = pages |
| 11 | + self.price = price |
| 12 | + self.copies = copies |
| 13 | + |
| 14 | + def display(self): |
| 15 | + print(self.title) |
| 16 | + print(f'ISBN : {self.isbn}') |
| 17 | + print(f'Price : {self._price}') |
| 18 | + print(f'Number of copies : {self.copies}') |
| 19 | + print('.' * 50) |
| 20 | + |
| 21 | + @property |
| 22 | + def price(self): |
| 23 | + return self._price |
| 24 | + |
| 25 | + @price.setter |
| 26 | + def price(self, new_price): |
| 27 | + if 10 <= new_price <= 500: |
| 28 | + self._price = new_price |
| 29 | + else: |
| 30 | + raise ValueError('Price cannot be less than 10 or more than 500') |
| 31 | + |
| 32 | +book1 = Book('957-4-36-547417-1', 'Learn Physics','Stephen', 'CBC', 350, 200,10) |
| 33 | +book2 = Book('652-6-86-748413-3', 'Learn Chemistry','Jack', 'CBC', 400, 220,20) |
| 34 | +book3 = Book('957-7-39-347216-2', 'Learn Maths','John', 'XYZ', 500, 300,5) |
| 35 | +book4 = Book('957-7-39-347216-2', 'Learn Biology','Jack', 'XYZ', 400, 20,6) |
| 36 | + |
| 37 | +book1.display() |
| 38 | +book2.display() |
| 39 | +book3.display() |
| 40 | +book4.display() |
| 41 | + |
| 42 | + |
0 commit comments