01. Perform Troubleshooting and Error Handling 1 Flashcards

1
Q

True or False: A Syntax error in python is similar to a grammatical or spelling error in writing.

A

True

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

Which lines of code in this example have syntax errors?

A
  1. Line 2 - The boolean false should be capitalised
  2. Line 5 - code is not indented
  3. Line 10 - elif statement is missing a colon
  4. Line 12 - print is spelt incorrectly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The following code contains a logic error. What is the issue?

A

The script is looking for “Riga” as the correct answer.

The user could enter “riga” and the script would note that as an incorrect answer.

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

Explain what is meant by the term “runtime error”.

A

These type of errors only occur when the program is run.

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

Name two common types of runtime errors.

A
  1. Trying to read a file that does not exist.
  2. Trying to divide a number by zero.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Referring to the code sample below, why would you add an else statement to a try/except block?

A

You would add an else statement after directly after the except block to print something if the try block did not raise an exception. Essentially this will mean that the code worked as expected.

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

Why would you add “finally” to a try/except block?

A

You may wish to display a final message to a user regardless of whether the try block was successful or not.

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

Referring to the code example below, what will happen if the user tries to divide a number by zero?

A

The program will raise the error, however, the program will still end without fully completing all of the print statements.

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

What keyword do we use to display an actual error message to a user?

A

The raise keyword.

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

What often causes syntax errors? Choose two answers.

Select one or more:

a. A missing colon beginning a block
b. Incorrect numbers
c. Using something where is does not fit according to the rules of writing Python
d. Coding from memory

A

a. A missing colon beginning a block
c. Using something where is does not fit according to the rules of writing Python

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

In an IDE, every syntax error is displayed with a red squiggly line beneath the flawed code.

True or false?

Select one:

True

False

A

False

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

In exception handling, the else keyword’s block of code can be used in Python to display a message of __________ to users.

a: warning
b: error unexpected
c: failure
d: success

A

d: success

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

Runtime errors occur only when an app runs, if not caught they _________ the app.

a: fix
b: crash
c: improve
d: give a warning message

A

b: crash

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

Which term describes the action of managing errors in a way that an app will not crash on a user, and if it does need to stop, a user is informed?

Select one:

a. Exception dealing
b. Exception handling
c. User benefits
d. Error management

A

b. Exception handling

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

A programmer would like to display a message to users regardless of whether the try block was successful or not. In this case, why should a finally keyword be used instead of an else keyword after the try/except block?

Select one:

a. The finally keyword is the last step in successful code
b. An else statement will not run if the try block fails
c. The else keyword can be used alone in this instance
d. A finally statement is more efficient than an else statement

A

b. An else statement will not run if the try block fails

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