BRANCHING & BOOLEAN LOGIC
LOOPS & COUNTING
LIST BUSINESS
STRING THEORY
FUNCTION JUNCTION
100

This Python keyword begins a conditional statement.  

What is "if"?

100

These are the four numbers generated by range(4), in order.

What are 0, 1, 2, and 3?

100

This is the index of the first element in a Python list.

What is 0?

100

This character is printed by the following code:

word = "python"
print(word[0])

What is "p"?

100

This Python keyword is used to define a function.

What is "def"?

200

This is the text printed by the following code:

x = 5
if x >= 5:
    print("Yes")
else:
    print("No")

What is "Yes"?

200

These three numbers are printed, in order, by the following loop:

for i in range(2, 7, 2):
    print(i)

What are 2, 4, and 6?

Each prints on its own line.

200

This is the number printed by the following code:

numbers = [2, 4, 6]
numbers.append(8)
print(len(numbers))

What is 4?

200

This is the value returned by len("crow").

What is 4?

200

This Python keyword sends a value back to the code that called a function, rather than merely displaying it.

What is "return"?

300

This is the Boolean value of the following expression:

not (True and False)

What is True?

300

This is the final value printed by the following code:

total = 0
for i in range(1, 5):
    total += i
print(total)

What is 10?

300

This is the list printed by the following code:

nums = [3, 5, 7]
nums[1] = nums[0] + nums[2]
print(nums)

What is [3, 10, 7]?

300

This text is printed by the following code:

word = "PyThOn"
print(word.lower())

What is "python"?

300

This is the number printed by the following function calls:

def square(n):
    return n * n

print(square(3) + square(2))

What is 13?

400

This is the letter printed by the following code:

x = 9
if x % 3 == 0 and x % 2 != 0:
    print("A")
else:
    print("B")

What is "A"?

400

This is the value printed after the following while loop finishes:

n = 1
while n < 10:
    n *= 2
print(n)

What is 16?

400

This is the list produced after the following loop runs:

nums = [1, 2, 3, 4, 5]
selected = []
for x in nums:
    if x % 2 == 1:
        selected.append(x * x)
print(selected)

What is [1, 9, 25]?

400

This number is printed after counting the letter A without distinguishing uppercase from lowercase:

word = "Banana"
count = 0
for letter in word:
    if letter.lower() == "a":
        count += 1
print(count)

What is 3?

400

This is the list printed by the following function call:

def keep_even(nums):
    result = []
    for n in nums:
        if n % 2 == 0:
            result.append(n)
    return result

print(keep_even([7, 2, 4, 9]))

What is [2, 4]?

500

This is the word printed by the following nested conditional:

temperature = 18
raining = True

if temperature < 10:
    print("Coat")
elif raining:
    if temperature >= 15:
        print("Umbrella")
    else:
        print("Jacket")
else:
    print("Walk")

What is "Umbrella"?

500

This is the number of times count is increased, and the final value printed by these nested loops:

count = 0
for i in range(4):
    for j in range(i):
        count += 1
print(count)

What is 6?

The inner loop runs 0 + 1 + 2 + 3 times.

500

This is the final list printed by the following code, which processes repeated values in their original order:

values = [2, 3, 2, 5, 3, 2]
result = []
for x in values:
    if x not in result:
        result.append(x)
print(result)

What is [2, 3, 5]?

500

This string is printed when the code keeps only the first character of each consecutive run of identical characters:

text = "aabcccaa"
result = ""
for i in range(len(text)):
    if i == 0 or text[i] != text[i - 1]:
        result += text[i]
print(result)

What is "abca"?

500

This number is printed by a function that counts places where an element is greater than the one immediately before it:

def mystery(nums):
    result = 0
    for i in range(1, len(nums)):
        if nums[i] > nums[i - 1]:
            result += 1
    return result

print(mystery([2, 5, 4, 4, 9, 1]))

What is 2?

M
e
n
u