Perfect Square Logic In Python