Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python Assignment Expressions Code

Practice using := to capture values in conditions, loops, and expressions while keeping ordinary assignment separate.

Core ~10 min read

Challenge 1

Capture the result of word_length("python") in length and compare that value with 5.

python Your answer
def word_length(word):
    return len(word)

if :
    print(length)

Press Ctrl⌘Enter to check your answer

Challenge 2

Capture each command returned by next(commands) and keep looping until the command is "quit".

python Your answer
commands = iter(["start", "status", "quit"])

while :
    print(command)

Press Ctrl⌘Enter to check your answer

Challenge 3

Bind captured to the value 40 while also producing that value for the assignment to result.

python Your answer
result = 
print(result)
print(captured)

Press Ctrl⌘Enter to check your answer

Challenge 4

Capture each doubled value as double and keep only doubles greater than 10.

python Your answer
values = [3, 5, 8]

doubles = [double for value in values if ]
print(doubles)

Press Ctrl⌘Enter to check your answer