Another beautiful day in this miserable world

Posts tagged ‘program to find distance’

Python Programming: An Introduction to Computer Science by Zelle Chap 3 Ex 7

7. Write a program that accepts two points and determines the distance between them.

We must import the math library to use the “sqrt” function.


from math import *
def main():
    pt1x, pt1y = eval(input("Input the first point seperated by a comma "))
    pt2x, pt2y = eval(input("Input the second point seperated by a comma "))
    dis = sqrt(((pt2x-pt1x)**2) + ((pt2y - pt1y)**2))
    print("The distance between the two points is", dis)
main()