0% found this document useful (0 votes)
95 views5 pages

Simple Code Tracing Practice

The document contains 4 coding tasks (CT) with functions and print statements: 1. CT1 defines a function ct1 that performs math operations on its arguments and returns a value. 2. CT2 defines a function ct2 that prints a value but does not return anything. 3. CT3 defines functions f and ct3, with ct3 calling f and performing division operations on its arguments. 4. CT4 defines a function h used by ct4, which defines variables, calls h, and prints a final value.

Uploaded by

julia.garland157
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views5 pages

Simple Code Tracing Practice

The document contains 4 coding tasks (CT) with functions and print statements: 1. CT1 defines a function ct1 that performs math operations on its arguments and returns a value. 2. CT2 defines a function ct2 that prints a value but does not return anything. 3. CT3 defines functions f and ct3, with ct3 calling f and performing division operations on its arguments. 4. CT4 defines a function h used by ct4, which defines variables, calls h, and prints a final value.

Uploaded by

julia.garland157
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CT 1 of 4:

- print(ct1(5, 3, 2))
- print(ct1(5, 4, 2))

def ct1(x, y, z):


x *= z
z = y ** z
return (10 * y + z) % x

print(ct1(4, 3, 2))

CT 2 of 4:

def ct2():
print(42, end='')
# no return statement!

print(ct2())

CT 3 of 4:
- print(ct3(9, 3))
- print(ct3(4, 3))

# f(x,y) is used by ct3

def f(x, y):


y += 1
return x - x // y

def ct3(x, y):


x = f(x, y - 1)
return x / (y - 1)

print(ct3(7, 3))

CT 4 of 4:
# h(x,y) is used by ct4

def h(x, y):


if (x > y):
if (x > 2 * y):
return 3
elif (x < 2 * y):
return 5
else:
return 7
return 9

def ct4():
w = h(8, 4)
x = h(4, 8)
y = h(8, 3)
z = w + 10 * x + 100 * y
print(z)

ct4()
def ct2(x, y, z):

print(x/y + x//y + int(x/y)) print(y**z + y%z)

a = int(x) / int(y)

return isinstance(a, int)

print(ct2(6, 4, 3))

def ct1(x):
print(x + 10)

x = x + 25 // 10
print(x)
x -= 3
print(x)

return x == 0
ct1(10)
def ct1(x, y):

print((x//10) % ((y%10)**3)) if (x > y):

return isinstance(x/10, type(x))

print(ct1(137,42))
print(ct1(42, 731))

def f(z):
return 2*z

def g(z):
z += 1

return z/2

def h(z):
if (z > 3):
return z + f(g(z))
else:
return g(z)

def ct2(z):
print(h(z-1))

z *= 2
return h(z)

print(ct2(3)

You might also like