<jupyter_start><jupyter_text>Exercise 09.1 (checking data validity)The Fibonacci series is valid only for $n \ge 0$. Add to the Fibonacci function in this notebook a check that raises an exception if $n < 0$. Try some invalid data cases to check that an exception is raised.*Optional:* Use `pytest` to test that an exception *is* raised for some $n < 0$ cases.<jupyter_code>def f(n): 
    "Compute the nth Fibonacci number using recursion"
    # YOUR CODE HERE
    raise NotImplementedError()
# Perform some tests    
assert f(0) == 0
assert f(1) == 1
assert f(2) == 1
assert f(3) == 2
assert f(10) == 55
assert f(15) == 610

# Check that ValueError is raised for n < 0
import pytest
with pytest.raises(ValueError):
    f(-1)
with pytest.raises(ValueError):
    f(-2)<jupyter_output><empty_output><jupyter_text>Exercise 09.2 (raising exceptions)Modify your program from the bisection exercise in Activity 04 to raise an error if the maximum number of iterations is exceeded. Reduce the maximum allowed iterations to test that an exception is raised.Add any other checks on the input data that you think are appropriate.<jupyter_code>def my_f(x):
    "Evaluate polynomial function"
    return x**3 - 6*x**2 + 4*x + 12

def compute_root(f, x0, x1, tol, max_it):
    # YOUR CODE HERE
    raise NotImplementedError()
# Test with max_it = 30
x, f, num_it = compute_root(my_f, x0=3, x1=6, tol=1.0e-6, max_it=30)

# Test with max_it = 20
with pytest.raises(RuntimeError):
    x, f, num_it = compute_root(my_f, x0=3, x1=6, tol=1.0e-6, max_it=20)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10082961072112316, 'fraction_numerical': 0.0389278876834716, 'mean_word_length': 4.3883161512027495, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '185171', 'license': 'MIT', 'n_tokens_mistral': 578, 'n_tokens_neox': 536, 'n_words': 201, 'path': 'Assignment/09 Exercises.ipynb', 'repo_name': 'reddyprasade/PYTHON-BASIC-FOR-ALL', 'size': '1567'}