PIXELBANKv8.2.1
Menu

Basic Class Creation

Problem Statement

Create a class to represent a 2D point.

Background

Python classes define objects with:

  • init: Constructor
  • Instance methods: Take self as first argument
  • str: String representation
  • repr: Developer representation

Your Task

Create a class Point with:

  • Constructor taking x and y coordinates
  • Method distance_to(other) returning Euclidean distance to another Point
  • Method translate(dx, dy) that moves the point and returns self
  • str returning "Point(x, y)"

Example:

Input:
Point(0, 0).distance_to(Point(3, 4))
Output:
5.0
Reasoning:

sqrt((3-0)^2 + (4-0)^2) = sqrt(9+16) = sqrt(25) = 5.0

Constraints:

  • Distance uses Euclidean formula: sqrt((x2-x1)^2 + (y2-y1)^2)
  • translate modifies the point in place and returns self
Editor

Test Results

0/0
Run code to see test results.