EDIT
You asked for the shortest, right?
def peasInAPod():
win = GraphWin(100,500)
list(map(lambda p: p.draw(win), [Circle(Point((i*100)+50,100),50) for i in range(int(input('How many peas? ')))]))
You need the list
to actually execute the lambda
.
Original answer:
Something like this?
def peasInAPod():
win = GraphWin(100,500)
peas = eval(input('How many peas? ')) # Use something safer than eval
for i in range(peas):
p = Circle(Point((i*100)+50,100),50)
p.draw(win)
I'm assuming you don't need to reuse the p*
variables elsewhere, and that you don't need to store or refer later to the list of peas (this just draws them). The more spec you provide, the better answer you'll get! Hope this helps.
Just for fun, here's a generator too! Sorry, I couldn't help it...
def the_pod(how_many):
for p in range(how_many):
yield Circle(Point((p*100)+50,100),50)
def peasInAPod():
win = GraphWin(100,500)
of_all_the_peas = input('How many peas? ') # raw_input for Python < 3
for one_of_the_peas in the_pod(int(of_all_the_peas)):
one_of_the_peas.draw(win)
This copies, pastes, and executes without any dependencies. Just in case you're after an infinite generator that forces people to have infinity peas.
def the_pod():
p = 0
while True:
yield (p*100)+50
p += 1
def peasInAPod():
print('You may have all the peas. Well. Only their x-coordinate.')
for one_of_the_peas in the_pod():
print(one_of_the_peas)
peasInAPod()
I'm off to get some pea soup. Thanks!