0
0
Flaskframework~10 mins

Control structures (if, for) in Flask - Interactive Code Practice

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

Complete the code to loop over the list and print each item.

Flask
items = ['apple', 'banana', 'cherry']
for [1] in items:
    print([1])
Drag options to blanks, or click blank then click option'
Ai
Bitem
Cfruit
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not consistent inside the loop.
Forgetting to use the loop variable in the print statement.
2fill in blank
medium

Complete the code to check if a user is logged in and show a welcome message.

Flask
if [1] == True:
    print('Welcome back!')
else:
    print('Please log in.')
Drag options to blanks, or click blank then click option'
Alogged_in
Buser_logged
Clogin_status
Dis_logged
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined or inconsistent.
Forgetting to compare the variable to True explicitly.
3fill in blank
hard

Fix the error in the for loop to correctly iterate over the range of numbers.

Flask
for num in range([1]):
    print(num)
Drag options to blanks, or click blank then click option'
Arange(10)
B1, 10
C0, 10
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Passing multiple arguments without unpacking.
Using range(10) inside the range function.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 letters.

Flask
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the wrong comparison operator.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words longer than 4 letters.

Flask
result = { [1]: [2] for w in words if len(w) [3] 4 }
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word as the key instead of uppercase.
Using the wrong comparison operator or value.