Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN PYTHON Consider the following sequence of numbers (Its not the fibonacci sequ

ID: 3812450 • Letter: I

Question

IN PYTHON Consider the following sequence of numbers (Its not the fibonacci sequence) 1,1,1,3,5,9,17,31,57.. the first 3 numbers are 1 1 and 1 . Every subsequent number is the sum of the previous 3 numbers . This the 4th number is the sum of 1,1,1 = 3 . The fifth number is the sum of. 1,1,3 thus 5. The sixth number is the sum of. 1,3,5 thus 9 and so on and so forth.

q1 5 points given n output the nth number in this sequence.

sample output:

enter n: 6

the answer is. 9

q2. given two numbers a and b output all numbers in the sequence between a and b (inclusive)

sample output

enter a : 2

enter b: 30

3 5 9 17

Explanation / Answer

Answer:

import sys


n = int(raw_input().strip())
def fibo(n):
if n<=1:
return 1
else:
return fibo(n-1)+fibo(n-2)+fibo(n-3)
print(fibo(n))

output:

Input (stdin)

Your Output

2)

import sys


a = int(raw_input().strip())
b = int(raw_input().strip())
def fibo(n):
if n<=1:
return 1
else:
return fibo(n-1)+fibo(n-2)+fibo(n-3)
for i in range (0,b):
n1=fibo(i)
if(a<=n1<=b):
print(n1)
else:
break