[Tutor] project euler #4

Alan Gauld alan.gauld at yahoo.co.uk
Mon May 11 04:01:54 EDT 2020


On 11/05/2020 04:46, Nitish Kumar wrote:
> i am an ansolute noob at python...i started teaching myself a while back
> please review my code....and please point out the errors...

It would help us if you could point out the errors. Specifically include
any error messages and tell us what happens when you run it. Don't
expect us to run a strangers code from an email.)

> can i not call or a function in a loop??

You can call all the functions you want.


> #largest 3x3 digit palindrome no
> 
> palin = []
> for i in range(100, 999):
>     for j in range(100, 999):
>         x = (i* j)

I'm not sure why you put this in parens, it not needed.

>         if x isPalindrome(x)

This should give a syntax error - no :
And no indented block

>         palind.append(t)

And this should give a name error. Check the spelling.

> print(palin)
> 
> 
> 
> 
> def isPalindrome(n):
>     temp = n
>     rev = 0
>     while(n > 0):
>         digit = n % 10
>         rev = rev*10 + digit
>         n = n // 10

This loop should never end since n will always be
greater than zero, albeit becoming very small.

>     if rev == temp:
>         return True

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list