int('nope') raises ValueError. Which plan catches that exception around the conversion?
- Put except ValueError before the call, without a try block
- Put the call in try, with except ValueError below it
- Put the call in try, but use except IndexError below it
The path absent.txt does not exist. Your program calls open('absent.txt', 'r'). Which exception does this missing read path cause?
- FileNotFoundError for the missing read path
- ValueError for an invalid integer conversion
- IndexError for an out-of-range list position
In a plain Python script using default error reporting, an exception that remains uncaught prints an error and stops that script.
Circle one: True False
open('roster.txt', 'r') fails because the path is absent; request another path. int('fern') fails because its text is not an integer; reject the record. Which handlers match these policies?
- FileNotFoundError requests a path; ValueError rejects the record
- ValueError requests a path; FileNotFoundError rejects the record
- FileNotFoundError handles both operations and always retries
half_positive accepts only n > 0. It receives n = -8. Which action follows the taught input-rejection policy?
- Return abs(n) / 2 as if the input were valid
- Return 0 as a default without reporting the input
- Raise ValueError to signal the unusable input
number = 7 try: number = int('bad') except: pass print(number) What is the risk of this handler?
- It replaces 7 with 0 because pass creates a default result
- It reports stale 7 without signalling the failed conversion
- It retries the conversion until valid numeric text appears
A report must use actual file contents. Reading missing.csv raises FileNotFoundError. Which policy can recover without inventing contents?
- Request another path and use contents only after a successful read
- Treat the failed read as an empty file and claim the data was read
- Use a contents variable even though this read never assigned it
A handler catches ValueError with except Exception as err, prints err, then executes bare raise. What does raise do?
- It retries the failed operation without leaving the handler
- It continues after the handler as if no error had occurred
- It propagates the current ValueError to the caller