Question 22. Weight 50 A text file contains a sequence ofx& y coordinates. These
ID: 3575675 • Letter: Q
Question
Question 22. Weight 50 A text file contains a sequence ofx& y coordinates. These represent the endpoints ofline segments (ie, in example the first line segment is from Co,o] to [o, s], the next segmentis from [0, 5 to CS, 5, etc.). Example file 1: 0 0 0 5 5 0 Example file 2: 10 3 Every such file contains information for at least one line segment. You may not assume a maximum number of such line segments. a) write a Python function computeDi coord1 coord2 to compute and return the straight-line distance between a pair ofcoordinates [xi, yi], [2, y2): dist (yl- y2)2 +(x1- x2) The exponentiation operator in Python denoted by You can obtain the square root of a number by takingit to the power of os. (Some marks will be given for the quality of your answer.Explanation / Answer
import math
inputfile=input("Enter file name with extension")
file = open(inputfile, "r")
output=file.read()
outputList=output.split(' ')
listnew=[]
j=len(outputList)
for i in range(len(outputList)):
j=len(outputList)
listnew.append(outputList[i])
print(listnew[i:j])## here is printing every axis i.e Xi and Yi
j=j-1
print(listnew)
## the axis need to pass to
def computeDist(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
print(computeDist(0, 1, 2, 3))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.