Skip to content
Advertisement

Function digits(n) that returns how many digits the number has , returns a random value in python

The function digits, in the while loop – while (n > 0) returns 325 326 327 and 1 as the count value and if I use while (n > 1) it returns the correct number count. Any logical reason for this behavior?

JavaScript

Advertisement

Answer

There is a difference between / and //.

/ does the normal division given an accurate answer upto 15 decimal places in python. However, // is the floor division method where only the quotient of the division is returned.

try to replace:

JavaScript

with this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement