A python program to calculate distance so that it takes two Points (x1, y1) and (x2, y2) as arguments and displays the calculated distance, using Class.
Added by Manuela S.
Step 1
Define a class named Point with two attributes x and y. Show more…
Show all steps
Your feedback will help us improve your experience
Aishwarya Krishnakumar and 57 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
'Write a python program to compute the distance between the points (x1, Y1) and (x2, y2) Take the points from user:'
Florencia C.
(Geometry: distance of two points) Write a program that prompts the user to enter two points $(x 1, y 1)$ and $(x 2, y 2)$ and displays their distance between them. The formula for computing the distance is $\sqrt{\left(x_{2}-x_{1}\right)^{2}+\left(y_{2}-y_{1}\right)^{2}}$. Note that you can use Math.pow(a, 0.5 ) to compute $\sqrt{a}$. Here is a sample run:
Calculate Distance Programming Challenge Description: You have (x, y) coordinates for 2 points and need to find the distance between them. Input: Your program should read lines from standard input. Each line contains two space-delimited coordinate pairs. All values are integers between -100 and 100. Output: Print the distance between the two points. You do not need to round the results you receive. Test 1: Test Input: (25, 4) (1, -6) Expected Output: 26 Test 2: Test Input: (47, 43) (-25, -11) Expected Output: 90
Brendan H.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD