Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

By using python language. Labtestz, FL2017 pd Problem A straight line can be defined by a pair of points piCx?, y) and pibo, y2) The

By using python language. image text in transcribed
Labtestz, FL2017 pd Problem A straight line can be defined by a pair of points piCx?, y) and pibo, y2) The slope m of a line is defined as follow Your program reads the points fiom a text file called points txt' which contains the coordinates of unknown mumber of pairs of points as shown in Figure L Each line contains four values xl, yl, 2 y2, where xl, yl are the coordinates of the first point and x2, y2 are the coordinates of the second point 10 2 7.5 32 23p 125 6 10 3 4 155 46 21 36 10 15 Figure 1 Input file contains unknown number of point pairs Use Spider, to create the following files ) The input file points.txt shown in Figure I () Your Python program that reads from the input file 'points.txt', the coordinates of unknown number of pairs of points, computes the corresponding slopes then prints the results on the screen as shown in Figure 2. Line# x1 Y1 X2 Y2 slope 10.00 2.00 7.50 4.00 e.e08.e8e.008.0e int 2.e0 10.00 3.80 3.28 .48 15.50 4.6021.00-.64 5.00 3.006.002.20 10.00 15.00 inf Figure 2. The output on screen Your program must define and use the following functiyons printleader ...); prints on screen the three lines header of the table as shown in the sample output (Fig. 2) 2 getCoordinatest.: receives one parameter representing a text line read from the input file, and it returns four float values xl. yl, x2, y2. In case of any wrong value format, the function returns 0.0, 0.0.0.0,0.0. 3. computeSlopet..): receives four parameters representing the values xl, yl, x2, y2 and returns the slope value m that should be computed according to the given formula above. If x2 is equal to x1 the computeSlope function returns an infinite value. In Python, the infinite value is a float constant value called inf (available in math library) Thus, you need to import inf rom the math library as from math import inf 4 main(..): the main function receives the nams of the input file points.txt'. This function opens the input file for reading, reads data from it, calls the various functions and finally prints the results on screen. If the input file is not found, an exception is raised and an error message will be displayed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions