For this lab you will create a custom class that implements a point in 3-D space. Name your class 'pt3d'. The class will

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

For this lab you will create a custom class that implements a point in 3-D space. Name your class 'pt3d'. The class will

Post by answerhappygod »

For this lab you will create a custom class that implements a point in 3-D space. Name your class 'pt3d'.
The class will have three attributes, x,y,z. These x,y,z values should default to zero.
Given two instances of the pt3d class a and b, implement methods such that:
a+b returns a new pt3d object whose x, y and z values are the sum of the a and b x, y and z values
a-b returns the Euclidean distance between points a and b
a==b returns true if the x, y and z values of a and b are equal, false otherwise
When you call print(a) the printout should be of the format '<a.x,a.y,a.z>'
You can test and develop your class either from the main block in your program, from another module, or using the python interpreter directly:
>>> from pt3d import pt3d
>>> p1=pt3d(1,1,1)
>>> p2=pt3d(2,2,2)
>>> print(p1+p2)
<3,3,3>
>>> print(p1-p2)
1.7320508075688772
>>> p1==p2
False
>>> p1+p1==p2
True
>>> p1==p2+pt3d(-1,-1,-1)
True
`
LAB ACTIVITY 11.26. 1:3-D point class 0/10 pt3d.py Load fandt lass ptsd: class implementation goes here Develop mode Submit mode Run your program as often as you'd like, before submitting for grading Below, type any needed input values in the fust box then click Run program and observe the programmis output in the second box
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply