Skip to content
Advertisement

Python while loop not working as intended

I don’t know how to get over this problem with while loop. So basically I want to return the number of zeros at the end of a number’s factorial.

JavaScript

After the while loop runs only 1 time, it breaks; I don’t know why.

Help would be very appreciated. Thanks!

Advertisement

Answer

After multiplying your value by 0.1 it becomes a float, and it’s string representation becomes the scientific notation 2.6525285981219107e+31 which doesn’t end by a 1

You’d better do the integer division by 10 to keep an int

JavaScript

Better You can also use str.rstrip : you remove the leading zeros and check the length difference

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