Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HW4.4. Check Collinearity Write a function named collinear which follows the specification below: The function must take in an argument named points. The input (points)
HW4.4. Check Collinearity Write a function named collinear which follows the specification below: The function must take in an argument named points. The input (points) will be a nested list of points in 2D. You may assume that the input format will always be correct (i.e. n distinct lists of length two, each tuple representing an (x, y) pair, where n >= 2). Some examples of expected inputs and outputs are shown below. Return False if the points are not collinear. Return a tuple, with the first element as True, and the second element containing the slope of the line through the points if the points in the list are collinear. Note: In Python when you want to return multiple values, you can use the syntax return a, b. For example, if the list of points form a line with slope 2, you could use the syntax return True, 2. The values are actually returned in a tuple, so the returned tuple from the previous example would be (True, 2). You will learn about tuples in a future lecture. Return (True, None) if the points are collinear, but the slope is undefined. Some examples of expected inputs and outputs are shown below: Input: [[0, 0], [2, 4], [3, 6], [4, 8]] Output: (True, 2). Input: [[3, 0], [3, 4], (3, 6], [3, 8]] Output: (True, None). Input: [[0, 0], [2, 5), (3, 7], [4, 2]] Output: False. Input: [[1.5, 3.5], [4, 6], [6.5, 8.5], [9, 11]] Output: (True, 1)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started