Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me write this in Python language with comments explaining what's happening in the code. 1. The following program calculates the Fibonacci value given

Please help me write this in Python language with comments explaining what's happening in the code.

image text in transcribed

1. The following program calculates the Fibonacci value given a number (let say 50). def fibonaccin) "-"Recursive fibonacci that remembers previous values". if n not in fibo dict: + recursive case, store in the dict fibo dict[n] = fibonacci(n-1) + fibonacci (n-2) return fibo_dict[n] #global fibonacci dictionary. fibo dict = 1 # enter the base cases fibo dict[0] = 1 fibo dict[1] = 1 fibo_val = input ("Calculate what Fibonacci value:") print("Fibonnaci value of", fibo_val, "is", fibonacci(int (fibo_val) >) Rewrite the program using generator function. Use the following template: def fibo_generator(): fibo_generator_object = fibo_generator () print (next(fibo_generator_object)) print (next(fibo_generator_object)) for print (next (fibo_generator_object), enda', Sample output: 0 1 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2179309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903 2971215073 4807526976, 7778742049, 12586269025, 20365011074

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

Heas twimantse Requirements

Answered: 1 week ago

Question

2. What efforts are countries making to reverse the brain drain?

Answered: 1 week ago