Created
September 23, 2023 16:29
-
-
Save foxy4096/345fab9d2dbadef40175e51bfce73607 to your computer and use it in GitHub Desktop.
Misc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| class Point: | |
| """Represents a point in 2D space.""" | |
| def __init__(self, x, y): | |
| """ | |
| Initialize a Point object with x and y coordinates. | |
| Args: | |
| x (float): The x-coordinate of the point. | |
| y (float): The y-coordinate of the point. | |
| """ | |
| self.x = x | |
| self.y = y | |
| def distance(self, other): | |
| """ | |
| Calculate the Euclidean distance between this point and another point. | |
| Args: | |
| other (Point): The other point to calculate the distance to. | |
| Returns: | |
| float: The Euclidean distance between the two points. | |
| """ | |
| return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2) | |
| # Get input from the user for the coordinates of two points. | |
| x1, y1 = map(float, input("Enter coordinates for the first point (separated by space): ").split()) | |
| x2, y2 = map(float, input("Enter coordinates for the second point (separated by space): ").split()) | |
| # Create Point objects for the two coordinates. | |
| point1 = Point(x1, y1) | |
| point2 = Point(x2, y2) | |
| # Calculate and display the distance between the two points. | |
| distance = point1.distance(point2) | |
| print(f"The distance between the two points is: {distance}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment