Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the first 5 even numbers.
Intro to Computing
for i in range(1, 11): if i [1] 2 == 0: print(i)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' instead of '%' causes a syntax or logic error.
Using '*' will multiply numbers, not check evenness.
✗ Incorrect
The % operator checks the remainder. If i % 2 == 0, then i is even.
2fill in blank
mediumComplete the code to find the sum of numbers from 1 to 5.
Intro to Computing
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 '-' will subtract instead of adding.
Using '*' or '/' will cause incorrect calculations.
✗ Incorrect
The += operator adds the right value to the variable on the left.
3fill in blank
hardFix the error in the code to print numbers from 1 to 5.
Intro to Computing
for i in [1](1, 6): print(i)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
list alone does not generate numbers.Using
str or dict causes errors in loops.✗ Incorrect
The range function generates a sequence of numbers, perfect for loops.
4fill in blank
hardFill both blanks to create a dictionary of squares for numbers 1 to 5.
Intro to Computing
squares = {x[1]2: x[2]2 for x in range(1, 6)} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' will add or subtract instead of squaring.
Using '*' will multiply by 2, not square.
✗ Incorrect
The ** operator is used for exponentiation (power) to compute squares.
5fill in blank
hardFill all three blanks to create a dictionary of uppercase words with their lengths, only for words longer than 3 letters.
Intro to Computing
result = { [1]: [2] for word in words if len(word) [3] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
word instead of word.upper() for keys.Using '<' instead of '>' causes wrong filtering.
✗ Incorrect
We use word.upper() for uppercase keys, len(word) for values, and filter words with length greater than 3 using >.