Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.3 KB

be-a-computer.md

File metadata and controls

62 lines (43 loc) · 1.3 KB

Be-a-Computer: Programming Basics

In the following exercises, you will be shown a piece of code, and will have to figure out what it does (without running it yourself in the Python interpreter)

Exercise #1

What is the value of w after evaluating the following code?

x = 7
y = 5.0
z = 10.0
w = x % 2 + y / z + z + y / (z + z)

Exercise #2

What is the value of c after evaluating the following code?

c = True
d = False
c = c and d
c = not c or d

Exercise #3

What is the output generated by the following program?

d = 0
for p in range(0, 5):
    if p % 4 == 0:
        d = d + (p-1) * 25;
    else:
        d = d + 100;
print("$" + str(d//100) + "." + str(d % 100))

Exercise #4

What is the output of the following code?

def F1(i, j) :
    print(f"F1({i}, {j})")
    F2(j, i+j)
    print(f"F1: i = {i}, j = {j}")
    

def F2(i, j) :
    print(f"    F2({i}, {j})".format(i, j))
    k = F3(i, j)
    print(f"    F2: i = {i}, j = {j}, k = {k}")
    

def F3(i, j) :
    print(f"        F3({i}, {j})".format(i, j))
    i = i+j
    j = i+2*j
    k = 2*i+3*j
    print(f"        F3: i = {i}, j = {j}, k = {k}")
    return k
    

print("Result:")
F1(1, 1)
print()