Skip to content

Instantly share code, notes, and snippets.

@johnholbrook
Last active December 29, 2015 05:39
Show Gist options
  • Select an option

  • Save johnholbrook/7623439 to your computer and use it in GitHub Desktop.

Select an option

Save johnholbrook/7623439 to your computer and use it in GitHub Desktop.
compares number of length n to the first n digits of sqrt(n). if they are identical, adds n to a list.
print "importing"
from math import sqrt
print "done importing"
def compare(num, root):
length = len(str(num))
print length
part = root[:length]
if part == num:
return True
else:
return False
numbers = []
highest = raw_input("How high?")
current = 1
while current <= highest:
result = compare(current, sqrt(current))
if result == True:
numbers.append(current)
current += 1
print "I found " + len(str(numbers)) + " such numbers below " + str(highest)
print numbers[0:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment