Recursive palindrome check - having issues when recalling the functionRecursive Function palindrome in Pythonpython and palindromesCheck Palindrome using recursionrecursion of palindrome functionCheck for palindrome recursivelycheck palindrome by recursion in cPalindrome function using recursionRecursive function finding PalindromeRecursive palindrome check with JavaScriptPalindrome check with recursive function without slicing and loops

Everyone Gets a Window Seat

Would a horse be sufficient buffer to prevent injury when falling from a great height?

Bothered by watching coworkers slacking off

Could the Queen overturn the UK Supreme Court ruling regarding prorogation of Parliament?

Is there a pattern for handling conflicting function parameters?

What does a textbook look like while you are writing it?

What's the correct way to determine turn order in this situation?

GPLv3 forces us to make code available, but to who?

How to say "respectively" in German when listing (enumerating) things

How are proofs normally constructed in a write up, in one line or split up into multiple lines?

How is this situation not a checkmate?

Should I be an author on another PhD student's paper if I went to their meetings and gave advice?

How to "Start as close to the end as possible", and why to do so?

Can a passenger predict that an airline or a tour operator is about to go bankrupt?

Giving a good fancy look to a simple table

The difference of Prime in Solve doesn't work

Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails

Generating numbers with cubes

How do we know Nemesis is not a black hole (or neutron star)?

If I travelled back in time to invest in X company to make a fortune, roughly what is the probability that it would fail?

Re-entering the UK after overstaying in 2008

Manager told a colleague of mine I was getting fired soon

Avoiding dust scattering when you drill

Rank-one positive decomposition for a entry-wise positive positive definite matrix



Recursive palindrome check - having issues when recalling the function


Recursive Function palindrome in Pythonpython and palindromesCheck Palindrome using recursionrecursion of palindrome functionCheck for palindrome recursivelycheck palindrome by recursion in cPalindrome function using recursionRecursive function finding PalindromeRecursive palindrome check with JavaScriptPalindrome check with recursive function without slicing and loops






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









1















The problem is simple, check if palindrome or not using recursion. They also provided a template so I can't change that.
The template:



def isPalindrome(s): # Wrapper function
def isPalindromeRec(s,low,high):
""" Recursive function which checks if substring s[low ... high] is palindrome
returns a True/False value"""

n = len(s)
return isPalindromeRec(s,0,n-1)


I am nearly there but I think I am having trouble understanding how recursion exactly works. (especially how the values changes in the recursion)



My code:



def isPalindrome(s): # Wrapper function
def isPalindromeRec(s,low,high):
if len(s)<=1:
return True
else:
if s[0]==s[len(s)-1]:
return isPalindromeRec(s[low+1:high],low+1,high-1)
else:
return False

n = len(s)
return isPalindromeRec(s,0,n-1)
print(isPalindrome("anna"))
print(isPalindrome("civic"))
print(isPalindrome("a"))
print(isPalindrome("tx1aa1xt"))
print(isPalindrome(""))
print(isPalindrome("Civic"))
print(isPalindrome("ab"))


this is the output:



runfile('/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7/Problem2.py', wdir='/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7')
True
True
True
False
True
False
False


the first false should be True.
Thank you for your help!










