1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is a SyntaxError?
A SyntaxError occurs when Python cannot understand the code because it violates Python's syntax rules.
What is the easiest way to remember SyntaxError?
Think: "Python can't understand how I wrote the code."
What is a common SyntaxError in an if statement?
Forgetting the colon after the condition. Example: if x > 5 instead of if x > 5:.
What error occurs if you write if x = 5:?
SyntaxError. Use == to compare values: if x == 5:.
What error can occur if you use invalid Python syntax?
SyntaxError.
What is a NameError?
A NameError occurs when Python tries to use a name or variable that has not been defined.
What is the easiest way to remember NameError?
Think: "Python doesn't know this name."
What happens if you print a variable before assigning it?
Python raises a NameError because the variable has not been defined yet.
What happens if you misspell a variable name?
A NameError can occur if the misspelled name has not been defined.
Are Python variable names case-sensitive?
Yes. x and X are different variable names.
What happens with x = 10 followed by print(X)?
NameError, because X and x are different names and X was never defined.
What is a TypeError?
A TypeError occurs when an operation is performed using an inappropriate type.
What is the easiest way to remember TypeError?
Think: "I'm using the wrong type."
What happens when you try "hello" + 5?
TypeError. Python cannot directly concatenate a string and an integer using +.
What is a ValueError?
A ValueError occurs when a function receives a value that is inappropriate even though the value has an acceptable general type.
What is the easiest way to remember ValueError?
Think: "The type is okay, but the value is not."
What happens when int("hello") is executed?
ValueError, because "hello" cannot be converted into an integer.
What is an IndentationError?
An IndentationError occurs when Python's indentation is incorrect.
Why is indentation especially important in Python?
Indentation determines code blocks, such as the statements inside if, elif, else, while, and for.
What can happen if you forget to indent the body of an if statement?
Python can raise an IndentationError because the statements belonging to the if block must be indented.
What is a ZeroDivisionError?
A ZeroDivisionError occurs when a program attempts to divide by zero.
What happens when 10 / 0 is executed?
ZeroDivisionError.
What happens when 10 // 0 is executed?
ZeroDivisionError.
What happens when 10 % 0 is executed?
ZeroDivisionError.
What is a logical error?
A logical error occurs when the code runs but produces an incorrect result because the programmer's logic is wrong.
What is the easiest way to remember a logical error?
Think: "Python runs it, but I got the wrong answer."
What is an example of a logical error in a conditional?
Using > when the problem requires <, causing the program to choose the wrong branch.
What is an off-by-one error?
A logical error where a loop runs one time too many or one time too few.
What commonly causes an off-by-one error in range()?
Forgetting that range() excludes its stop value.
What is an infinite loop?
A loop that continues indefinitely because its condition never becomes false or because the loop is otherwise never stopped.
Is an infinite loop necessarily a SyntaxError?
No. An infinite loop can be a logical error because the code can be valid Python but never terminate.
What commonly causes an infinite while loop?
Failing to update the variable that controls the while condition so the condition never becomes false.
What is the difference between SyntaxError and NameError?
SyntaxError means Python cannot understand the code's syntax; NameError means Python cannot find a defined name or variable.
What is the difference between NameError and TypeError?
NameError means a name has not been defined; TypeError means an operation is being performed with an inappropriate type.
What is the difference between TypeError and ValueError?
TypeError means the type is inappropriate; ValueError means the type is acceptable but the value itself is inappropriate.
What is the difference between a Python error and a logical error?
A Python error such as SyntaxError or TypeError causes Python to report a problem, while a logical error can allow the program to run while producing the wrong result.
What should you do when you see an error in a quiz code-tracing question?
Find the line causing the problem, identify what Python rule was violated, and determine the error type.
Which error means Python cannot understand the way the code is written?
SyntaxError.
Which error means a variable or name has not been defined?
NameError.
Which error means an inappropriate type was used?
TypeError.
Which error means an inappropriate value was used even though the type is acceptable?
ValueError.
Which error means the indentation is incorrect?
IndentationError.
Which error means the program attempted to divide by zero?
ZeroDivisionError.
Which error means the program runs but gives the wrong result because the logic is incorrect?
Logical error.
What are the seven error concepts most important to know for these Gateway Python topics?
SyntaxError, NameError, TypeError, ValueError, IndentationError, ZeroDivisionError, and logical errors.