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 30 ?
flower = Flower("rose",4, 30)
flower = Flower(rose,4, 30)
flower = Flower('rose',4, 30)
flower = Flower("rose",'4', '30')?
the statement to set an object flower with rose , 4 and price 30 flower = Flower("rose",4, 30)
Option 1
Consider following flower class. class Flower: def __init__(self, Fname, numberofpetals, Fprice): self.Fname = Fname self.numberofpetals =...
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')...
9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name, age) + getName + getAge0 def init (self, name, age): self.mName = name self.mAge = age Dog Cat def getName(self): return self.mName mSize mColor + __init__(name, age,size) + getSize() + momCommento + getDog Years() +_init__(name, age,color) + getColor + pretty Factor + getCatYears def getAge(self): return self.mAge #dog.py import pet #cat.py import pet class Dog (pet. Pet): class Cat (pet. Pet): def init (self,...
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...
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: ...
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'.
I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress='' def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress def getName(self): return self.__publisherName def setName(self,publisherName): self.__publisherName=publisherName def getAddress(self): return self.__publisherAddress def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...
PYTHON 3.8 class student(): def __init__(self, name = 'Bill', grade = 9, subjects = ['math','science']): self.name = name self.grade = grade self.subjects = subjects def add_subjects(self): print('Current subjects:') print(self.subjects) more_subjects = True while more_subjects == True: subject_input = input('Enter a subject to add: ') if subject_input == '': more_subjects = False print(self.subjects) else: self.subjects.append(subject_input) print(self.subjects) m = student()...
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...
class BinaryTree: def __init__(self, data, left=None, right=None): self.__data = data self.__left = left self.__right = right def insert_left(self, new_data): if self.__left == None: self.__left = BinaryTree(new_data) else: t = BinaryTree(new_data, left=self.__left) self.__left = t def insert_right(self, new_data): if self.__right == None: self.__right = BinaryTree(new_data) else: t = BinaryTree(new_data, right=self.__right) self.__right = t def get_left(self): return self.__left def get_right(self): return self.__right def set_data(self, data): self.__data = data def get_data(self): return self.__data def set_left(self, left): self.__left = left def set_right(self, right): self.__right...