A point identified by the co-ordinates x,y is at a distance from the origin identified by the co-ordinates 0,0. Let’s write a Python program to find the distance of a point from the origin.
How to find the distance of a point from the origin?
The distance between a given point (x,y) from the origin (0,0) can be calculated using the formula given below.
- Distance from Origin = Square Root of (x*x + y*y)
The sqrt function from math module of Python can be used to calculate the distance.
Python code (to calculate the distance)
#Program to find the distance of a point from the origin
import math
x = int(input("Enter the x co-ordinate "))
y = int(input("Enter the y co-ordinate "))
d = math.sqrt(x*x + y*y)
print("The distance from the origin is ", d)