Python Programming – John Zelle: Chapter 3 ex. 7

Write a program that accepts two points (see previous problem) and determines the distance between them.

Chapter 3 Exercise 7

Python

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #Chapter 3 Exercise 7 #Write a program that accepts two points (see previous problem) and determines the distance between them. from math import * def main(): print("This program calculates the slope of a line through 2 points.") print() ptx1, pty1 = eval(input("Input the first x and y point separated by a comma ")) ptx2, pty2 = eval(input("Input the second x and y point separated by a comma ")) slopex = (ptx2 - ptx1)**2 slopey = (pty2 - pty1)**2 distance = sqrt(slopex + slopey) print("The distance between the two points is ", distance) main() |

Run =

This program calculates the slope of a line through 2 points.

Input the first x and y point separated by a comma 3,5

Input the second x and y point separated by a comma 6,7

The distance between the two points is 3.605551275463989