Question
Please use a WHILE loop and ONLY a WHILE loop to solve this problem, NOT a for loop. Please use the Python 2.7 language. The
Please use a WHILE loop and ONLY a WHILE loop to solve this problem, NOT a "for" loop. Please use the Python 2.7 language. The problem MUST pass all test cases(provided below). The problem itself, the answer template, and the test cases are provided below.
The Problem:
Write code that checks every adjacent pair of numbers in a list to see if either is a factor of the other and returns all factor-pairs in order. For example, the list [2, 6, 12, 3, 7, 8, 16, 10] would yield ["2-6", "6-12", "3-12", "8-16"]. You may not use any built-in functions/methods besides len() and .append().
The Answer Template:
def pairs(l1): list1 = l1 return 0 #YOUR CODE GOES HERE (indented) return l1 #END YOUR CODE
And Finally, The Test Cases!
pairs [] [] pairs [2] [] pairs [1,2] ['1-2'] pairs [5,15,2,-4,3,6] ['5-15', '-4-2', '3-6'] pairs [5,1,2,-4,3,6] ['1-5', '1-2', '-4-2', '3-6'] pairs [2,6,12,3,7,8,16,10] ['2-6', '6-12', '3-12', '8-16']
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