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)....
Write a Python class Matrix which defines a two-by-two matrix with float entries as a Python...
Write a Python class Matrix which defines a two-by-two matrix with float entries as a Python object. The class Matrix has to be able to display the object on the screen when the print function is called, and it should include methods determinant(), trace(), inverse(), characteristic_polynomial(), and matrix_product(). Furthermore, a user should be able to multiply the matrix by a constant and be able to add and subtract two matrices using the usual symbols + and -. Use the following...
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...
Java assignment: You are tasked with building a BookStore. Your Architect has told you that the...
Java assignment: You are tasked with building a BookStore. Your Architect has told you that the BookStore class has the following members : long id; String name; Address address; Book book; The Address class has the following attributes : String streetName; String houseNumber; String apartmentNumber; String zipCode; The book class has the following members String name; String isbn; Author author; The Author class within the book class has the following member : String firstName; String lastName; Date dateOfBirth; Address address;...
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...