Topic 5 - Session 5 - MTA Intro Course Flashcards
What statements are used in python to handle errors?
Try and except statements
What except block can be used to perform input validation to ensure a user enters a numerical value?
except ValueError:
Spelling or grammatical errors are known as what in programming?
Syntax errors
Explain what a runtime error is in Python
A runtime error occurs when Python understands the code, but runs into an error when trying to follow the instructions.
Provide two examples of a runtime error in python.
- ) Python will run into a runtime error if it tries to access a file which does not exist.
- ) If you try to divide by zero without coding for any input validation.
When using a try/except block, what code is used if you want to display a successful message?
You use an else statement. It comes after the except statement.
try: print("something") except: print("something again") else: print("Success")
When using a try/except block, what code is used to display a message to the user regardless as to whether the code worked or not?
Use the word “finally”
What keyword in code is used to display an error message that the exception caused?
Use the keyword “raise”
What are the toughest type of error to identify?
Logic errors.
Provide an example of a logic error?
A logic error may be caused when no input validation is performed.
Example, a program is looking for a specific input such as “Dublin”, but the user enters “dublin” instead.