CMU 15-112 Fall 2015 Quiz 2 Practice: Code Tracing
(Due never)
- This is part of quiz2-practice.
- Quiz2 code tracing will be nearly identical to these.
# Code Tracing #1 of 2
def ct1(x):
counter = 0
target = 5
while (target < 7):
if ((counter % x) == (target % x)):
print(counter, target, end=" * ")
target += 1
counter += 2
return 1000*counter + target
print(ct1(3))
# Code Tracing #2 of 2
def ct2(x):
for y in range(x, 2*x, 1+x//2):
for z in range(3,4):
x += 1
if ((x + z) % 2 == 1):
print("A", x, end=" ")
for z in range(y, y-3, -2):
print("B", z, end=" ")
return y
print(ct2(4))