A Float Range Sequence

medium
Unit 22 · Bisect0/0 to milestone

range only works with integers. Implement FloatRange(start, stop, step) behaving like a proper read-only sequence:

  • len(r) is max(0, ceil((stop - start) / step)), computed with a tolerance so FloatRange(0, 1, 0.1) has length 10, not 11
  • r[i] returns start + i * step (no accumulated error), supports negative indices and raises IndexError out of range; slices return a list
  • iteration, reversed(), and x in r (true if x is within 1e-9 of an element)
  • step of 0 raises ValueError; negative steps count down
Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
A Float Range Sequence · TechGradify