Easy function, please help.

Terry Reedy tjreedy at udel.edu
Wed Feb 9 15:48:27 CET 2011

On 2/9/2011 9:27 AM, RJB wrote:
> On Feb 8, 11:08 pm, Paul Rudin<paul.nos... at rudin.co.uk>  wrote:
>> It works because 0 tests false and because integer division yields
>> integers... eventually you'll get something like 1/10 giving 0.
>> It's not necessarily a good thing to rely on. For example if you try it
>> after "from __future__ import division" - or in python 3 - you'll get a
>> float as the result of the division and it won't test False.
> What operator should I use if I want integer division?


The line should be 'n = n//10' or even 'n //= 10'.
You might have answered your own question be putting
print(n, count) at the top of the loop body.
Print is an excellent tool.

Terry Jan Reedy

More information about the Python-list mailing list