Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone explain what is happening in words, step by step for this oding Probiem S.2.2 Q Bookmark this page Coding Problem 5.2.2 (External resource)

Can someone explain what is happening in words, step by step for this
image text in transcribed
oding Probiem S.2.2 Q Bookmark this page Coding Problem 5.2.2 (External resource) 80/30 poi 1|#Aemember that Fibonacci's sequence is a sequence of 2 where every number is the sum of the previous two numbers. For this problem, implement Fibonacci recursively, with a twistl Imagine that we want to create a new number sequence 6 Icalled Fibonacci-3. In Fibonacci-3, each number in the 7 dsequence is the sum of the previous three numbers. The 8.sequence will start with three is, so the fourth Fibonacci-3 9 #number would be 3 (1+1+1), the fifth would be 5 (1+1+3), 10 the sixth would be 9 (1+3+5), the seventh would be 17 11 3+5+9), etc 12 13 Name your function fib3, and make sure to use recursion. 14 15 16 Write your code herel 17 def fib3 (n) 18 ror n-_ 2 or n--3: return 1 else: 20 21return fib3 (n-1)+fib3 (n-2)+fib3 (n-3) 23 #The lines below will test your code. rf your funciton is 24 fcorrect, they will print 1:317and $7 25 print (fib3(3)) 26 print (fib3(4)) 27 print (fib3 (7)) 28 print (fib3(9)) 29 30 31

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions