Generator LAB

Write some generators:

(test code in test_generator.py)

Sum of the integers:

keep adding the next integer

0 + 1 + 2 + 3 + 4 + 5 + ...

so the sequence is:

0, 1, 3, 6, 10, 15 .....

Doubler

Each value is double the previous value:

1, 2, 4, 8, 16, 32,

Fibonacci sequence

The fibonaccisequenc as a generator:

f(n) = f(n-1) + f(n-2)

1, 1, 2, 3, 5, 8, 13, 21, 34...

Prime numbers

Generate the prime numbers (numbers only divisible by them self and 1):

2, 3, 5, 7, 11, 13, 17, 19, 23...

Others to try:

Try x^2, x^3, counting by threes, x^e, counting by minus seven, ...