Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a message automatically.
Raspberry Pi
print([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the text.
✗ Incorrect
The print function needs a string inside quotes to display text.
2fill in blank
mediumComplete the code to run a task every 5 seconds.
Raspberry Pi
import time while True: print("Task running") time.[1](5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name like wait or delay.
✗ Incorrect
The time.sleep(seconds) function pauses the program for the given seconds.
3fill in blank
hardFix the error in the code to automate a task without stopping.
Raspberry Pi
count = 0 while count < 3: print("Running task", count) count [1] 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of += causes no change in count.
✗ Incorrect
The += operator adds 1 to count each loop to avoid an infinite loop.
4fill in blank
hardFill both blanks to create a dictionary of tasks that run only if active.
Raspberry Pi
tasks = {task: status for task, status in [1] if status [2] True} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'is' for boolean check.
✗ Incorrect
Use tasks.items() to get pairs and is to check if status is True.
5fill in blank
hardFill all three blanks to filter and square numbers automatically.
Raspberry Pi
result = [1]: [2]**2 for [3] in numbers if [2] % 2 == 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
✗ Incorrect
Use the same variable num for key, value, and loop variable to square even numbers.