0
0
Pythonprogramming~10 mins

Why loops are needed in Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A[1, 2]
Brange(1, 4)
C3
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single number instead of a range.
Using a list with fewer numbers than needed.
2fill in blank
medium

Complete 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'
A+=
B*=
C-=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to update the total inside the loop.
3fill in blank
hard

Fix 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'
Aletter
Bword
Cchar
Dletters
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.
4fill in blank
hard

Fill 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'
A**
B>
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of power.
Using wrong comparison operators.
5fill in blank
hard

Fill 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'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting keys to uppercase.
Using wrong comparison operator or variable names.