Skip to content

anonymous /gist:4465193

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
use len(str(x)) to find the length of a number
"""Compares two differing methods of determining a number's length."""
import math
def using_log(number):
"""Using math.log to figure out the length of a number."""
return math.floor(math.log(number, 10)) + 1
def using_len(number):
"""Converts the number to a string and determines length through len()."""
return len(str(number))
def find_weird_maths():
"""Finds where the levee breaks."""
digit = 9
number = digit
for i in range(1, 500):
if using_log(number) != using_len(number):
print "9's x %d differs logrithmic v string." % using_len(number)
number = int(str(digit) * i)
if __name__ == "__main__":
find_weird_maths()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.