Question: The loop function is similar to range(), but handles the parameters somewhat differently: it takes in 3 parameters: the starting point, the stopping point, and

The loop function is similar to range(), but handles the parameters somewhat differently: it takes in 3 parameters: the starting point, the stopping point, and the increment step. When the starting point is greater than the stopping point, it forces the steps to be negative. When, instead, the starting point is less than the stopping point, it forces the step to be positive. Also, if the step is o, it changes to 1 or -1. The result is returned as a one-line, space-separated string of numbers. For example, loop(11,2,3) should return 118 5 and loop(1,5,0) should return 1 2 3 4. Fill in the missing parts to make that happen. 1 - def loop(start, stop, step): 2 return_string = "". 3. if step == 0: 5. 7. if ___: step = abs(step) * -1 else: step = abs(step) for --_: return_string += str(count) + "" return return_string.strip() 9- 10 11 12 Run 13 14 15 16 17 print(loop(11,2,3)) # Should be 11 8 5 print(loop(1,5,0)) # Should be 1 2 3 4 print(loop(-1,-2,0)) # Should be -1 print(loop(10,25,-2)) # Should be 10 12 14 16 18 20 22 24 print(loop(1,1,1)) # Should be empty Reset
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
