Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function points that takes four arguments, The numbers x1, y1, x2, and y

ID: 3924023 • Letter: W

Question

Write a function points that takes four arguments, The numbers x1, y1, x2, and y2 are coordinates of two points (x1, y1) and (x2, y2) in the plane. Your function should compute:

The slope of the line going through the points, unless the line is vertical

The distance between the two points

The function should print the computed slope and distance in the following way: if the line is vertical, the value of the slope should be the string 'infinity'. Otherwise the slope and distance will be printed as computed normally. If you don’t know how to compute the slope and distance find a reference, for example Wikipedia. The following shows several sample runs of the function:

>>> points(0,0,1,1)

The slope is 1.0 and the distance is 1.4142135623730951

>>> points(0,0,0,1)

The slope is infinity and the distance is 1.0

>>> points(3,4,5,6)

The slope is 1.0 and the distance is 2.8284271247461903

>>> points(-12.3,55,99.4,-3.6)

program being used: python

Explanation / Answer

import math //import to perform square root and sqaring operation
def point(x1, y1, x2, y2): // function definition for points
Y = float(y2) - float(y1)
X = float(x2) - float(x1)
slope = Y/X
dist = math.sqrt(math.pow((x2-x1),2) + math.pow((x2-x1),2));
print "Slope = ", slope ," and the distance is = " , dist
  

point(0,0,1,1) // calling the function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote