Skip to main content

Featured

Introduction to Numpy Library in Python

Introduction to Numpy Library in Python NUMPY - Introduction Introduction     NUMPY stands for Numerical Python. Numpy is one of the libraries for the python programming language. It is used for high level mathematical calculations. It has the large collection of functions for working with the multi-dimensional arrays, matrices, linear algebra, Fourier transform, etc. Installation of Numpy 1. Open the command or terminal on your system. 2. Enter the following command below.      #installation of NUMPY using PIP      pip install numpy       (OR)       #installation of NUMPY using CONDA      conda install numpy 3. Now, NUMPY installed on your system. To verify that use the command below.      #check for version of NUMPY      numpy --version  Tip : Use Anaconda Navigator , it comes with built-in software of JUPYTER NOTEBOOKS and pre-installed packages like Nump...

Calculate Distance Between Two Points in Python

Python - Distance Between Two Points Calculation

Python - Distance Between Two Points Calculation
Python - Distance Between Two Points Calculation


Source Code

Aim :

    To calculate the distance between two points using formula in python.

Algorithm :

  • Get the required input from the user by using input statement for x1, x2 represents co-ordinates in x-axis and y1, y2 represents co-ordinates in y-axis .
  • Calculate the distance between two points using formula ((((x2-x1)**2)+((y2-y1)**2))**0.5)
  • Display the result with the help of print statement

Program :

#calculate distance between two points using formula in python
#x1, x2 represents co-ordinates in x-axis and y1, y2 represents co-ordinates in y-axis and get input from user
x1 = float(input("Enter the value of x1 co-ordinate : "))
x2 = float(input("Enter the value of x2 co-ordinate : "))
y1 = float(input("Enter the value of y1 co-ordinate : "))
y2 = float(input("Enter the value of y2 co-ordinate : "))

#calculate distance between two points using formula ((((x2-x1)**2)+((y2-y1)**2))**0.5)
a = (x2 - x1)**2 ; b = (y2-y1)**2
Distance_between_two_points = (a+b)**0.5

#Display the result using print statement
print("Distance between two points are", Distance_between_two_points)

Output :

Enter the value of x1 co-ordinate : 
7
Enter the value of x2 co-ordinate : 
10
Enter the value of y1 co-ordinate : 
5
Enter the value of y2 co-ordinate : 
2
Distance between two points are 4.242640687119285

Terminal Code :

Python - Distance Between Two Points Program
Python - Distance Between Two Points Program


Terminal Output :

Python - Distance Between Two Points Output
Python - Distance Between Two Points Output


Result :

    The output was executed successfully and result was verified.


Personal Writings for Readers!!!

Story behind single family described in Pandemic Family Book.


Read more on...

Paperback - https://amzn.to/34NS6Sk

Amazon Kindle - https://amzn.to/3aKtIng

Kobo Writing - https://bit.ly/3iQysNy

Comments

Popular Posts