| ZeroDivisionError | print(12 / 0) | ZeroDivisionError: division by zero |
| Example: A / whose right side is 0, here or after a count that stayed at 0. |
| ZeroDivisionError | print(12 // 0) | ZeroDivisionError: integer division or modulo by zero |
| Example: The same error with // or %, worded differently: 12 // 5 gives 2, 12 // 0 has no value. |
| ValueError | print(int("ten")) | ValueError: invalid literal for int() with base 10: 'ten' |
| Example: Right type, a string, wrong value: int('10') gives 10, int('ten') has letters. |
| ValueError | print(float("4,5")) | ValueError: could not convert string to float: '4,5' |
| Example: A comma typed as the decimal mark: float('4.5') gives 4.5. |
| ValueError | import math ; print(math.sqrt(-4)) | ValueError: math domain error |
| Example: math.sqrt(4) gives 2.0; math.sqrt(-4) has no real value, and it is a ValueError too, like a typing error. |
| TypeError | print("Score: " + 85) | TypeError: can only concatenate str (not "int") to str |
| Example: A string and a number joined by +: print('Score:', 85) prints Score: 85 with no error. |
| TypeError | print("30" > 25) | TypeError: '>' not supported between instances of 'str' and 'int' |
| Example: A value from input() never converted: once converted, int('30') > 25 is True. |
| NameError | total = 5 ; print(totl) | NameError: name 'totl' is not defined. Did you mean: 'total'? |
| Example: A misspelled name: print(total) prints 5, totl was never assigned. |
| IndexError | print([4, 8, 1][3]) | IndexError: list index out of range |
| Example: [4, 8, 1] has 3 cells, indices 0 to 2: [4, 8, 1][2] is 1, index 3 does not exist. |
| SyntaxError | x = 5 ; if x > 3 ; print(x) | SyntaxError: expected ':' |
| Example: Found before the run: no line runs, not even line 1. |
| none: logic error | average = a + b / 2 | no message at all no message |
| Example: With a = 70 and b = 90, it prints 115.0 and stops normally. Same form, other result: With a = 0 and b = 0, the same line prints 0.0, the right average: one passing test proves nothing. What to do: Compute the expected outcome by hand, (70 + 90) / 2 = 80.0, and compare: the test fails. |