Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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): printStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started