CommencerCommencer gratuitement

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!

Cet exercice fait partie du cours

Intermediate Object-Oriented Programming in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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 ____
Modifier et exécuter le code