Gadgets 4 Students Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
131k 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.

Where can I do online courses From Word's Top Instructors?

UDEMY::  Attend All Udemy Courses in Just INR 450[Coupon]
Coursera:: Join For FREE

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

Code your future with Programming skills. Courses starting at ₹ 455 only!

3.3k questions

7.1k answers

395 comments

4.5k users

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
...