1) Given this function:
y = x % 3
if y == 0:
a) What is the name of the function?
b) How many arguments does this function take?
c) What does this function return?
d) Explain what this function does:
e) What would happen if a program called aFunction(4)?
2) Given this while loop:
while x < a:
a = a + 1
x = x + 2
a) If a is 3 and x is 0, what will the output of this loop be?
b) What are two values for a and x such that the code inside the loop will not execute at all?
3) Given a program:
def aFunction(x, z):
r = ""
while z > 0:
r += " " + x
z -= 1
q = aFunction("ABC", 3)
a) What is the type of the value stored in q after the line q = aFunction("ABC", 3)?
b) What is the value stored in q after the line q = aFunction("ABC", 3)?
4) This function is supposed to print all the even numbers that are less than q. However, when q is even it prints the wrong numbers and when q is odd it prints nothing at all! What is wrong with this function?
p = q
while q > 1:
if p % 2 == 0:
q = q - 1
5) Write pseudocode for a function that takes two strings as input and returns the number of words they have in common: