Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 12.0 ** 10000 | AA float calculation that is too big for a float to hold, so Python raises an OverflowError | |
| 2except OverflowError: | Bif power <= 1000: result = 2.0 ** power | |
| 3Guard against overflow by checking the size of the exponent before doing the calculation | CThere is no check or try/except, so the overflow stops the program with an OverflowError. Guard the value or wrap the calculation in try/except. | |
| 4Fixed-size integers in languages like Java or C overflow by wrapping around once they pass their maximum value | Dint big = 2147483647 + 1; | |
| 5result = 2.0 ** 10000 print(result) | EThe wrong error type is caught. An overflow raises OverflowError, not ValueError, so the program still crashes. Use except OverflowError. | |
| 6try: x = 2.0 ** 10000 except ValueError: | FCatches the error raised when a calculation result is too big for its data type |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
OverflowError — An error raised when a calculation gives a number too big for its data type to hold, such as a Python float going past its maximum, e.g. 2.0 ** 10000.try:
x = 2.0 ** 10000
except OverflowError:print(2.0 ** 10000)try:
big = 10.0 ** 400
except OverflowError:if exponent > 1000:
print("Exponent too big")raise OverflowError("Value too big")