Complete the code to loop over the list and print each item.
items = ['apple', 'banana', 'cherry'] for [1] in items: print([1])
The variable item is used to represent each element in the list during the loop.
Complete the code to check if a user is logged in and show a welcome message.
if [1] == True: print('Welcome back!') else: print('Please log in.')
The variable logged_in is commonly used to check if the user is logged in.
Fix the error in the for loop to correctly iterate over the range of numbers.
for num in range([1]): print(num)
range(10) inside the range function.The range function needs a single integer to define the stop value. Using 10 iterates from 0 to 9.
Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 letters.
lengths = {word: [1] for word in words if len(word) [2] 3}The dictionary maps each word to its length using len(word). The condition filters words longer than 3 letters using >.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words longer than 4 letters.
result = { [1]: [2] for w in words if len(w) [3] 4 }The key is the uppercase word using w.upper(). The value is the length len(w). The condition filters words longer than 4 letters using >.