Question

By using Python: a, Make a class called Book. The __init__() method for Book should store...

By using Python:

a, Make a class called Book. The __init__() method for Book should store two attributes: a title and an author. Make a method called book_info() that prints these two pieces of information, and a method called book_available() that prints a message indicating that the book is available in the library.

b. Create an instance called book1 from your class. Print the two attributes individually, and then call both methods.

Homework Answers

Answer #1
class Book:
    def __init__(self, title, author):
        self.title = title
        self.author = author

    def book_info(self):
        print("Title:", self.title)
        print("Author:", self.author)

    def book_available(self):
        print("the book is available in the library.")


b = Book("Harry Potter", "J. K. Rowling")
print(b.title)
print(b.author)
b.book_info()
b.book_available()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
Python Define a class called Animal that abstracts animals and supports three methods: setSpecies(species): Sets the...
Python Define a class called Animal that abstracts animals and supports three methods: setSpecies(species): Sets the species of the animal object to species. setLanguage(language): Sets the language of the animal object to language. speak(): Prints a message from the animal as shown below. The class must support supports a two, one, or no input argument constructor. Then define Bird as a subclass of Animal and change the behavior of method speak() in class Bird. >>> snoopy = Animal('dog', 'bark') >>>...
We encourage you to work in pairs for this challenge to create a Student class with...
We encourage you to work in pairs for this challenge to create a Student class with constructors. First, brainstorm in pairs to do the Object-Oriented Design for a Student class. What data should we store about Students? Come up with at least 4 different instance variables. What are the data types for the instance variables? Write a Student class below that has your 4 instance variables and write at least 3 different constructors: one that has no parameters and initializes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
Python #Imagine you're writing a program to check if a person is #available at a certain...
Python #Imagine you're writing a program to check if a person is #available at a certain time. # #To do this, you want to write a function called #check_availability. check_availability will have two #parameters: a list of instances of the Meeting class, and #proposed_time, a particular date and time. # #check_availability should return True (meaning the person #is available) if there are no instances of Meeting that #conflict with the proposed_time. In other words, it should #return False if proposed_time...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file....
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file. Both files must be in the same directory to compile. Display all dollar amounts using the DecimalFormat class. Create an account Ask the user for the type of account, the bank account number, the amount that they will deposit to start the account. Set interest earned to 0. Print the account information using an implicit or explicit call to toString Update an account Use...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT