2 ms·
Yes, that is funky. def long_div(x,y,N=10): """Given two integers x and y, return us the N digits of x/y.""" #First work out the integer part x =
by kghose 15y ago
Yes, that is funky.
def long_div(x,y,N=10):
"""Given two integers x and y, return us the N digits of x/y."""
#First work out the integer part
x = int(x)
divisor = y = int(y)
quotients = [x/y]
dividend = x % y
for digit in range(N):
dividend *= 10
quotient = dividend/divisor
dividend = dividend%divisor
quotients.append(quotient)
return quotients
def pretty_print(quotients, G=3):
"""Pretty print quotients by grouping digits by 3."""
strp = ''
cnt = 1
for n in quotients[1:]:
strp += str(n)
cnt +=1
if cnt > G:
print strp
strp = ''
cnt = 1
quotients = long_div(1,998001,N=3000)
pretty_print(quotients,G=3)