<jupyter_start><jupyter_text>Python basic exercises* You are expected to complete all basic exercises.* Advanced exercises are prefixed with \*.* You are free to use any material (lecture, Stackoverflow etc.) except full solutions. 1. `range()` practice 1.1 Print the numbers between 70 and 79 inclusive.  1.2 Print the first 10 square numbers starting from 1.  \*1.3 Print the numbers from 19 to 10 (backwards).  2. Reading user inputUser input can be read with the `input()` function. It always returns a string which can be converted to integer using the `int()` function.<jupyter_code>n = input()
int(n)<jupyter_output><empty_output><jupyter_text>2.1 Read a number N and print the numbers from 1 to N.  2.2 Read a number N and print the first N square numbers starting from 1.  2.3 Read numbers until 0 and print their sum.  \*2.4 Read numbers until 0 and print their mean and standard deviation without using a list.  3. Lists 3.1 Print the odd numbers from this list.<jupyter_code>l = [2, 3, -2, -7, 0, 2, 3]<jupyter_output><empty_output><jupyter_text>3.2 Read numbers until 0 and collect them in a list. Print the elements backwards (zero not included).For example:```input: 3 4 2 12 3 0output: 3 12 2 4 3 ```  3.3 Read a number N and then read exactly N numbers. Print them backwards.For example:```input: 4 -1 0 2 12output: 12 2 0 -1```  4. FunctionsThe following exercises contain function skeletons. Finish these functions.If you work correctly, the assert statements should not fail, however, passing all tests does not guarantee that your solution is correct.You are free to add more tests. 4.1 Write a function that takes an integer parameter (N) and returns a list of the first N prime numbers starting from 2.<jupyter_code>def get_n_primes(N):
    # TODO

assert(get_n_primes(3) == [2, 3, 5])<jupyter_output><empty_output><jupyter_text>4.2 Write a function that takes an integer parameter (N) and returns the Nth Fibonacci number.The Fibonacci series starts as 1, 1, 2, 3, 5, 8, so the 2nd number is 1 and the 3rd number is 2.<jupyter_code>def get_nth_fibonacci(N):
    # TODO

assert(get_nth_fibonacci(3) == 2)
assert(get_nth_fibonacci(2) == 1)<jupyter_output><empty_output><jupyter_text>4.3 Write a function that takes an integer parameter (N) and returns a list of the first N Fibonacci numbers.You are encouraged to reuse previous functions.<jupyter_code>def get_n_fibonacci(N):
    # TODO
    
assert(get_n_fibonacci(4) == [1, 1, 2, 3])<jupyter_output><empty_output><jupyter_text>\*4.4 Write a function that takes two integers, A and B and returns B-A Fibonacci numbers starting from the Ath Fibonacci number to the (B-1)th number. See the example below.<jupyter_code>def get_range_fibonacci(A, B):
    # TODO

assert(get_range_fibonacci(2, 5) == [1, 2, 3])
assert(get_range_fibonacci(5, 5) == [])
assert(get_range_fibonacci(1, 5) == [1, 1, 2, 3])<jupyter_output><empty_output><jupyter_text>5. Default and keyword arguments 5.1 Write a function that computes the sum of a list with an optional starting value. If no starting value is provided, it should sum from 0.<jupyter_code># TODO def sum_list...

assert(sum_list([1, 2, 3]) == 6)
assert(sum_list([1, 2, 3], 5) == 11)<jupyter_output><empty_output><jupyter_text>5.2 Write a function that takes two numbers and an arithmetic operator as a string ("+", "-", "\*" or "/") and returns the result of the arithmetic operation on the two numbers. The default operation should be addition.<jupyter_code># TODO def arithmetic...

assert(arithmetic(2, 3) == 5)
assert(arithmetic(2, 3, "-") == -1)
assert(arithmetic(2, 3, "*") == 6)
assert(arithmetic(2, 3, "/") == 2/3)<jupyter_output><empty_output><jupyter_text>\*5.3 Write a function that takes three parameters. The third is a callable (function) that takes two parameters. The function should call its third parameter with the first two as parameters. If the third parameter is not specified the function should add the two arguments.This is very similar to the previous function but the third parameter is a function instead of a string.<jupyter_code># TODO def call_func(...)

def product(x, y):
    return x * y

assert(call_func(3, 4, product) == 12)
assert(call_func("foo", "bar") == "foobar")<jupyter_output><empty_output><jupyter_text>6. Extra exercises \*6.1 Create a function that take a list and a predicate (function with boolean return value) as parameters and returns a new list of those elements which the predicate return True.A predicate is a function that takes one element and return `True` or `False`, for example `is_even`, `is_prime`.If you implemented The following tests should run.<jupyter_code>def filter_list(input_list, predicate):
    # TODO
    return output_list

def is_prime(n):
    # TODO
    pass

def is_odd(n):
    return n % 2 == 1

l1 = [1, 2, 3, 4, 19, 35, 11]

assert(filter_list(l1, is_odd) == [1, 3, 19, 35, 11])
assert(filter_list(l1, is_prime) == [2, 3, 19, 11])<jupyter_output><empty_output><jupyter_text>\*6.2 Reduce is a function that applies a two argument function against an accumulator and each element in the sequence (from left to right) to reduce it to a single value. If no initial value is provided, the accumulator is initialized with the return value of the function run on the first two elements of the sequence.```reduce([1, 2, 3], product) ---> 6reduce([1, 2, 3], product, accumulator=10) ---> 60reduce(["foo", "bar"], string_addition) ---> "foobar"reduce(["foo", "bar"], string_addition, accumulator="hello") ---> "hellofoobar"```<jupyter_code>def reduce(l, acc_func, accumulator=None):
    # TODO
    
def add(x, y):
    return x + y

l1 = [1, 2, -1, 5]

assert(reduce(l1, add) == 7)
assert(reduce(l1, add, 10) == 17)
def string_len_add(acc, s):
    return acc + len(s)

l2 = ["foo", "bar", "hello"]

assert(reduce(l2, string_len_add, 0) == 11)<jupyter_output><empty_output><jupyter_text>\*6.3 Use your reduce function for the following operations:1. count the number of odd elements in a list of integers,2. find the maximum of a list of integers,3. find the longest string in list of strings.Test your solutions.  \*6.4 Implement qsort. Qsort sorts a list in place using the quicksort algorithm.<jupyter_code>def qsort(l):
    # TODO
    
l = [10, -1, 2, 11, 0]

qsort(l)

assert(l == [-1, 0, 2, 10, 11])<jupyter_output><empty_output><jupyter_text>\*6.5 Implement bubble sort (in place).<jupyter_code>def bubblesort(l):
    # TODO
    
l = [10, -1, 2, 11, 0]

bubblesort(l)

assert(l == [-1, 0, 2, 10, 11])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11244055836784783, 'fraction_numerical': 0.038502837858567264, 'mean_word_length': 4.68935427574171, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '116428', 'license': 'MIT', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2093, 'n_words': 852, 'path': 'practice/02_Python_basics_exercises.ipynb', 'repo_name': 'juditacs/bprof-python', 'size': '6519'}