<jupyter_start><jupyter_text>Introduction From Wikipedia:>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:>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...>By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.>The sequence Fn of Fibonacci numbers is defined by the recurrence relation:>**$F_{n}$ = $F_{n-1}$ + $F_{n-2}$**  Instructions Write a function called **fibonacci** to calculate the fibonnaci sequence of a given starting number.  Solution<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Recursion<jupyter_code>def fibonacci(n):
    '''with recursion'''
    
    # error checking
    assert n >= 0, 'n must be a nonnegative integer'
    assert type(n) == int, 'n must be a nonnegative integer'
    
    # main logic
    if n == 0: 
        return 0
    elif n == 1: 
        return 1
    else: 
        return fibonacci(n-1) + fibonacci(n-2)
for i in range(10):
    print('n: {} | result: {}'.format(i, fibonacci(i)))<jupyter_output>n: 0 | result: 0
n: 1 | result: 1
n: 2 | result: 1
n: 3 | result: 2
n: 4 | result: 3
n: 5 | result: 5
n: 6 | result: 8
n: 7 | result: 13
n: 8 | result: 21
n: 9 | result: 34
{'fraction_non_alphanumeric': 0.10854816824966079, 'fraction_numerical': 0.03934871099050204, 'mean_word_length': 3.6825396825396823, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '311356', 'license': 'MIT', 'n_tokens_mistral': 541, 'n_tokens_neox': 474, 'n_words': 209, 'path': 'notebooks/Python/Programming_Problems/Fibonacci.ipynb', 'repo_name': 'ashishpatel26/Data_Science_Fundamentals', 'size': '1474'}