dimanche 17 janvier 2021

Why does Python not read the next line (if)?

i wrote the program about Pythagorean i got my answer but python doesn't read (break) after (if) . my program title : (Special Pythagorean triplet), there is a one answer exist for ((a+b+c=1000)&(a2 + b2 =c**2) ) i want find abc . i know (a=200, b=375, c=425) but when program starts it never stop and it continue . It also types the product of these three numbers continuously.

import random as r
def pyth(b,d,c):
    pyth = None
    if b**2+c**2 == d**2 :
        pyth = True
        h=d*c*b
        print(h)
        return pyth
    if b**2+d**2==c**2 :
        pyth= True
        h=d*c*b
        print(h)
        return pyth
    if d**2 + c**2 == b**2:
        pyth =True
        h=d*c*b
        print(h) 
        return pyth
   else:
       pyth = False 
       return 

a = list(range (150,1000))
b=0
c=0
d=0
h = 0
for i  in range(0,10000000):
    b = r.choice(a)
    c = r.choice(a)
    d = 1000-b-c
    e = b+c+d
if e == 1000 :
    pyth(b,d,c)
if pyth == True:
    break
else:
    continue

Aucun commentaire:

Enregistrer un commentaire