Created
November 23, 2011 17:21
-
-
Save justinvoss/1389272 to your computer and use it in GitHub Desktop.
Tennis Ball Pyramid Part Deux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pyramid(level): | |
total = 0 | |
for x in range(1, level+1): | |
total += (x * x) | |
return total | |
assert pyramid(1) == 1 | |
assert pyramid(2) == 5 | |
assert pyramid(3) == 14 | |
print "Tennis balls in a 10,000-level pyramid: %d" % pyramid(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment