Question: For Python 2.7 The following code produces the first 10 integers in the Fibonacci sequence: 1 a = b = 1 2 fib_numbers = [a]

For Python 2.7

For Python 2.7 The following code produces the first 10 integers in

The following code produces the first 10 integers in the Fibonacci sequence: 1 a = b = 1 2 fib_numbers = [a] 3 a, b = b, a + b 4 fib_numbers.append (a) 5 a, b = b, a + b 6 fib_numbers.append (a) 7 a, b = b, a + b 8 fib_numbers.append (a) 9 a, b = b, a + b 10 fib_numbers.append (a) 11 a, b = b, a + b 12 fib_numbers. append (a) 13 a, b = b, a + b 14 fib_numbers.append (a) 15 a, b = b, a + b 16 fib_numbers.append (a) 17 a, b = b, a + b 18 fib_numbers.append (a) 19 a, b = b, a + b 20 fib_numbers.append (a) 21 22 print fib_numbers Output: [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] Write a generator called Fib that produces Fibonacci numbers. Your generator should accept a parameter named end that specifies how many numbers will be produced before throwing a StopIteration exception. Use your generator with a for-loop to print the first 20 numbers in the Fibonacci sequence to the screen. For example: for i in Fib (20): print

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!