class Vector3D: def __init__(self, x, y, z): # TODO: Create a routine that saves the vector # into this Vector3D object. pass def __add__(self, other): # TODO: Create a routine that adds this vector with Vector3D other # and returns the result as a Vector3D object return None def __neg__(self): # TODO: Create a routine that returns the negative (opposite) of # this vector as a Vector3D object return None def __sub__(self, other): # TODO: Create a routine that subtracts this vector with Vector3D other # and returns the result as a Vector3D object return None def __mul__(self, other): # TODO: Create a routine that multiplies this vector with other # depending on its data type, and returns the result as a # Vector3D object. other can either be an integer # scalar or a Vector3D object. return None def main():
PYTHON Activity: (see pic about class Vector3D)
Given code:
class Vector3D:
def __init__(self, x, y, z):
# TODO: Create a routine that saves the vector
# <x, y, z> into this Vector3D object.
pass
def __add__(self, other):
# TODO: Create a routine that adds this vector with Vector3D other
# and returns the result as a Vector3D object
return None
def __neg__(self):
# TODO: Create a routine that returns the negative (opposite) of
# this vector as a Vector3D object
return None
def __sub__(self, other):
# TODO: Create a routine that subtracts this vector with Vector3D other
# and returns the result as a Vector3D object
return None
def __mul__(self, other):
# TODO: Create a routine that multiplies this vector with other
# depending on its data type, and returns the result as a
# Vector3D object. other can either be an integer
# scalar or a Vector3D object.
return None
def main():
testcases = int(input())
for t in range(testcases):
line_in = input().split()
op = line_in[0].strip()
vec_vals = [int(x) for x in line_in[1:]]
# TODO: a Write routine that processes a line in the input
# op - string
# - operation to do with the provided vectors
# - can only be one from the set: {add, sub, neg, mul_s, mul}
# vec_vals - list of integers
# - numbers that follow the op in the input line
# - can only have a length of 3, 4, or 6
if __name__ == '__main__':
main()
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images