So I need to find period of a number when dividing, for example 1/7 = 0.142857142857142857... and print it like 0.(142857) so in brackets I need to print a period of that number.
I'm using Set for this example
class Set:
def __init__(self):
self.content= []
def __str__(self):
self.content.sort()
return '' + str(self.content)
def length(self):
return len(self.content)
def insert(self,x):
if x not in self.content:
self.content.append(x)
def erase(self,x):
for i in range(self.length()-1):
if self.content[i]==x:
del self.content[i]
def find(self,x):
if x in self.content:
return True
else:
return False
def items(self):
return self.content
Here I want to convert that eval input to a string because I want to find point while dividing using expression.index('.') and finding that period. After that I'm putting that period in 'k' and print the number to the point + period of that number.
if __name__=='__main__':
set1=Set()
expression=eval(input('enter an expression: '))
expression=str(expression)
point=expression.index('.')
for i in range(point+1,len(expression)):
set1.insert(expression[i])
k=''
for x in set1.items():
k+=x
print(f'{expression[:point+1]}({k})')
Problem here is that for example 7/9 = 0.77777777778 program will print 0.(78) like 78 is a period, but only 7 is a period here not 0.78787878787878...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…