Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 3 using a loop.
Python
for i in [1]: print(i)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single number instead of a range.
Using a list with fewer numbers than needed.
✗ Incorrect
The range(1, 4) function creates numbers 1, 2, 3 for the loop to print.
2fill in blank
mediumComplete the code to calculate the sum of numbers from 1 to 5.
Python
total = 0 for num in range(1, 6): total [1] num print(total)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to update the total inside the loop.
✗ Incorrect
The += operator adds each number to the total, accumulating the sum.
3fill in blank
hardFix the error in the code to print each character in the word.
Python
word = 'hello' for [1] in word: print(letter)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name in the loop and print.
Using the whole word instead of a single character.
✗ Incorrect
The loop variable should be letter to match the print statement.
4fill in blank
hardFill both blanks to create a dictionary of squares for numbers 1 to 4.
Python
squares = {x: x[1]2 for x in range(1, 5) if x [2] 3}
print(squares) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of power.
Using wrong comparison operators.
✗ Incorrect
** is used for power, and < filters numbers less than 3.
5fill in blank
hardFill all three blanks to create a dictionary of uppercase keys and values greater than 1.
Python
result = [1]: [2] for k, v in data.items() if v [3] 1} print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting keys to uppercase.
Using wrong comparison operator or variable names.
✗ Incorrect
Keys are converted to uppercase with k.upper(), values are v, and filtered with > 1.