1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Simora [160]
2 years ago
11

In python please.

Computers and Technology
1 answer:
Aloiza [94]2 years ago
3 0

Answer:

class Book:
   def __init__(self, book_title, book_author, book_publisher):

       self.__book_title = book_title

       self.__book_author = book_author

       self.__book_publisher = book_publisher

Explanation:

Python kind of haves private data attributes, although technically they don't.

Take for example the following code:

"

class A:

   def __init__(self):

       self.__privateAttribute = 0

x = A()

print(x.__privateAttribute)

"

all this really does is rename the variable name, and if you run the following code:

print(dir(x))

it will print the attributes of "x" which include "_A__privateAttribute" which is the attribute that was initialized.

Anyways getting that out of the way, you need to now about the __init__ method, which runs each time you initialize a new instance of the class. It's a way of setting up some necessary values that will be used in the objects methods (the functions inside the class)

So, because we simply cannot know what the book_title, book_author, and book_publisher are (since they vary book to book...), we take them as arguments using the __init__ method, and then initialize their values in their.

"

class Book:
   def __init__(self, book_title, book_author, book_publisher):

       self.__book_title = book_title

       self.__book_author = book_author

       self.__book_publisher = book_publisher

"

I just realized I completely forgot to even mention what the "self" variable stands for. Whenever you initialize a variable, or call a method from an instance of the class, the first argument passed will be the instance of the class. Take for example the following class

"

class A:

   def __init__(self, b):
       self.b = b

   def printB(self):
       print(self.b)

def printB(self):

   print(self.b)

c = A(3)

d = A(4)

c.printB()

printB(c)

d.printB()

printB(d)

"

The two lines

c.printB() and printB(c) are the same exact thing, the only difference is when you call c.printB(), you automatically pass the "c" as the first argument, and the same thing for d.printD(), it's implicitly passed whenever you call a method from an instance of the class.

You might be interested in
Hat are three machines or devices that depend on gravity to work?
jonny [76]
Some devices that depend on gravity to function include scales, showers, and satellites, to list a few.
6 0
3 years ago
Review the HTML tags that we have gone over in this lesson. Research HTML tags on the web and identify two new tags. Use these t
NemiM [27]

Answer:

w3schools

Explanation:

there is a webiste called w3schools that really helped me through my web page design class, just click on learn html

4 0
3 years ago
What are the functions of the windows button, Task View and Search Box? give me short answer
artcher [175]

Answer:

Windows button = You can see a Start Menu

Task view = You can view your Tasks

Search Box = You can search any app you want in an instance

6 0
3 years ago
4.15 LAB: Mad Lib - loops Mad Libs are activities that have a person provide various words, which are then used to complete a sh
Sergio039 [100]

Answer:

Following are the program in the Python Programming Language.

#set the infinite while loop

while(True):

 #get string input from the user

 name=input()

 #get integer input from the user

 num=int(input())

 #set the if statement to break the loop

 if(num==0):

   break

 #otherwise, print the following output

 else:

   print("Eating {} {} a day keeps the doctor away.".format(num, name))

<u>Output</u>:

oranges

5

Eating 5 oranges a day keeps the doctor away.

apple

0

Explanation:

<u>Following are the description of the program</u>:

  • Set the loop that iterates at infinite times and inside the loop.
  • Declare two variables which are 'name' that get string type input from the user and 'num' that get integer type input from the user.
  • Set the if conditional statement for break the infinite while loop.
  • Otherwise, it prints the following output.
7 0
3 years ago
Insurance can help you:a. minimize monthly expenses
KIM [24]
This is an easy answer sure in the back of your mind u knew it was b good luck :).

4 0
3 years ago
Other questions:
  • Determine encryption that is needed to provide security for the company’s system. This will include plans to address: Passive an
    11·1 answer
  • Mathematical computations by a computer are faster than your quickest mathematical computations because the top speed of a neura
    13·1 answer
  • Technician A says that in any circuit, electrical current takes the path of least resistance. Technician B says that while this
    11·2 answers
  • In this activity, you'll decide how a computer (in this case, a smartphone)
    12·1 answer
  • If you're using the paintbrush tool and want to change the color of the paint being used what should you change
    6·1 answer
  • Write a Temperature class that will hold a temperature in Fahrenheit and provide methodsto get the temperature in Fahrenheit, Ce
    14·1 answer
  • Crees que es necesario que el estado Peruano, proponga nuevamente el aislamiento desde este 22 de diciembre al 02 de enero del 2
    6·1 answer
  • suppose as a head software engineer you assign the job of creating a class to a subordinate. You want to specify thirty-eight di
    11·1 answer
  • What is the difference between information poor and information rich<br>​
    13·1 answer
  • Ninety percent of the fastest-growing jobs require some kind of postsecondary education.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!