Finance[US] Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
164k views
in RTU/BTU B.Tech(CSE-VI SEM) PYTHON LAB by Goeduhub's Expert (7.6k points)
python program  to calculate distance between two points taking input from the user.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Write a python program to calculate distance between two points taking input from the user

Distance can be calculated using the two points (x1, y1) and (x2, y2), the distance d between these points is given by the formula:

for e.g : let x1 , y1=10,9    and x2 , y2=4,1 then (x2-x1)2=(10-4)= 6= 36 and (y2-y1)2= (9-1)2 = 8= 64 now  64 + 36 =100 and 100 is square root of 10 sp distance between (10,9) and (4,1) is 10 . 

Program-1 

x1=int(input("enter x1 : "))

x2=int(input("enter x2 : "))

y1=int(input("enter y1 : "))

y2=int(input("enter y2 : "))

result= ((((x2 - x1 )**2) + ((y2-y1)**2) )**0.5)

print("distance between",(x1,x2),"and",(y1,y2),"is : ",result)

Output 

enter x1 : 4 

enter x2 : 6 

enter y1 : 0 

enter y2 : 6 

distance between (4, 6) and (0, 6) is : 6.324555320336759

Program -2 

import math

a=input("enter first coordinate : ")

p1 = a.split(",")

b=input("enter second coordinate : ")

p2 = b.split(",")

distance = math.sqrt( ((int(p1[0])-int(p2[0]))**2)+((int(p1[1])-int(p2[1]))**2) )

print("distance between ", a,"and", b, "is",distance) 

Output 

enter first coordinate: 4,0

enter second coordinate : 6,6

distance between 4,0 and 6,6 is 6.324555320336759 


For more Rajasthan Technical University CSE VI Sem Python Lab Experiments Click here

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...