Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Python 2.7 or higher, (no dictionaries or built in min or max functions; use basic if and while loops only) 4. Implement function, q4(L,
Using Python 2.7 or higher,
4. Implement function, 4(L, goalX, goaly), that takes a non-empty list, L, of [x,y) pairs, and two goal numbers, and returns tuple (closestXY, Xory) where closestXY is the item from L whose x distance from goal X or whose y distance from goal is the minimum among all distances, and Xory is 'x' if x distance is minimized and 'y' otherwise. You may assume there is a unique answer. Note: You may not use built-in min or max functions. Examples: 94 ([[4, 4], [10, 10]], 1, 8) should return ([10,10), 'y') 94([[10, 25], [2, 2], [49, 200]], 50, 8) should return ([ 49,200), 'x') 5. Implement function q5(L) that takes as input a (possibly empty) list of (possibly empty) lists of numbers and returns a three-element list. The first element is a list of the sums of corresponding lists in L, the second element is the number of lists in L that contain more positive than negative values, and the third element in the minimum value among all items in all lists (or None if there is no minimum). Note: you may NOT use Python's 'sum' or 'min' function instead,compute sums and min within a loop or loops.) For example, >>> 95([[1, 2, 2], [3]]) [[5, 3), 2, 1] >>> 05([[0, 1, 0], U, 1-1, 100]]) [[1, 0, 99], 1, -1] (no dictionaries or built in min or max functions; use basic if and while loops only)
4. Implement function, q4(L, goalX, goalY), that takes a non-empty list, L, of [x,y] pairs, and two goal numbers, and returns tuple (closestXY, XorY) where closestXY is the item from L whose x distance from goal X or whose y distance from goalY is the minimum among all distances, and XorY is 'x' if x distance is minimized and 'y' otherwise. You may assume there is a unique answer. **Note: You may not use built-in min or max functions.**
Examples:
q4([[4, 4], [10, 10]], 1, 8) should return ([10,10], 'y')
q4([[10, 25], [2, 2], [49, 200]], 50, 8) should return ([49,200], 'x')
5. Implement function q5(L) that takes as input a (possibly empty) list of (possibly empty) lists of numbers and returns a three-element list. The first element is a list of the sums of corresponding lists in L, the second element is the number of lists in L that contain more positive than negative values, and the third element in the minimum value among all items in all lists (or None if there is no minimum). **Note: you may NOT use Python's 'sum' or 'min' function (instead,compute sums and min within a loop or loops.)**
For example,
>>> q5([[1, 2, 2], [3]])
[[5, 3], 2, 1]
>>> q5([[0, 1, 0], [], [-1, 100]])
[[1, 0, 99], 1, -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