Question: Although you know it, we'll remind you about lines: Given two points p0=(x0,y0),p1=(x1,y1), a line is formed by: ym=mx+b=x0x1y0y1 Using either point, we can solve



Although you know it, we'll remind you about lines: Given two points p0=(x0,y0),p1=(x1,y1), a line is formed by: ym=mx+b=x0x1y0y1 Using either point, we can solve for the intercept b. For a non-zero slope m, the inverse is m1. Three points p0,p1,p2 are colinear if they lie along the same line. You've decided to create a start-up that helps K-12 students learn about lines-in particular, 2D Euclidean space. After researching the area, you decided on three functions: 1. build_line that takes two points and a dictionary and assigns the keys "slope" and returns the dictionary containing the slope and intercept if the points define a line-remember, any two points (x,y0),(x,y1) does not because the slope is undefined. 2. clear_line that assigns None to both the slope and intercept. 3. inverse_slope that returns the inverse of the slope: if m is the slope, the inverse is m1. Since m=0 does not have an inverse, if there's not a valid way to return the inverse, you return "Error: no slope". 4. colinear that takes three points p0,p1,p2 and, using build_line returns True if they are colinear and False otherwise To make things easier you've decided to use a dictionary: 1 line = { 'slope':None, 'intercept': None } This dictionary holds the slope and intercept, but begins with None. Here's a simple run: 1 print(line) 2 build_line( (2,3),(8,6), line) 3 print(line) 4 clear_line(line) 5 print(line) 6 build_line( (2,3),(2,5), line) \#not a line (no slope) 7 print(line) with output: 1{ 'slope': None, 'intercept': None\} 2{ 'slope': 0.5, 'intercept': 2.0\} 3 \{'slope': None, 'intercept': None\} 4{ 'slope': None, 'intercept': None\} Assignment 2: Functions and Choice Page 10 The function call build_line assigns to the keys "slope" and "intercept" the slope and intercept if the two points define a line; otherwise, the dictionary is not changed as shown in the last print. Let's see the inverse slope and colinear functions: 1 build_line ((3,2),(4,1), line ) 2 print(line) 3 print(inverse_slope(line)) 4print(colinear((2,1),(1,7),(4,13))) has output: 1 \{'slope': -0.42857142857142855, 'intercept': 0.7142857142857144} 22.3333333333333335 3 True When you send a mutable object to a function, a new local copy is not created: it uses the same address. Observe this code: 123456789x=[dog,123]>deff(happy):>x[dog,123]>y(x)>x[dog,wholetthe We will change the mutable dictionary as an argument. Later in the course, we'll learn how to make a copy of the mutable object. Deliverables Problem 8 - Complete the build_line, inverse_slope and colinear functions. - We've completed the clear function. - You must use the dictionary line. - The function colinear must use the build line function. Use the local dictionary line that we have provided
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
