<jupyter_start><jupyter_text>Chapter 4 Exercises  Exercise 1<jupyter_code># Part I
x_vals = (1,2,3)
y_vals = (4,5,6)
cul = 0
for x, y in zip(x_vals,y_vals):
    cul = cul + x * y
print(cul)
# Part II
len([x for x in range(100) if x % 2 == 0])
# Part III
pairs = ((2,5),(4,2),(9,8),(12,10))
sum([x % 2 == 0 and y % 2 == 0 for x, y in pairs])<jupyter_output><empty_output><jupyter_text>Exercise 2<jupyter_code>def p(x, coeff):
    value = 0
    i = 0
    for a in coeff:
        point = a * (x**i)
        i = i + 1
        value = value + point
    return value
p(2,[1,2,3])
# enumerate()
def p(x, coeff):
    return sum(a * x ** i for i, a in enumerate(coeff))
p(2,[1,2,3])
c = [1,2,3]
for i, a in enumerate(c):
    print(i,a)<jupyter_output>0 1
1 2
2 3<jupyter_text>Exercise 3<jupyter_code>def function3(str_arg):
    number = 0
    bignumber = str_arg.upper()
    for i, z in zip(str_arg, bignumber):
        if i == z:
            number = number + 1
    return number

function3('AbCbCC')<jupyter_output><empty_output><jupyter_text>Exercise 4<jupyter_code>def function4(seq_a, seq_b):
    for i in seq_a:
        if not(i in seq_b):
            return False
        else:
            return True
function4('1','123')<jupyter_output><empty_output><jupyter_text>Exercise 5<jupyter_code>def linapprox(f, a, b, n, x):
    length_of_interval = b - a
    num_subintervals = n - 1
    step = length_of_interval / num_subintervals
    point = a
    while point <= x:
        point += step
    u, v = point - step, point

    return f(u) + (x - u) * (f(v) - f(u)) / (v - u)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14956195244055068, 'fraction_numerical': 0.039424280350438046, 'mean_word_length': 2.9776119402985075, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '579215', 'license': 'MIT', 'n_tokens_mistral': 703, 'n_tokens_neox': 665, 'n_words': 173, 'path': '0. quant_econ_with_py_codes/0. Basic Knowledge of Economic with Python/Chapter4_Codes/Ch4_Exercises.ipynb', 'repo_name': 'Matrix-JCG/quant_econ_with_python', 'size': '1598'}