Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7773221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:05:04+00:00 2026-06-01T17:05:04+00:00

So having some trouble with a class methods. I’ll post all the information that

  • 0

So having some trouble with a class methods. I’ll post all the information that I have. I need to write the relevant methods for the questions given.

import math
epsilon = 0.000001
class Point(object):
    def __init__(self, x, y):
        self._x = x
        self._y = y

    def __repr__(self):
        return "Point({0}, {1})".format(self._x, self._y)

First question; i need to add a method, called disttopoint that takes another point object, p, as an argument and returns the euclidean distance between the two points. I can use math.sqrt.

test cases:

abc = Point(1,2)
efg = Point(3,4)
abc.disttopoint(efg) ===> 2.8284271

Second question; add a method, called isnear that takes another point object, p, as an argument and returns True if the distance between this point and p is less than epsilon (defined in the class skeleton above) and False otherwise. Use disttopoint.

test cases:

abc = Point(1,2)
efg = Point(1.00000000001, 2.0000000001)
abc.isnear(efg) ===> True

Third question; add a method called addpoint that takes another point object p as an arguement and changes this point so that it is the sum of the oint’s old value and the value of p.

test cases;

abc = Point(1,2)
efg = Point(3,4)
abc.add_point(bar)
repr(abc) ==> "Point(4,6)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:05:06+00:00Added an answer on June 1, 2026 at 5:05 pm
    class Point(object):
        # __init__ and __repr__ methods
        # ...
        def disttopoint(self, other):
            # do something using self and other to calculate distance to point
            # result = distance to point
            return result
    
        def isnear(self, other):
            if (self.disttopoint(other) < epsilon):
                return True
            return False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having some trouble getting the syntax right. I have a movie clip that
I'm having some trouble understanding this issue. I have a class: class StringProperty {
Im having some trouble with part of a lab for class, most of it
I'm having trouble implementing a nested class who's constructor is initialized with some of
I´m having some trouble retrieving a collection of strings in a projection: say that
Im having some trouble writing a getstring function, this is what I have so
When designing both the domain-model and class-diagrams I am having some trouble understanding what
I'm having trouble deserializing a ruby class that I wrote to YAML. Where I
I'm having some trouble with adding tips to a Request.HTML function. I have a
I am having some trouble wrapping my head around virtual proxies. I have read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.