Question

USE PYTHON / RECURSION METHOD

Fibonacci Dictionary Function Name: fibtionary Parameters: num (int) Returns: dictionary (key: int, value: int) Description:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# STAY HOME # STAY SAFE
# initialize a global dictionary
di={1:1,2:1}
pos=3
limit=0
flag=1

# recursive function fibtionary
def fibtionary(num):
# use the global variables
global pos,limit,flag
global di
# set the value of limit as num
if(flag==1):
limit=num
flag=0
  
# if num is 1 then return {1:1}
if(num==1):
return {1:1}
# if num is 2 then return di
if(num==2):
return di
else:
# else build the dictionary and recursively call the function until the pos reaches the limit
di[pos]=di[pos-1]+di[pos-2]
pos=pos+1
# if the pos becomes greater than limit then return di
if(pos>limit):
return di
# else call the function recursively
else:
return fibtionary(pos)

  
num1 = 5
print(fibtionary(num1))

In [15]: #STAY HOME #STAY SAFE # initial in a global dictionary di (1:1, 2:1) pos=3 limite flap-1 # recursive function fibtioIn 16]: STAY HONE STAY SAFE initialize a global dictionary dis 1:1, 2:1} posm3 linite fla=1 # recursive function fibtionary d

Add a comment
Know the answer?
Add Answer to:
USE PYTHON / RECURSION METHOD Fibonacci Dictionary Function Name: fibtionary Parameters: num (int) Returns: dictionary (key:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT