To the people who kindly replied to my question: many thanks!


On 10/31/2013 06:29 PM, Danny Yoo wrote:
As an aside: It shouldn't be too bad to write a "generator" for the geometric series, so that we can pick out the terms on-demand.

#################################
>>> def geometric(base):
...     x = 1
...     while True:
...         yield x
...         x *= base
...
>>> twos = geometric(2)
#################################


'twos' is a representation of the geometric series; we can then pick out the elements one at a time:


#################################
>>> twos.next()
1
>>> twos.next()
2
>>> twos.next()
4
>>> twos.next()
8
>>> twos.next()
16
>>> twos.next()
32
>>> twos.next()
64
#################################


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to