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():

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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()

PYTHON Activity: Class Vector3D
Input Format
The first line of the input is an integer T denoting the number of lines that will follow. Each line then consists
of a variable number of elements separated by a space. The line starts with a word op denoting what
operation to do. The operations will only be any of the following: add, sub, neg, mul_s, mul.The next
elements will be space-separated numbers.
Input (Testcase):
5
add 1 2 3 4 5 6
sub 1 2 3 4 5 6
mul s 1 2 3 -2
mul 1 2 3 4 5 6
For add, sub, and mul, op will be followed by six numbers a, ay az bz by bz corresponding to the
coordinates of vectors a and b respectively.,
neg 3 3 3
For mul_s,op will be followed by four numbers ag ay az s corresponding to the coordinates of the vector a
and a scalar s, respectively.
Expected Output
For neg, op will be followed by three numbers az ay az corresponding to the coordinates of the vector a.
5 7 9
-3 -3 -3
Constraints
-2 -4 -6
4 10 18
Input Constraints
-3 -3 -3
T< 100
A = (ap, ay, az) E Z3, {a; € Z: [a;| < 10°}
op € {add, sub, neg, mul, mul_s}
Max running time of code should be < 5 seconds for each test input.
You can assume that all of the inputs are well-formed and are always provided within these constraints. You
are not required to handle any errors.
Functional Constraints
You are required to create a class named Vector3D with an __init__(self, x, y, z) function. It should
also have the following special functions: _add__,
sub__, __neg__, -_mul__. Failure to do so will mark
your code with a score of zero.
Output Format
The output consists of T lines, with each line i corresponding to the 3D vector a;g aiy aig that is the result
of performing the operation requested on that line.
Transcribed Image Text:PYTHON Activity: Class Vector3D Input Format The first line of the input is an integer T denoting the number of lines that will follow. Each line then consists of a variable number of elements separated by a space. The line starts with a word op denoting what operation to do. The operations will only be any of the following: add, sub, neg, mul_s, mul.The next elements will be space-separated numbers. Input (Testcase): 5 add 1 2 3 4 5 6 sub 1 2 3 4 5 6 mul s 1 2 3 -2 mul 1 2 3 4 5 6 For add, sub, and mul, op will be followed by six numbers a, ay az bz by bz corresponding to the coordinates of vectors a and b respectively., neg 3 3 3 For mul_s,op will be followed by four numbers ag ay az s corresponding to the coordinates of the vector a and a scalar s, respectively. Expected Output For neg, op will be followed by three numbers az ay az corresponding to the coordinates of the vector a. 5 7 9 -3 -3 -3 Constraints -2 -4 -6 4 10 18 Input Constraints -3 -3 -3 T< 100 A = (ap, ay, az) E Z3, {a; € Z: [a;| < 10°} op € {add, sub, neg, mul, mul_s} Max running time of code should be < 5 seconds for each test input. You can assume that all of the inputs are well-formed and are always provided within these constraints. You are not required to handle any errors. Functional Constraints You are required to create a class named Vector3D with an __init__(self, x, y, z) function. It should also have the following special functions: _add__, sub__, __neg__, -_mul__. Failure to do so will mark your code with a score of zero. Output Format The output consists of T lines, with each line i corresponding to the 3D vector a;g aiy aig that is the result of performing the operation requested on that line.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Study of Characters
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education