Check perfect square using addition / subtraction | This function returns true if n is perfect square , else false ; the_sum is sum of all odd numbers . i is used one by one hold odd numbers ; Driver code
def isPerfectSquare ( n ) : NEW_LINE INDENT i = 1 NEW_LINE the_sum = 0 NEW_LINE while the_sum < n : NEW_LINE INDENT the_sum += i NEW_LINE if the_sum == n : NEW_LINE INDENT return True NEW_LINE DEDENT i += 2 NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT print ( ' Yes ' ) if isPerfectSquare ( 35 ) else print ( ' NO ' ) NEW_LINE print ( ' Yes ' ) if isPerfectSquare ( 49 ) else print ( ' NO ' ) NEW_LINE DEDENT