number which is Square or can be written as sum of two squares python -


i created program in python check if given number square or can written sum of 2 squares, doesn't work.please me.

def sum(num):     def m(a):         b=a         item in range(a):             b=b-1             if a==b*b:                 return(a)     c=num     item in range(1,num):         c-=1         if m(c)==c , m(d)==d:             print(num) 

you can check if perfect square if int of square root squared target

def is_square(n):     return int(n**0.5)**2 == n 

the second part little harder (though not hard)

first need check ints square root of target , add 1

for in range(0,int(target**0.5+1)): 

then need go on remaining numbers can teh remaining numbers

    j in range(i,int((target-i**2)**0.5+1) 

then have check if squared + j squared target if i,j 1 of solutions


Comments