Complete the code to print the error message when an exception occurs.
try: result = 10 / 0 except ZeroDivisionError as [1]: print([1])
In Python, the common variable name to catch an exception is e. This variable holds the error message.
Complete the code to check if a number is positive and print a message.
number = -5 if number [1] 0: print("Positive number") else: print("Not positive")
The condition number > 0 checks if the number is positive.
Fix the error in the code to correctly access the first element of the list.
my_list = [10, 20, 30] first_element = my_list[1]
In Python, list elements are accessed using square brackets [] with the index inside.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
{word: [1] for word in words if [2]The dictionary comprehension maps each word to its length using len(word). The condition len(word) > 3 filters words longer than 3 characters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 2.
{ [1]: [2] for word in words if [3] }word.lower() instead of uppercase.The comprehension maps the uppercase version of each word (word.upper()) to its length (len(word)) only if the length is greater than 2 (len(word) > 2).