class Simpy: values: list[float] # TODO: Your constructor and methods will go here. def _init_(self, list) -> None: "*"initialize values' self.values = list def str_(self) -> str: "*"Print value as a string." return str(self.values) def fill(self, full: float, f: int) -> None: "*"Fill the values with a specific repeating value.' self.values = [full] * f %3D def arange(self, start: float, stop: float, step: float = 1.0): "*"Fill in values attribute with range of values.""" assert step != 0.0 start while r != stop: self.values.append(r) r += step def sum(self) -> float: return sum(self.values)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Part 5. Operator Overload:
add
Next, you will add the ability to use the addition operator (+) in conjunction with Simpy objects and floats.
You will implement
add
such that the left-hand side operand of an addition expression can be either a simpy object or a float value
using a Union type. The
add_method should return a new Simpy object and should not mutate the object the method is called on.
When the right-hand side of an addition expression is also a simpy object, you should assert that both objects' values attributes have equal
lengths. Then, you should produce a new simpy object where each item in its values attribute corresponds to the items of the original
Simpy objects at the same index added together. For example:
a = Simpy([1.0, 1.0, 1.0])
b = Simpy([2.0, 3.0, 4.0])
c = a + b
print(c)
# Output: Simpy([3.0, 4.0, 5.0])
When the right-hand side of an addition expression is a float value, you should produce a new simpy object where each item corresponds to
the item at the same index in the left-hand side simpy object added to the float. For example:
a = Simpy( [1.0, 2.0, 3.0])
b = a + 10.0
print (b)
# Output: Simpy([11.0, 12.0, 13.0])
The signature of the
add
function should be:
def_add_(self, rhs: Union[float, Simpy]) -> Simpy:
# This cell tests a Simpy + Simpy
a = Simpy([1.0, 1.0, 1.0])
b = Simpy([2.0, 3.0, 4.0])
C = a + b
print("Actual: ", c, " - Expected: Simpy ([3.0, 4.0, 5.0])")
print("Actual: ", a + a,
- Expected: Simpy([2.0, 2.0, 2.0])")
- Expected: Simpy([4.0, 6.0, 8.0])")
print("Actual: ", b + b,
Python
# This cell tests a Simpy + float
a = Simpy([1.0, 2.0, 3.0])
b 3D а + 10.0
print("Actual: ", b, "
print("Actual:
Expected: Simру ([11.0, 12.0, 13.0])")
Expected: Simpy ([2.0, 3.0, 4.0])")
a + 1, "
Python
Transcribed Image Text:Part 5. Operator Overload: add Next, you will add the ability to use the addition operator (+) in conjunction with Simpy objects and floats. You will implement add such that the left-hand side operand of an addition expression can be either a simpy object or a float value using a Union type. The add_method should return a new Simpy object and should not mutate the object the method is called on. When the right-hand side of an addition expression is also a simpy object, you should assert that both objects' values attributes have equal lengths. Then, you should produce a new simpy object where each item in its values attribute corresponds to the items of the original Simpy objects at the same index added together. For example: a = Simpy([1.0, 1.0, 1.0]) b = Simpy([2.0, 3.0, 4.0]) c = a + b print(c) # Output: Simpy([3.0, 4.0, 5.0]) When the right-hand side of an addition expression is a float value, you should produce a new simpy object where each item corresponds to the item at the same index in the left-hand side simpy object added to the float. For example: a = Simpy( [1.0, 2.0, 3.0]) b = a + 10.0 print (b) # Output: Simpy([11.0, 12.0, 13.0]) The signature of the add function should be: def_add_(self, rhs: Union[float, Simpy]) -> Simpy: # This cell tests a Simpy + Simpy a = Simpy([1.0, 1.0, 1.0]) b = Simpy([2.0, 3.0, 4.0]) C = a + b print("Actual: ", c, " - Expected: Simpy ([3.0, 4.0, 5.0])") print("Actual: ", a + a, - Expected: Simpy([2.0, 2.0, 2.0])") - Expected: Simpy([4.0, 6.0, 8.0])") print("Actual: ", b + b, Python # This cell tests a Simpy + float a = Simpy([1.0, 2.0, 3.0]) b 3D а + 10.0 print("Actual: ", b, " print("Actual: Expected: Simру ([11.0, 12.0, 13.0])") Expected: Simpy ([2.0, 3.0, 4.0])") a + 1, " Python
class Simpy:
values: list[float]
# TODO: Your constructor and methods will go here.
def
_init_(self, list) -> None:
"""initialize values""
self.values = list
def _str_(self) -> str:
"""Print value as a string.'
II II
return str(self.values)
def fill(self, full: float, f: int) -> None:
II II II
"""Fill the values with a specific repeating value."
self.values
[full] * f
def arange(self, start: float, stop: float, step: float = 1.0):
"""Fill in values attribute with range of values."
assert step != 0.0
r = start
while r != stop:
self.values.append(r)
r += step
def sum(self) -> float:
return sum(self.values)
Transcribed Image Text:class Simpy: values: list[float] # TODO: Your constructor and methods will go here. def _init_(self, list) -> None: """initialize values"" self.values = list def _str_(self) -> str: """Print value as a string.' II II return str(self.values) def fill(self, full: float, f: int) -> None: II II II """Fill the values with a specific repeating value." self.values [full] * f def arange(self, start: float, stop: float, step: float = 1.0): """Fill in values attribute with range of values." assert step != 0.0 r = start while r != stop: self.values.append(r) r += step def sum(self) -> float: return sum(self.values)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY