[Tutor] project euler #4
Sibylle Koczian
nulla.epistola at web.de
Mon May 11 05:04:42 EDT 2020
Am 11.05.2020 um 10:01 schrieb Alan Gauld via Tutor:
> 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...
>
>> 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.
>
Wrong. The division is integer division, of course n will be zero. This
might be a little faster using divmod(n, 10) - and learning about divmod
will often be useful. But the function is quite correct.
Greetings
Sibylle
More information about the Tutor
mailing list