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 0, 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 11 8 5 and loop(1,5,0) should return 1 2 3 4. Fill in the missing parts to make that happen.
metodo 1 - def loop(start, stop, step): return_string = ** if step==: step-1 if start>step: step = abs(step)-1 else: step = abs(step) for count in range(start, stop, step): return_string += str(count)+"" return return_string.strip) Ejecutar 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,)) # 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 RestablecerStep 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