Question

Write a python function to print a Fibonacci sequence up to the nth term entered by...

Write a python function to print a Fibonacci sequence up to the nth term entered by the user. For ex. If user entered 10, then your function should output 0,1,1,2,3,5,8,13,21,24.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#Code.py
N = int(input("Enter a number: "))
if(N>=1):
    print(0,end=" ")
if(N>=2):
    print(1,end=" ")
if(N>=3):
    fold1 = 0
    fold2 = 1
    fnew = 1
    for i in range(N-2):
        print(fnew,end=" ")
        fold1 = fold2
        fold2 = fnew
        fnew = fold1 + fold2

Add a comment
Know the answer?
Add Answer to:
Write a python function to print a Fibonacci sequence up to the nth term entered by...
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
  • python Write a function that takes as input a single integer parametern and computes the nth...

    python Write a function that takes as input a single integer parametern and computes the nth Fibonacci Sequence number The Fibonacci sequence first two terms are 1 and 1(so, if n - 2 your function should return 1). From there, the previous two values are summed to come up with the next result in the sequence 1.1,2,3,5,8,13, 21, 34, 55, etc.) For example, if the input is 7 then your function should return 13 26561.1615880 1 def Fibonacci(n): # your...

  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • Below you will find a recursive function that computes a Fibonacci sequence (Links to an external...

    Below you will find a recursive function that computes a Fibonacci sequence (Links to an external site.).   # Python program to display the Fibonacci sequence up to n-th term using recursive functions def recur_fibo(n): """Recursive function to print Fibonacci sequence""" if n <= 1: return n else: return(recur_fibo(n-1) + recur_fibo(n-2)) # Change this value for a different result nterms = 10 # uncomment to take input from the user #nterms = int(input("How many terms? ")) # check if the number...

  • F25 = 75,025 and F26 = 121,393 where Fn is the nth term in the Fibonacci sequence

    F25 = 75,025 and F26 = 121,393 where Fn is the nth term in the Fibonacci sequence. Find F27.

  • 2. The Fibonacci numbers are defined by the sequence: f = 1 f2 = 1 fo=fni...

    2. The Fibonacci numbers are defined by the sequence: f = 1 f2 = 1 fo=fni + 2 Implement a program that prompts the user for an integer, n, and prints all the Fibonacci numbers, up to the nth Fibonacci number. Use n=10. Show a sample output with the expected results. Output: Enter a number: 100 number Fib 89

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Write a formula for the general term or nth term for the sequence. Then find the...

    Write a formula for the general term or nth term for the sequence. Then find the indicated term. 6, 8, 10, 12, 14, ..., 210 an-(Simplify your answer. Type an expression using n as the variable.) a 10 (Simplify your answer.)

  • Write a formula for the general term (the nth term) of the arithmetic sequence, a, a,...

    Write a formula for the general term (the nth term) of the arithmetic sequence, a, a, ag, ...Then, use the formula for an to find azo, the 20th term of the sequence 4.1. - 2.-5... an- (Simplify your answer.)

  • is this correct Write a formula for the general term or nth term for the sequence....

    is this correct Write a formula for the general term or nth term for the sequence. Then find the indicated term. 6, 8, 10, 12, 14, ...; 010 an-2n + 4 (Simplify your answer. Type an expression using n as the variable.) 210 = 24 (Simplify your answer.)

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