-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
109 lines (88 loc) · 2.12 KB
/
main.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
divprec = int(input("Division Precision: "))
def div(b, prec):
prec = int(prec)
prec -= 1
preci = 0
# Define a var for the answer
ans = []
# Define a function to convert list to float
def l2f(lis):
print(lis)
lis = list(lis)
ll = len(lis)
text = ""
i = 0
while ll > 0:
text += str(lis[i])
i += 1
ll -= 1
n = float(text)
return n
# Define a function to convert int to list
def i2l(inte):
inte = str(inte)
string = list(inte)
return string
a = 4
b = int(b)
temp1 = 0 # the result of how many times b gets into a
temp3 = 0 # temp3 * b = temp1
temp4 = a
# Start, check how many times (temp1)
# B gets into A
while not temp1 > temp4:
temp1 += b
if temp1 > temp4:
temp1 -= b
temp3 = temp1 / b
temp3 = int(temp3)
print("temp1: " + str(temp1))
print("TEMP3 " + str(temp3))
ans.append(str(temp3) + ".")
temp4 -= temp1 # the new a num
temp4 = temp4 * 10
print("New A num: " + str(temp4))
print("ANS: " + str(ans))
if temp4 == 0:
return l2f(ans)
while not preci > prec:
temp1 = 0; temp3 = 0
while not temp1 > temp4:
temp1 += b
if temp1 > temp4:
temp1 -= b
temp3 = temp1 / b
temp3 = int(temp3)
print("temp1: " + str(temp1))
print("TEMP3 " + str(temp3))
ans.append(str(temp3))
temp4 -= temp1
temp4 = temp4 * 10
print("New A num: " + str(temp4))
print("ANS: " + str(ans))
if temp4 == 0:
return l2f(ans)
preci += 1
answer = l2f(ans)
print("Answer: " + str(answer))
return answer
pii = 4/1
d = 3
op = False
n = input("Iterations: ")
n = int(n)
i = 0
while i <= n:
if op == False:
pii = pii - div(d, divprec)
if op == True:
pii = pii + div(d, divprec)
if op == False:
op = True
else:
op = False
d = d + 2
i = i + 1
print(pii)
print("Press anything to exit...")
input()