class Contador:
def __init__(self, limite):
self.limite = limite
self.valor = 0
def __iter__(self):
return self
def __next__(self):
if self.valor >= self.limite:
raise StopIteration #Para a iteração
self.valor += 1
return self.valor
for num in Contador(5):
print(num)
To embed this project on your website, copy the following code and paste it into your website's HTML: