The code demonstrates the concept of method overriding
The parent class Employee has method bonus which is overridden in derived class Staff.
The bonus for Employee is 5% and bonus for staff is 10%.
Do ask if any doubt. Please up-vote.
[21] The following code demonstrates the concept of method class Employee: def_init__(self): def bonus(self): return self.salary...
(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
Consider the following code for a Fraction class: self. numerator = 0 self tsn return self. denominator # Greatest Common Divisor def GCD (self, m, n): while n != 0: m=t return m def reduce(self): gcd - self.GCD(self._numerator, self._denominator) self. numerator int(self,_numerator / gcd) self'-denominator înt (self-denominator, gcd) def_str (self): 프 str(self-numerator). "ItDenominator, return "Numerator : str(self,-deno 프, . minator) Write a Unittest framework class to test the GCD method presented in the Fraction class Upload your answer code to...
Code Example 14-3 class Multiplier: def __init__(self): self.num1 = 0 self.num2 = 0 def getProduct(self): return self.num1 * self.num2 def main(): m = Multiplier() m.num1 = 7 m.num2 = 3 print(m.num1, "X", m.num2, "=", m.getProduct()) if __name__ == "__main__": main() Refer to Code Example 14-3: When this code is executed, what does it print to the console? a. 7 X 3 = 0 b. 3 X 7 = 0 c. 7 X 3...
class Leibniz: def __init__(self): self.total=0 def calculate_pi(self,n): try: self.total, sign = 0, 1 for i in range(n): term = 1 / (2 * i + 1) self.total += term * sign sign *= -1 self.total *= 4 return self.total except Exception as e: ...
Take the class Person. class Person: """Person class""" def __init__(self, lname, fname, addy=''): self._last_name = lname self._first_name = fname self._address = addy def display(self): return self._last_name + ", " + self._first_name + ":" + self._address Implement derived class Student In the constructor Add attribute major, default value 'Computer Science' Add attribute gpa, default value '0.0' Add attribute student_id, not optional Consider all private Override method display() Test your code with the following driver: # Driver my_student = Student(900111111, 'Song', 'River')...
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'.
Can you complete the following
code, please? Thank you.
class BinaryNode:
def __init__(self, value):
self.__value = value
self.__left = None
self.__right = None
self.__parent = None
self.__height = 1
def getValue(self):
return self.__value
def setHeight(self, height):
self.__height = height
def getHeight(self):
return self.__height
def setParent(self, node):
self.__parent = node
def getParent(self):
return self.__parent
def setLeftChild(self, child):
self.__left = child
child.setParent(self)
def setRightChild(self, child):
self.__right = child
child.setParent(self)
def createLeftChild(self, value):
self.__left = BinaryNode(value)
def createRightChild(self, value):
self.__right = BinaryNode(value)
def...
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 and according to this
#Creating class for stack
class My_Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def Push(self, d):
self.items.append(d)
def Pop(self):
return self.items.pop()
def Display(self):
for i in reversed(self.items):
print(i,end="")
print()
s = My_Stack()
#taking input from user
str = input('Enter your string for palindrome checking:
')
n= len(str)
#Pushing half of the string into stack
for i in range(int(n/2)):
s.Push(str[i])
print("S",end="")
s.Display()
s.Display()
#for the next half checking the upcoming string...
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...