Topic 5 - Session 5 - MTA Intro Course Flashcards

1
Q

What statements are used in python to handle errors?

A

Try and except statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What except block can be used to perform input validation to ensure a user enters a numerical value?

A

except ValueError:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Spelling or grammatical errors are known as what in programming?

A

Syntax errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain what a runtime error is in Python

A

A runtime error occurs when Python understands the code, but runs into an error when trying to follow the instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Provide two examples of a runtime error in python.

A
  1. ) Python will run into a runtime error if it tries to access a file which does not exist.
  2. ) If you try to divide by zero without coding for any input validation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When using a try/except block, what code is used if you want to display a successful message?

A

You use an else statement. It comes after the except statement.

try:
   print("something")
except:
   print("something again")
else:
   print("Success")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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?

A

Use the word “finally”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What keyword in code is used to display an error message that the exception caused?

A

Use the keyword “raise”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the toughest type of error to identify?

A

Logic errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Provide an example of a logic error?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly