Python Programming - Objects - Discussion

Discussion Forum : Objects - General Questions (Q.No. 30)
30.
Consider the following Python code:
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def distance_from_origin(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5
If you create an instance of the `Point` class called p with coordinates (3, 4), what will be the result of calling p.distance_from_origin()?
7
25
5
10
Answer: Option
Explanation:
The distance_from_origin method calculates the distance of the point from the origin using the distance formula.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.