Jupiter. Please do that Fibonacci(n) function. n is an integer. The function ret
ID: 3935130 • Letter: J
Question
Jupiter. Please do that Fibonacci(n) function. n is an integer. The function returns the nth Fibonacci number. If you do not know what the n-th Fibonacci number is, study it on a Wikipedia page. You must use accumulator variables in your solution. Do not use simultaneous assignment. Write also test0 function to list the first 20 Fibonacci numbers in which numbers are precisely RIGHT JUSTIFIED as illustrate in the following (Blackboard may not show the output precisely. Stick to the RIGHT-JUSTIFIED requirement):Explanation / Answer
def fibonacci(n):
first = 0
second = 1
next = 0
for i in range(1,n+1):
if i <= 1:
next = i
else:
next = first + second;
first = second;
second = next;
print "The " + str(i).rjust(2) + "th fibonacci number is: " + str(next).rjust(5)
def test():
fibonacci(20)
test()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.