share|improve this question
































    1















    The problem is simple, check if palindrome or not using recursion. They also provided a template so I can't change that.
    The template:



    def isPalindrome(s): # Wrapper function
    def isPalindromeRec(s,low,high):
    """ Recursive function which checks if substring s[low ... high] is palindrome
    returns a True/False value"""

    n = len(s)
    return isPalindromeRec(s,0,n-1)


    I am nearly there but I think I am having trouble understanding how recursion exactly works. (especially how the values changes in the recursion)



    My code:



    def isPalindrome(s): # Wrapper function
    def isPalindromeRec(s,low,high):
    if len(s)<=1:
    return True
    else:
    if s[0]==s[len(s)-1]:
    return isPalindromeRec(s[low+1:high],low+1,high-1)
    else:
    return False

    n = len(s)
    return isPalindromeRec(s,0,n-1)
    print(isPalindrome("anna"))
    print(isPalindrome("civic"))
    print(isPalindrome("a"))
    print(isPalindrome("tx1aa1xt"))
    print(isPalindrome(""))
    print(isPalindrome("Civic"))
    print(isPalindrome("ab"))


    this is the output:



    runfile('/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7/Problem2.py', wdir='/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7')
    True
    True
    True
    False
    True
    False
    False


    the first false should be True.
    Thank you for your help!










    share|improve this question




























      1












      1








      1


      0






      The problem is simple, check if palindrome or not using recursion. They also provided a template so I can't change that.
      The template:



      def isPalindrome(s): # Wrapper function
      def isPalindromeRec(s,low,high):
      """ Recursive function which checks if substring s[low ... high] is palindrome
      returns a True/False value"""

      n = len(s)
      return isPalindromeRec(s,0,n-1)


      I am nearly there but I think I am having trouble understanding how recursion exactly works. (especially how the values changes in the recursion)



      My code:



      def isPalindrome(s): # Wrapper function
      def isPalindromeRec(s,low,high):
      if len(s)<=1:
      return True
      else:
      if s[0]==s[len(s)-1]:
      return isPalindromeRec(s[low+1:high],low+1,high-1)
      else:
      return False

      n = len(s)
      return isPalindromeRec(s,0,n-1)
      print(isPalindrome("anna"))
      print(isPalindrome("civic"))
      print(isPalindrome("a"))
      print(isPalindrome("tx1aa1xt"))
      print(isPalindrome(""))
      print(isPalindrome("Civic"))
      print(isPalindrome("ab"))


      this is the output:



      runfile('/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7/Problem2.py', wdir='/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7')
      True
      True
      True
      False
      True
      False
      False


      the first false should be True.
      Thank you for your help!










      share|improve this question
















      The problem is simple, check if palindrome or not using recursion. They also provided a template so I can't change that.
      The template:



      def isPalindrome(s): # Wrapper function
      def isPalindromeRec(s,low,high):
      """ Recursive function which checks if substring s[low ... high] is palindrome
      returns a True/False value"""

      n = len(s)
      return isPalindromeRec(s,0,n-1)


      I am nearly there but I think I am having trouble understanding how recursion exactly works. (especially how the values changes in the recursion)



      My code:



      def isPalindrome(s): # Wrapper function
      def isPalindromeRec(s,low,high):
      if len(s)<=1:
      return True
      else:
      if s[0]==s[len(s)-1]:
      return isPalindromeRec(s[low+1:high],low+1,high-1)
      else:
      return False

      n = len(s)
      return isPalindromeRec(s,0,n-1)
      print(isPalindrome("anna"))
      print(isPalindrome("civic"))
      print(isPalindrome("a"))
      print(isPalindrome("tx1aa1xt"))
      print(isPalindrome(""))
      print(isPalindrome("Civic"))
      print(isPalindrome("ab"))


      this is the output:



      runfile('/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7/Problem2.py', wdir='/Users/Rayan/Desktop/AUB Spring 2019/EECE 230 /HW/Homework 7')
      True
      True
      True
      False
      True
      False
      False


      the first false should be True.
      Thank you for your help!







      python-3.x recursion palindrome






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 21:30







      Rayan Al Hobayb

















      asked Mar 28 at 21:10









      Rayan Al HobaybRayan Al Hobayb

      377 bronze badges




      377 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0
















          Rewrote it:



          def isPalindrome(s):
          def isPalindromeRec(s,low,high):

          if (low == high):
          return True

          if (s[low] != s[high]) :
          return False

          if (low < high + 1) :
          return isPalindromeRec(s, low + 1, high - 1);

          return True

          n = len(s)
          if (n == 0) :
          return True

          return isPalindromeRec(s, 0, n - 1);

          print(isPalindrome("anna"))
          print(isPalindrome("civic"))
          print(isPalindrome("a"))
          print(isPalindrome("tx1aa1xt"))
          print(isPalindrome(""))
          print(isPalindrome("Civic"))
          print(isPalindrome("ab"))

          output:
          True
          True
          True
          True
          True
          False
          False





          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );














            draft saved

            draft discarded
















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406884%2frecursive-palindrome-check-having-issues-when-recalling-the-function%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0
















            Rewrote it:



            def isPalindrome(s):
            def isPalindromeRec(s,low,high):

            if (low == high):
            return True

            if (s[low] != s[high]) :
            return False

            if (low < high + 1) :
            return isPalindromeRec(s, low + 1, high - 1);

            return True

            n = len(s)
            if (n == 0) :
            return True

            return isPalindromeRec(s, 0, n - 1);

            print(isPalindrome("anna"))
            print(isPalindrome("civic"))
            print(isPalindrome("a"))
            print(isPalindrome("tx1aa1xt"))
            print(isPalindrome(""))
            print(isPalindrome("Civic"))
            print(isPalindrome("ab"))

            output:
            True
            True
            True
            True
            True
            False
            False





            share|improve this answer





























              0
















              Rewrote it:



              def isPalindrome(s):
              def isPalindromeRec(s,low,high):

              if (low == high):
              return True

              if (s[low] != s[high]) :
              return False

              if (low < high + 1) :
              return isPalindromeRec(s, low + 1, high - 1);

              return True

              n = len(s)
              if (n == 0) :
              return True

              return isPalindromeRec(s, 0, n - 1);

              print(isPalindrome("anna"))
              print(isPalindrome("civic"))
              print(isPalindrome("a"))
              print(isPalindrome("tx1aa1xt"))
              print(isPalindrome(""))
              print(isPalindrome("Civic"))
              print(isPalindrome("ab"))

              output:
              True
              True
              True
              True
              True
              False
              False





              share|improve this answer



























                0














                0










                0









                Rewrote it:



                def isPalindrome(s):
                def isPalindromeRec(s,low,high):

                if (low == high):
                return True

                if (s[low] != s[high]) :
                return False

                if (low < high + 1) :
                return isPalindromeRec(s, low + 1, high - 1);

                return True

                n = len(s)
                if (n == 0) :
                return True

                return isPalindromeRec(s, 0, n - 1);

                print(isPalindrome("anna"))
                print(isPalindrome("civic"))
                print(isPalindrome("a"))
                print(isPalindrome("tx1aa1xt"))
                print(isPalindrome(""))
                print(isPalindrome("Civic"))
                print(isPalindrome("ab"))

                output:
                True
                True
                True
                True
                True
                False
                False





                share|improve this answer













                Rewrote it:



                def isPalindrome(s):
                def isPalindromeRec(s,low,high):

                if (low == high):
                return True

                if (s[low] != s[high]) :
                return False

                if (low < high + 1) :
                return isPalindromeRec(s, low + 1, high - 1);

                return True

                n = len(s)
                if (n == 0) :
                return True

                return isPalindromeRec(s, 0, n - 1);

                print(isPalindrome("anna"))
                print(isPalindrome("civic"))
                print(isPalindrome("a"))
                print(isPalindrome("tx1aa1xt"))
                print(isPalindrome(""))
                print(isPalindrome("Civic"))
                print(isPalindrome("ab"))

                output:
                True
                True
                True
                True
                True
                False
                False






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 22:12









                RalphRalph

                2272 silver badges10 bronze badges




                2272 silver badges10 bronze badges

































                    draft saved

                    draft discarded















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406884%2frecursive-palindrome-check-having-issues-when-recalling-the-function%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현