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 = 21 |
|
| d. |
3 X 7 = 21 |
What do you typically use to model the relationships between the classes in an object-oriented program?
| a. |
UML diagrams |
|
| b. |
Hierarchy charts |
|
| c. |
Pseudocode |
|
| d. |
Object models |
In a three-tier architecture, the database tier stores the code that
| a. |
handles all monetary transactions |
|
| b. |
controls the user interface |
|
| c. |
accesses the file or database |
|
| d. |
defines the business objects |
2 numbers of Multiplier are num1=7 and num2=3
output would be 7 X 3 = 21
To Model relationships between classes in object-oriented
program is
(a). UML diagrams
In a three-tier architecture, the database tier stores the code
that
accesses the file or database
(c)
Code Example 14-3 class Multiplier: def __init__(self): self.num1 = 0 self.num2 = 0 def...
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 ...
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: ...
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()
I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code...
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...
ill thumb up do your best
python3
import random
class CardDeck:
class Card:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return "{}".format(self.value)
def __init__(self):
self.top = None
def shuffle(self):
card_list = 4 * [x for x in range(2, 12)] + 12 * [10]
random.shuffle(card_list)
self.top = None
for card in card_list:
new_card = self.Card(card)
new_card.next = self.top
self.top = new_card
def __repr__(self):
curr = self.top
out = ""
card_list = []
while curr is not None:...
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...
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...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...