17 lines
333 B
Python
17 lines
333 B
Python
class Squares:
|
|
def __init__(self, max_value):
|
|
self.n = 1
|
|
self.max_value = max_value
|
|
|
|
def __next__(self):
|
|
if self.n >= self.max_value:
|
|
raise StopIteration
|
|
self.n +=1
|
|
return self.n * self.n
|
|
|
|
def __iter__(self):
|
|
return self
|
|
|
|
s = Squares(5)
|
|
for i in s:
|
|
print(i) |