📜  python fiboncci - Python (1)

📅  最后修改于: 2023-12-03 15:34:00.115000             🧑  作者: Mango

Python Fibonacci

Python Fibonacci is a simple Python script that generates the Fibonacci sequence.

Installation

To use this script, first ensure that you have Python installed on your system. Then, download the Python Fibonacci script from the GitHub repository and save it to a location of your choice.

Usage

To run the Python Fibonacci script, open a command prompt or terminal window and navigate to the directory where you saved the script. Then, enter the following command:

python fibonacci.py

This will generate the Fibonacci sequence and print it to the console.

Code

Here is the code for the Python Fibonacci script:

def fibonacci(n):
    if n < 0:
        return None
    elif n == 0:
        return [0]
    elif n == 1:
        return [0, 1]
    else:
        fib = [0, 1]
        for i in range(2, n+1):
            fib.append(fib[i-1] + fib[i-2])
        return fib

if __name__ == '__main__':
    n = input("Enter the number of terms in the Fibonacci sequence: ")
    print(fibonacci(int(n)))

The fibonacci function takes an integer n as an argument and returns a list containing the first n numbers in the Fibonacci sequence. The main block of code prompts the user to enter the number of terms they want to generate, converts this input to an integer, calls the fibonacci function, and prints the result to the console.

License

Python Fibonacci is released under the MIT License. Feel free to use, modify, and distribute this code as you see fit.