Complete the code to raise a new exception while preserving the original one.
try: x = 1 / 0 except ZeroDivisionError as e: raise ValueError('Invalid value') from [1]
The from e syntax preserves the original exception e when raising a new one.
Complete the code to suppress the original exception when raising a new one.
try: int('abc') except ValueError: raise RuntimeError('Conversion failed') from [1]
Using from None disables exception chaining and hides the original exception.
Fix the error in the code to correctly chain exceptions.
try: open('missing.txt') except FileNotFoundError as err: raise Exception('File error') from [1]
The variable err holds the original exception and should be used after from to chain exceptions.
Fill both blanks to create a dictionary of word lengths, filtering words longer than 3 characters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if [2]
The dictionary maps each word to its length using len(word). The filter keeps words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }The dictionary comprehension uses uppercase keys with k.upper(), values v, and filters values greater than zero.