Answer to Question #246995 in Python for Hiruni

Question #246995
Fibonacci sequence is defined with an integer n as,
F(n)=F(n-1)+F(n-2) for n ≥2,where F(0)=0,F(1)=1.
develop a Python program to compute F(n) for a given integer between 0 and 20.
Input: Output:
0≤n≤20 F(n)≤2 to the power32
Compute F(n) starting with n=2 and increment iteratively until the required value is obtained.
instructions-
Create a text file include the value ofn. The text file needs to saved in same folder
where the source file has been saved. The file name will be given as input through terminal.
Develop a function named“getNum"to read number n from file.
Develop a function named “show” to display the given value n and computed value
of F(n) on screen. (Expected output format Fibonacci(3) = 2)
Develop a function “saveFile” to write what was displayed in (3) above to a text
file named"result.txt”. This file should be in same folder where source file is.
program must call suitable functions to do the task.
1
Expert's answer
2021-10-05T23:13:36-0400
import shutil
def fibonacci(n):
    f = [0, 1]
     
     
    for i in range(2, n+1):
        f.append(f[i-1] + f[i-2])
    return f[n]
     
print(fibonacci(12))


src = input("Enter src filename:")
def getNum():
    N =N.fibonacci()
def show():
    print(fibonacci(12))
    n=12
    print(n)


show()


src = "saveFile"
dest = "result.txt"
shutil.copyfile(src, dest)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS