<jupyter_start><jupyter_text>Objective Write a program that performs various functions in Python, based on the user input.The requirements are:- Print out a menu of options, then query the user to select one.- Based on the user’s choice, calculate the following:     - Calculate the first n Fibonacci numbers (where the user enters a number, n). The defination of Fibonacci numbers is followed.$$ f(n) = \left\{\begin{array}{l}0  & (n=1),\\1  & (n=2),\\f(n-1) + f(n-2) & (n>2).\\\end{array}\right.$$     - Print the numbers 1 to n, and print “Fizz” for mulitiples of 3, and “Buzz” for multiples of 5, and “FizzBuzz” for multiples of both (where the user enters a number, n).     - Calculate the primes numbers up to n (where the user enters a number, n).     - Create a list of random numbers, each random number being between -50 and 50, where the list is n long (where the user enters a number, n).  Code<jupyter_code>import random


# Calculate the first n Fibonacci numbers
def fibonacci(n):
    fn_list = [0, 1]
    while len(fn_list) < n:
        fn_list.append(fn_list[-1]+fn_list[-2])
    return fn_list[:n]


# Return the numbers 1 to n, and print “Fizz” for mulitiples of 3, and “Buzz” for
# multiples of 5, and “FizzBuzz” for multiples of both
def fizz_buzz(n):
    result = []
    for i in range(1, n+1):
        if i % 15 is 0:   # 15, 30, ...
            result.append("FizzBuzz")
        elif i % 3 is 0:  # 3, 6, 9, 12, ...
            result.append("Fizz")
        elif i % 5 is 0:  # 5, 10, 15, ...
            result.append("Buzz")
        else:
            result.append(i)
    return result


# Judge whether a number is a prime number
def _judge_prime(n):
    flag = True
    for i in range(2, n):
        if n % i is 0:
            flag = False
            break
    return flag


# Calculate the primes numbers up to n
def primes(n):
    return [i for i in range(2,n+1) if _judge_prime(i)]


# Take in an user input
def _get_input_number():
    while True:
        number = input("Please input an integer number n for the function: ")
        if number.isnumeric():
            break
        else:
            print("That was not an integer number, please try again.")
    number = int(number)
    return number


# Generate a list of random numbers, each random number being between -50 and
# 50, where the list is n long
def generate_randoms(n):
    result = []
    for i in range(n):
        result.append(random.randint(-50, 50))
    return result


choice_descriptions = [
    "\n# Here are four choices, you can select one to perform the corresponding function.",
    '1. Calculate the first n Fibonacci numbers.',
    '2. Print the numbers 1 to n, and print “Fizz” for mulitiples of 3, and “Buzz” for \
multiples of 5, and “FizzBuzz” for multiples of both.',
    '3. Calculate the primes numbers up to n.',
    '4. Create a list of n random numbers between -50 and 50.']

user_menu = {
    '1': fibonacci,
    '2': fizz_buzz,
    '3': primes,
    '4': generate_randoms
}

while True:
    for line in choice_descriptions:
        print(line)
    user_choice = input("- Please input your choice:")
    if user_choice in user_menu.keys():
        n = _get_input_number()
        print(user_menu[user_choice](n))
    else:
        print("It is not a valid choice.")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10626128838049367, 'fraction_numerical': 0.021372667068031308, 'mean_word_length': 2.6516483516483516, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '345085', 'license': 'MIT', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1036, 'n_words': 435, 'path': 'practice/example3.ipynb', 'repo_name': 'Pengeace/PythonTutorial', 'size': '3322'}