Question

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci...

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …

The sequence Fn of Fibonacci numbers is defined by the recurrence relation:

Fn = Fn-1 + Fn

with seed values F1 = 1 F2 = 1

For more information on Fibonacci Numbers see Wikipedia. We want to write a program that asks the user how many Fibonacci numbers they want to generate, put them in a list and then output the list. Keep in mind there are 3 special cases we need to handle.

Number to Fibonacci numbers to generate Result
0 []
1 [1]
2 [1,1]

One last reminder is we user the list.append(value) to add value to list. See Adding and removing list elements in Section 3.2. The output of the program should look like this.

How many Fibonacci numbers would you like to generate? 5

The first 5 Fibonacci numbers are [1, 1, 2, 3, 5].

Homework Answers

Answer #1

Python Program:

# Fibonacci number generator function
def fibonacci_numbers(num):
    fib_list = [1, 1]
    
    if num == 0:
        return []
    elif num == 1:
        return fib_list[0:1]
    elif num == 2:
        return fib_list
    else:
        for i in range(2, num):
            next_fibonacci = fib_list[i-1] + fib_list[i-2]
            fib_list.append(next_fibonacci)
            
    return fib_list
    
# Main Driver Function
if __name__ == "__main__":
    num = int(input("How many Fibonacci numbers would you like to generate? "))
    fibonacci_list = fibonacci_numbers(num)
    print("The first {0} Fibonacci numbers are : {1}".format(num, fibonacci_list))

Output:

Thumbs Up Please !!!

Know the answer?
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
Similar Questions
Write a VSC (macro) program that computes and displays a Fibonacci sequence. A Fbonacci sequence is...
Write a VSC (macro) program that computes and displays a Fibonacci sequence. A Fbonacci sequence is generated by adding the two most recent sequence numbers together, i.e., 1, 1, 1+1-2, 1+2=3, 2+3=5, 3+5=8, … The user will enter the number of terms in the sequence to be displayed. Assemble this program using the VSC assembler (ASM), and simulate this program using the VSC simulator (SIM). Include a copy of the source listing (SOURCE.DAT), the assembled listing (SLIST.DAT) and the simulation...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Solution.The Fibonacci numbers are defined by the recurrence relation is defined F1 = 1, F2 =...
Solution.The Fibonacci numbers are defined by the recurrence relation is defined F1 = 1, F2 = 1 and for n > 1, Fn+1 = Fn + Fn−1. So the first few Fibonacci Numbers are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . . There are numerous curious properties of the Fibonacci Numbers Use the method of mathematical induction to verify a: For all integers n > 1 and m > 0 Fn−1Fm + FnFm+1...
IN C++ The Catalan numbers are an integer sequence Cn that appears in tree-enumeration problems. The...
IN C++ The Catalan numbers are an integer sequence Cn that appears in tree-enumeration problems. The first Catalan numbers for n = 1, 2, 3, ... are 1, 2, 5, 14, 42, 132, .... A formula generating Cn is: Cn=(1÷(n+1))=(2n)!÷(n+1)!n! Design two programs that communicate with shared memory using the Win32 API as outlined in Section 8.7.2. The producer process will generate the Catalan sequence and write it to a shared memory object. The consumer process will then read and...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Draw a flowchart for a computer program to receive 40 numbers and output “yes” if number...
Draw a flowchart for a computer program to receive 40 numbers and output “yes” if number of negative values among the first 10 inputs is equal to number of positive values among the last 10 inputs. Note. The 20 numbers in middle are ignored. For instance, if the values are: 1,-1,1,1,-1,1,-2,5,1,1,4,4,5,-6,5,8,-12,0,2,0,1,2,3,7,7,-7,0,1,1,1,3,4,1,-1,-1,-1,-1,-1,-1,-1 the program should output “yes” since the number of negative values in the first 10 numbers is 3, and the number of positive values in the last 10 numbers...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in the sequence, the next number in the sequence is determined by two simple rules: If the current number n is odd, the next number in the sequence is equal to 3 * n + 1 If the current number n is even instead, the next number in the sequence is equal to one half of n (i.e., n divided by 2) We repeat this...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...