<jupyter_start><jupyter_text>Test Your KnowledgeIn the blocks below you will find a range of questions that cover the material we've looked at in the previous notebooks. Make sure you can do these tasks before you move on to the next topic, which will cover modules and functions in Python.  1) Take a look at the built-in `round` and `sorted` functions in the Python documentation. Use them, with any other functions you think might be useful, to convert the unsorted list of floats into a sorted list of floats that are all rounded to 2 decimal places.<jupyter_code>L = [3.765, 2.094, -5.092, -2.43, 2.51, 1.02]
for i in sorted(L, reverse=False):
    answer=round(i,2)
    print(answer)<jupyter_output>-5.09
-2.43
1.02
2.09
2.51
3.77<jupyter_text>2) Define your own function that calculates and returns the value of the expression a*b+c for three variables `a`,`b`, and `c`.<jupyter_code>def function(a,b,c):
    print(a*b/c)

function(2,3,5)<jupyter_output>1.2<jupyter_text>3) Define your own function that will print out all prime numbers between 3 and an input `p`. It will probably be helpful to reuse a significant portion of code you developed for a similar question in the previous topic.<jupyter_code>def primefinder(p):
    if p<2:
        print('you put a wrong number')
    elif p<=3:
        print(p)
    else:
        for i in range(3,p+1):
            for j in range(2,i):
                if i%j==0:
                    break
            else:
                print(i)
primefinder(105)<jupyter_output>3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103<jupyter_text>4) Using the square root function of the math module, write a function to calculate and return the hypotenuse of a right angled triangle, where the lengths of the other two sides of the triangle are the inputs to the function.<jupyter_code>import math
def hypotenuse(a,b):
    hypo=math.sqrt((a**2+b**2))
    return hypo

hypotenuse(3,4)<jupyter_output><empty_output><jupyter_text>5) Write a function that calculates the volume of a cylinder, where the diameter and length are the inputs to the function. Compare how the solution varies when using the built-in value of pi from the math module compared to using approximations for pi that you store in a variable yourself.<jupyter_code>def volume(d,l):
    v=d/2**2*math.pi*l
    return v
volume(3,1)<jupyter_output><empty_output><jupyter_text>6) Generate a list of random integers using the random module. Write a function that takes this list of random integers and returns both the mean and median values. You may find some of the built-in Python functions useful to you again.<jupyter_code>import random
import statistics as st
ran=[random.randint(1,100) for iter in range(10)]
def meanmedian():
    return print(st.mean(ran),st.median(ran))
meanmedian()<jupyter_output>54 54.5<jupyter_text>7) Implement a function called `coinToss`. The function should take a variable `n` as input, which represents the number of times to flip a coin. The function should return the number of heads, the number of tails, and the length of the longest streak of the same result. You should use a random number generator to implement your coin.E.g. If the input was 15 and sequence of coin flips was HHTHTTHTTHHHTTH then we should return 8,7,3 as we flipped 8 heads, 7 tails, and there was a longest streak of 3 heads in a row.<jupyter_code>def coinToss(n):
    coinface=['H','T']
    samples = [random.choice(coinface) for times in range(n)]
    heads = samples.count('H')
    tails = samples.count('T')
    numbers=list(range(n-1))
    for num in numbers:
        if samples[num+1]==samples[num]:
            count+=1
        else:
            count=1
coinToss(15)<jupyter_output><empty_output><jupyter_text>8) Using the copy module, make a copy of the list L. Change some values in your new list, and print both lists out to ensure they are both different.<jupyter_code>L = [2,4,6,8,10,9,7,5,3,1]

import copy
L1=copy.copy(L)
L1[0]=4;L1[5]=15
print(L1)<jupyter_output>[4, 4, 6, 8, 10, 15, 7, 5, 3, 1]
{'fraction_non_alphanumeric': 0.08673091178650852, 'fraction_numerical': 0.04447739065974796, 'mean_word_length': 3.954712362301102, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 28, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '588541', 'license': 'Apache-2.0', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1278, 'n_words': 545, 'path': '4.3 - Test Your Knowledge.ipynb', 'repo_name': 'KaiyeYang-git/Introduction-to-Computer-Science', 'size': '4047'}