Sqrt Iterable example 1

This commit is contained in:
Mert Gör 🇹🇷 2023-09-02 13:19:51 +03:00
parent 53d8d941f2
commit fc8f0baf83
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9

View File

@ -0,0 +1,28 @@
import math
class SqrtIterable:
def __init__(self, limit):
self.limit = limit
def __iter__(self):
return SqrtIterator(self.limit)
class SqrtIterator:
def __init__(self, limit):
self.limit = limit
self.i = 0
def __iter__(self):
return self
def __next__(self):
if self.i == self.limit:
raise StopIteration()
self.i += 1
return math.sqrt(self.i)
s = SqrtIterable(25)
for f in s:
print(f)