In PYTHON:
Assume there is a class Animal, containing a method with the header: def __init__(self).
What statement will create an Animal object and store it in the variable 'cat'.
statement will create an Animal object and store it in the variable 'cat' is cat = Animal()
cat = Animal()
In PYTHON: Assume there is a class Animal, containing a method with the header: def __init__(self)....
In Python: Which one is the arguments of the ShowInfo method? class Car(): def __init__(self,model, year): self._model = model self._year = year def ShowInfo( ): print(self._model + str(self._year)) Question 16 options: model, year No argument is needed self,model, year self
class FileUtility: def __init__ (self, filename): self.__filename = filename def displayFile(self): # use loop structure to read and print each line of the file def main(): #1. create a new file and write the follwing lines to it. # #I never saw a Purple Cow, #I never hope to see one, #But I can tell you, anyhow, #I’d rather see than be one! # #2. create an object of FileUtility class #3. call the object's displayFile method main()
(python please!)
[21] The following code demonstrates the concept of method class Employee: def _init__(self): def bonus(self): return self.salary * 0.05 class Staff(Employee): def __init__(self): def bonus(self): return self.salary * 0.10
In Python: Which keyword should be replaced instead of X? class Class(Car): def __init__ (self,arg1,arg2): X.__init__(arg1,arg2) Question 21 options: class def super() super
PYTHON
--------------------------------------------------------
class LinkedList:
def __init__(self):
self.__head = None
self.__tail = None
self.__size = 0
# Return the head element in the list
def getFirst(self):
if self.__size ==
0:
return
None
else:
return
self.__head.element
# Return the last element in the list
def getLast(self):
if self.__size ==
0:
return
None
else:
return
self.__tail.element
# Add an element to the beginning of the
list
def addFirst(self, e):
newNode = Node(e) #
Create a new node
newNode.next =
self.__head # link...
How to convert this python to c++? class SOMENode: def __init__(self, name, parent, verbose=False): self.name = name self.parent = parent self.children = [] if self.parent: self.parent.add_child(self) self.verbose = verbose
Code Example 14-2 class Die: def __init__(self): self.__value = 1 def getValue(self): return self.__value def roll(self): self.__value = random.randrange(1, 7) Refer to Code Example 14-2: Given a Die object named die, which of the following will print the value of the __value attribute to the console? a. print(die.getValue()) b. print(die.roll()) c. print(die.value) d. print(die.__value) To prevent another programmer from directly accessing the attributes of an object, you use a. instantiation b. composition ...
Consider following flower class. class Flower: def __init__(self, Fname, numberofpetals, Fprice): self.Fname = Fname self.numberofpetals = numberofpetals self.Fprice = Fprice def getName(self): return self.Fname def getPetalsCount(self): return self.numberofpetals def getPrice(self): return self.Fprice def setName(self, Fname): self.Fname = Fname def setPetalsCount(self, numberofpetals): self.numberofpetals = numberofpetals def setPrice(self, Fprice): self.Fprice = Fprice def main(): flower f, print("name = ", flower.getName()) flower.setName("jasmine") print("name = ", flower.getName()) main() Q. What is the statement to set an object flower with rose , 4 and price...
In Python Exercise – Overriding class Address: def __init__(self, street, num): self.street_name = street self.number = num Now make a subclass of the class Address called CampusAddress that has a new attribute, office number, that can vary. This subclass will always have the street attribute set to Massachusetts Ave and the num attribute set to 77. Use the class as follows: >>> Sarina_addr = CampusAddress("32-G904") >>> Sarina_addr.office_number ’32G-904’ >>> Sarina_addr.street_name ’Massachusetts Ave’ >>> Sarina_addr.number 77
Here is a Python program. import turtle class Box: def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height def show(self): turtle.up() turtle.goto(x, y) turtle.down() for _ in range(2): turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) bigbox = Box(-100, -150, 200, 300) bigbox.show() turtle.done() If you run the above program, it will produce an error. What is the keyword that has...