Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:4465193
Created Jan 6, 2013

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__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment