"""
Examples
"""

"""
Local vs. global variables:
What is the output of the code?
"""

# Part 1
def f_sum(a):
    b = 99
    return a + b

a = 1
b = 100
c = -55
print(a, b, c)
print(f_sum(c), a, b, c)

# Output:
# 1 100 -55
# 44 1 100 -55

# Part 2
def f_sub(a):
    global b
    a += 1
    return a - b

a = 1
b = 100

print(a, b)
print(f_sub(a), a, b)

# Output:
# -98 1 100

"""
Local vs. global variables:
What if arguments are lists/sets/dictionaries?
"""


def f_extender(my_list, factor):
    my_list *= factor


numbers = ['N', 0, 'v']

f_extender(numbers, 2)
print(numbers)

f_extender(numbers, 2)
print(numbers)

"""
Recursive function to calculate the sum of elements in list 'a' from index 'b' down to index 3
"""


def f(a, b):
    # Base case: if 'b' is less than 3, stop the recursion and return 0
    if b < 3:
        return 0
    # Recursive step: add the element at index 'b' to the result of calling 'f' with 'b-1'
    res = a[b] + f(a, b - 1)
    return res


# Example list of integers
s = [2, 7, 1, 4, 6, 9, 4, 3, 0, 0]

# Call the function 'f' starting from index 8 and print the result
print(f(s, 8))
# Answer: 26
