1

I have to defined a function called float_range(start,stop,step). It works the same as a built in function only it can accept float values too.For the content I am not to use the range function at all and I am to assume start, stop and step are integer or float numbers. The problem I am having with my code, is I believe to have created a infinite loop in one of the while loops and its not passing all the test cases. Some of the examples are float_range(0,1.0,.25) and should count out from 0 to 1 in a list as [0,0.25,.5,.75] or float_range(0,0.25,-1) this would not work because its never true so it would return a empty list. I need help making in finding that infinite loop I created and also passing these test cases.

def float_range(start,stop,step):
   range_list = [start]
   Value = start
   while Value != stop: 
      if start < stop:
         while Value < stop:
            Value += step
            range_list.append(Value)
         return range_list[:-1]
      elif start > stop:
         while Value > stop:
            Value += step
            range_list.append(Value)
         return range_list[:-1]
brian012
  • 193
  • 1
  • 2
  • 12

0 Answers0