Ask Your Question

Revision history [back]

One way would be as follows:

with open('collatz_{}_{}.txt'.format(X, N), 'w') as file:
        file.writelines(str(k) + '\n' for k in f(X, N))

Also, you could use x = x // 2 in your code to always work with integers rather than rational numbers.