## Palindrome Problem

For questions about problems on the Project Euler web site. No spoilers. Please include the question number in the subject line of your post.

### Palindrome Problem

Hello, my name is Austin. First time doing a forum for my projects, but figured wisdom from wise individuals would be beneficial.

I just starting with Python, been doing HTML, CSS, PHP and SQL for 8 years. Moving my way towards computer based programming.

Now that my past is out of the way, here is my problem.

Challenge # 4 on Euler, find the largest Palindrome number from the product of two 3-digit numbers. I did a flowchart, and I think it will work, but it's not printing anything. Here is my code:

Code: Select all
`def ans_rev(ans):    return int(str(ans)[::-1])def main():    i = 9    while i <= 9 & i > 0:        a = 9        ans = a * i        pal = ans_rev(ans)                if ans == pal:            print(ans)        else:            print('. ')            i = i - 1`

I was going to start small (1 digit numbers), and work my program up to 3-digit numbers. I know I will need to cycle a for when i reaches 0, but I know the largest here is (9 * 6 = 55). Question is, why doesn't it print anything? If I understand the why, I can solve for that problem.
virtuouswheel44

Posts: 1
Joined: Fri Jun 07, 2013 4:41 pm

### Re: Palindrome Problem

None of your code is getting executed, you're just defining functions.
You probably want to call main().

Also, here:
Code: Select all
`while i <= 9 & i > 0:`

You want and instead of &, which is the binary and operator.
You could also write:
Code: Select all
`while 0 < i <= 9:`

And finally, this looks like it should be a for loop.
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Return to Project Euler

### Who is online

Users browsing this forum: No registered users and 1 guest