Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:22:24+00:00 2026-06-11T16:22:24+00:00

Possible Duplicate: Why does 'return self' return None? I’ve been trying to solve Problem

  • 0

Possible Duplicate:
Why does 'return self' return None?

I’ve been trying to solve Problem 55 on Project Euler (http://projecteuler.net/problem=55)
and now that I think I have the answer, I Experience a problem. I don’t want a solution to the Problem 55, just on what I’ve done wrong.

Here’s my code: (I don’t think you need all of it)

t=0
lychrel=0
called=0

def iteratepal(n):
    global t
    global called
    called+=1
    b = int(''.join(reversed(str(n))))
    #print ("n =",n,"\nb =",b,"\nb+n =",b+n,"\n")

    if ispal(b+n) or ispal(n):
        t=0
        return False

    if t<50:
        t+=1
        iteratepal(b+n)
    else:                          # Here's the prob
        t=0                        # this block is executed (because it prints "yea")
        print("yea")               # but it doesn't return True!
        return True                # you can try it yourself (even in the interpreter)

def ispal(n):
    if n == int(''.join(reversed(str(n)))):
        return True
    return False

print(iteratepal(196))

for i in range(0,200):
    if iteratepal(i)==True:
        lychrel+=1
        print(i,"is Lychrel!")
    else:
        print(i,"is not a Lychrel!")
print(lychrel)

Thanks for any help, I’m really confused with this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:22:25+00:00Added an answer on June 11, 2026 at 4:22 pm

    You call the function recursively when t < 50, but don’t do anything with the return value:

    if t<50:
        t+=1
        iteratepal(b+n)
    else:                          
        t=0                        
        print("yea")               
        return True
    

    The else: branch is never executed then, so None is returned instead. You probably want to return the result of the recursive call:

    if t<50:
        t+=1
        return iteratepal(b+n)
    else:                          
        t=0                        
        print("yea")               
        return True
    

    Some further tips:

    • There is no need to test for ==True in an if statement, the following will work just fine:

      if iteratepal(i):
      
    • You can return the test in def ispal(n) is itself a boolean result, just return that without testing:

      def ispal(n):
          return n == int(''.join(reversed(str(n))))
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What should main() return in C/C++? What does main return? I've been
Possible Duplicate: Why does column = NULL return no rows? I am trying to
Possible Duplicate: What does Asynchronous means in Ajax? jQuery ajax return value Trying to
Possible Duplicate: JavaScript: why does parseInt(1/0, 19) return 18? Why does parseInt(1/0, 19) evaluate
Possible Duplicate: Why does second function declaration win even though I return before it?
Possible Duplicate: Java - why no return type based method overloading? The compiler does
Possible Duplicate: What does jQuery.fn mean? I have some script on a page trying
Possible Duplicate: Why does InputStream#read() return an int and not a byte? Issue regarding
Possible Duplicate: Why does Enumerable.All return true for an empty sequence? Code: var line
Possible Duplicate: What does map(&:name) mean in Ruby? Post.all.map(&:id) will return => [1, 2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.