-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.py
More file actions
36 lines (30 loc) · 912 Bytes
/
iterator.py
File metadata and controls
36 lines (30 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class crude_calculator:
"""Simple class that provides iteration over digits in a division operation,
will automatically stop if a repeating pattern is found."""
def __init__(self, numerator, denominator):
self.numerator = numerator
self.denominator = denominator
self.digits = ""
def __iter__(self):
return self
def __next__(self):
if self.numerator == 0:
raise StopIteration
next = self.numerator
new = 0
while self.numerator > 1 and self.denominator <= self.numerator:
new = self.numerator / self.denominator
self.numerator = self.numerator % self.denominator
self.numerator *= 10
self.digits += str(new)
return int(new)
enum = crude_calculator(355, 113)
#enum = crude_calculator(7, 22)
#enum = crude_calculator(1, 3)
index = 0
for d in enum:
if index > 1000:
print()
break
print(d,end='')
index += 1