Answer the question
In order to leave comments, you need to log in
How to fix python error?
def gcd(a, b):
while b:
a, b = b, a % b
return a
def main(a,b,c):
return(gcd(gcd(a,b),c))
def getPowers(n, p):
vac=[]
with open(str(p)+".txt", "r") as f:
for x in range(1, n + 1):
vac.append(f.readline(x))
return vac
def detNumbers(n,p):
xxx=0
a1=[]
a2=[]
a3=[]
vac=getPowers(n, p)
for x in range(1, p):
for y in range(x + 1, p-1):
for z in range(y+1, p+1):
if main(x,y,z)==1:
if gcd(x, y)==gcd(y, z)==gcd(x, z)==1:
if vac[x]+vac[y]==vac[z]:
xxx=xxx+1
a1[xxx].append(x)
a2[xxx].append(y)
a3[xxx].append(z)
for c in range(1, p+1):
with open("Тройки"+str(c)+".txt", "w") as f:
for g in range(1, xxx + 1):
f.write(a1[g] + " " + a2[g] + " " + a3[g] + "\n")
for pop in range(1, 1000+1):
detNumbers(2000,pop)
Answer the question
In order to leave comments, you need to log in
Here are the errors
a1[xxx].append(x)
a2[xxx].append(y)
a3[xxx].append(z)
a1.append(x)
a2.append(y)
a3.append(z)
Sorry, but there is no personal Python technical support here and no one will parse your code with terribly named variables. Learn to look for mistakes yourself, otherwise it will turn into a bad habit.
I can only recommend that you pay attention to the error in the Python emulator and google it. The emulator detects and shows errors well, so there should be no problems.
line 39, in detNumber(2000,1000)
line 29, in detNumber a1[xxx].append(x)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question