Get startedGet started for free

Creating a Lottery iterator

You've practiced building an iterator, and handling StopIteration exceptions when using an iterator. Now, it's time to put it all together. You'll be building a Lottery iterator to draw integers at random and create a winning number. Happy coding!

This exercise is part of the course

Intermediate Object-Oriented Programming in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

class Lottery:
  def __init__(self, number_digits):
    self.number_digits = number_digits
    self.counter = 0
  
  # Create an iterator using a magic method
  def ____(____):
    return ____
Edit and Run Code