quadrat&ungerade zahlen
This commit is contained in:
1 parent
bc47b9c41e
commit
5e9bb3e314
2 files changed
+32
No files matched your search
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
class Squares:
|
||||
def __init__(self, n):
|
||||
self.n = n
|
||||
self.current = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
if self.current >= self.n:
|
||||
raise StopIteration
|
||||
self.current += 1
|
||||
return self.current ** 2
|
||||
|
||||
for q in Squares(5):
|
||||
print(q) # 1, 4, 9, 16, 25
|
||||
|
||||
print(list(Squares(5))) # [1, 4, 9, 16, 25]
|
||||
Reference in new issue
Block a user