when the code itself has "wrong grammer" or is spelled incorrectly. Most times, the code will not run at all. Usually the interpreter/IDE will catch this.
2
New cards
syntax error. While is not spelled correctly
whil x > 3:
3
New cards
syntax error. used assignment (=) instead of a relational operator (==)
if x = 2:
4
New cards
run-time error. there is no parameter when the function is called
def dosomething(x): .... dosomething()
5
New cards
run-time errors
an error that only occurs when the program runs Sometimes you can write a program that uses up too much memory Sometimes you can write a program that makes too many nested function calls
6
New cards
run-time error
answer = int(input('Enter a number: ')) (the user enters a float)
7
New cards
the code runs!
answer = int(float(input('Enter a number: '))) (the user enters a float)
8
New cards
the code runs!
answer = int(float(input('Enter a number: '))) (the user enters an integer)
9
New cards
run-time error
my_list = [3, 6, 1] a = my_list[20]
10
New cards
run-time error
b = 0 a = 5 c = a / b
11
New cards
run-time error. This goes on forever and eventually uses too much memory
L = [1] while True: L += [1]
12
New cards
logic errors
a mistake in how the code works. Code "runs" but produces the wrong output. examples: forgetting to indent misspelling a variable name typing the wrong variable name
13
New cards
try-except statements
used to prevent run-time errors from occurring, especially when the run-time error is a result of the user inputting incorrect data
14
New cards
TypeError
trying to perform an operation on the wrong type of variable (adding int to str)
15
New cards
IndexError
trying to access an element out of range of a list