Exercise 46
1. Define a Book class with the following attributes: Title, Author (Full name), Price.
2. Define a constructor used to initialize the attributes of the method with values entered by the user.
3. Set the View() method to display information for the current book.
4. Write a program to testing the Book class.
Solution
# Question 1
class Book:
# Question 2
def __init__(self , Title , Author , Price):
self.Title = Title
self.Author = Author
self.Price = Price
# Question 3
def view(self ):
return ("Book Title: " , self.Title , "Book Author: " , self.Author, "Book Price: " , self.Price)
# Question 4
MyBook = Book("Python Crash Course" , "Eric Matthes" , "23 $")
print( MyBook.view())
# The output: ('Book Title: ', 'Python Crash Course', 'Book Author: ', 'Eric Matthes', 'Book Price: ', '23 $')
Younes Derfoufi
my-courses.net
my-courses.net