I have one baseball and want to completely surround it with others.
One way: put six around the center one on a table, then three on
top, three on the bottom. With real baseballs, this would be difficult.
To see an animation of what I'm talking about, check here:
For a lot more on the mathematics, check here:
sprite = codesters.Sprite("person10")
sprite.set_say_color("white") # for speaking
input n should be a non-negative integer
says how many balls in any layer
if (not isinstance(n, int)) or n < 0:
raise TypeError # signals we're done!
if n == 0:
return 1 # the central ball
return 10 * n * n + 2 # otherwise, if n > 0
# put in a negative number to stop
while True: # loop until TypeError is raised by user
guess = int(sprite.ask("What layer number? (-1 to quit): >"))
how_many = shell(guess)
sprite.say("That layer has " + str(how_many) + " balls in it.")
sprite.say("OK! Thanks for playing.")