Complete the code to print the length of the string.
word = "hello" print(len([1]))
len(word) inside len() causing an error.The len() function needs the variable word to get the string length.
Complete the code to check if the letter 'a' is in the string.
text = "apple" if [1] in text: print("Found a")
To check membership, the letter must be a string literal like "a".
Fix the error in the code to check if 'x' is not in the string.
my_str = "example" if 'x' [1] my_str: print("No x found")
not without in.!= which compares equality, not membership.The correct syntax to check if a character is not in a string is not in.
Fill both blanks to create a dictionary of words with length greater than 3.
words = ["cat", "lion", "dog", "tiger"] lengths = {word: [1] for word in words if len(word) [2] 3}
The dictionary maps each word to its length, but only if the length is greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values longer than 4.
words = ["apple", "pear", "banana", "kiwi"] result = [1]: [2] for w in words if len(w) [3] 4}
The dictionary uses uppercase words as keys and original words as values, filtering words longer than 4.
