Nov-09-2019, 05:14 PM
I'm having a problem with writing to file. It only works part time. I have a print statement right after the file.write line and it shows that everything is being calculated correctly. Other scripts I've written don't have any problems. And I don't get any error messages. And yes, I already know the code isn't very pretty. I'm still learning this stuff.
Here's the code.
Here's the code.
import numpy as np # def mat(num_in, side): rows = [] A = [] for y in range(0, side): for x in range(0, side): rows.append(int(num_in[x])) A.append(rows) rows = [] rgt = num_in[side - 1:] temp = rgt for z in range(0, side - 1): temp = temp + num_in[z] num_in = str(temp) return A side = 4; side1 = side num_in = str(10**(side1 - 1)) hold = int(num_in) fhand = open("cd4.txt", "w") s = 0 chain = [] while int(hold) < 10**side1: while s == 0: A = mat(num_in, side) det = int(round(np.linalg.det(A))) if (det in chain or abs(det) in chain) or (det < 10 and det > -10): chain.append(det) break else: chain.append(det) num_in = str(abs(det)) side = len(num_in) hold += 1 num_in = str(hold) side = len(num_in) fhand.write(f'{hold - 1}, {chain}\n') print(f'{hold - 1}, {chain}') chain = [] fhand.closeIf the the range is say from 100 to 1000 it only prints up to 720. Or range is 1000 to 10000 it stops at 9884. And if the range is small say 10 to 20 it doesn't write to file at all. What's up with the selective write? Is it tired or something? TIA