-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_26.py
More file actions
35 lines (30 loc) · 845 Bytes
/
Problem_26.py
File metadata and controls
35 lines (30 loc) · 845 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
def decimal_rep(numr, denr):
word = str(numr//denr)
rem = numr%denr
rem_list = []
recurring = ''
if rem != 0:
word += '.'
while rem!=0 and (rem not in rem_list):
rem_list.append(rem)
rem = rem*10
word += str(rem//denr)
rem = rem % denr
if rem in rem_list:
recurring = word[rem_list.index(rem)+2:]
non_recurring = word[:rem_list.index(rem)+2]
else:
non_recurring = word
return (word, non_recurring, recurring)
def main():
max_rec = ''
max_d = 0
for d in range(1, 1001):
word, non_rec, rec = decimal_rep(1,d)
if len(rec)>len(max_rec):
max_rec = rec
max_d = d
word, non_rec, rec = decimal_rep(1,max_d)
print(f"{max_d}\n{word}\n{non_rec}\n{rec}")
if __name__ == "__main__":
main()