Chapter 10: Python Debugging: Errors, DRIFT, and IDE Tools

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/53

encourage image

There's no tags or description

Looks like no tags are added yet.

54 Terms

1
New cards

What are the three main types of errors in coding?

Syntax errors, run-time errors, and logic errors.

2
New cards

What is a syntax error?

Using incorrect syntax that usually prevents the code from running.

3
New cards

How can syntax errors typically be identified?

Most code editors will catch syntax errors before the code runs.

4
New cards

What is a run-time error?

An error that occurs while the program is running, often referred to as an exception.

5
New cards

Give an example of a run-time error.

Attempting to divide by zero or accessing an index out of range in a list.

6
New cards

What is a logic error?

A mistake in how the code works that produces incorrect output despite the code running.

7
New cards

Why are logic errors considered the toughest to deal with?

They often manifest far from the actual mistake in the code.

8
New cards

What is the purpose of the try-except statement in Python?

To handle run-time errors without crashing the program.

9
New cards

What is the basic structure of a try-except statement?

try: except :

10
New cards

What happens if there is no exception in a try-except block?

The code following the try-except block executes normally.

11
New cards

What is a TypeError?

An error that occurs when trying to perform an operation on the wrong type of variable.

12
New cards

What is an IndexError?

An error that occurs when trying to access an element out of range of a list.

13
New cards

What is a ZeroDivisionError?

An error that occurs when attempting to divide by zero.

14
New cards

What is a NameError?

An error that occurs when trying to access a variable that does not exist.

15
New cards

What historical event popularized the term 'bug' in computing?

Grace Hopper found a moth causing a malfunction in the Mark II computer in 1947.

16
New cards

What is the debugging process for inexperienced programmers?

Find something that doesn't work, change something randomly, and check if it fixed the issue.

17
New cards

What is the significance of catching errors with try-except statements?

It allows recovery from errors and provides more information about what went wrong.

18
New cards

What is an example of a logic error due to a typo?

Misspelling a variable name or forgetting to indent a line of code.

19
New cards

What can cause a run-time error related to memory?

Creating an infinite loop that continuously grows a list until memory is exhausted.

20
New cards

What should you do if a run-time error occurs?

Use a try-except statement to handle the error gracefully.

21
New cards

What is the role of the 'except' clause in a try-except statement?

To define the code that runs if an exception of the specified type occurs.

22
New cards

What is a common practice when writing code to prevent crashes?

Implementing try-except statements to catch potential run-time errors.

23
New cards

What does it mean to handle bugs in programming?

Identifying and fixing problems in the code that cause incorrect behavior.

24
New cards

What is a common outcome of logic errors?

The code runs but produces incorrect or unexpected output.

25
New cards

How can better programmers differ from inexperienced ones in error handling?

They tend to make fewer errors and can find and fix errors more quickly.

26
New cards

What does the term 'exception' refer to in programming?

An error that occurs during the execution of a program.

27
New cards

What is the first step in the debugging process?

Identifying something in the code that does not work as intended.

28
New cards

What does the acronym DRIFT stand for in debugging?

Discover, Reproduce, Isolate, Fix, Test

29
New cards

What is the first step in the DRIFT debugging process?

Discover: Find a repeatable problem

30
New cards

What is the purpose of creating a test case in debugging?

To reliably reproduce the problem

31
New cards

What should you do after isolating the bug in your code?

Fix the bug and then test to ensure it is resolved

32
New cards

What is an interactive debugger?

A tool in code editors that helps you debug your code without fixing the bugs automatically

33
New cards

Name three code editors that include a debugger.

VS Code, Spyder, and PyCharm

34
New cards

What is the significance of running code in 'debug mode'?

It allows you to debug the program with additional information but runs less efficiently

35
New cards

What is a breakpoint in debugging?

A marker that pauses code execution at a specific line

36
New cards

What does the 'Step-into' function do in a debugger?

Executes the next line of code and stops inside a function if there is a function call

37
New cards

What is the Call Stack in debugging?

A list of functions that have been called, showing the order of execution

38
New cards

What is the purpose of the Variable Explorer in a debugger?

To view current variables and their values during execution

39
New cards

What should you do if you don't have a debugger available?

Use print statements to output values at various points in the code

40
New cards

What is the purpose of using assert statements in debugging?

To perform sanity checks on parts of your code, ensuring valid inputs and outputs

41
New cards

What happens if an assertion fails in Python?

An AssertionError exception is raised, stopping the program

42
New cards

How can talking to a duck help in debugging?

Explaining your program line-by-line can help identify discrepancies in expected behavior

43
New cards

What is the final step in the DRIFT process?

Consider whether the same error might occur elsewhere and fix it if necessary

44
New cards

How can debugging principles apply outside of programming?

They can be used to systematically solve problems in other areas, like mechanical issues

45
New cards

What is the importance of testing after fixing a bug?

To ensure the bug is resolved and that no other parts of the code were broken

46
New cards

What does the 'Continue/Run' function do in a debugger?

Runs the code until a breakpoint is encountered

47
New cards

What is the difference between 'Step' and 'Step-over' in debugging?

'Step' executes the next line, while 'Step-over' executes the next line and returns normally if it's a function call

48
New cards

What does it mean to isolate a bug?

To narrow down the location in the code where the issue is occurring

49
New cards

What is a common practice to identify where a bug is occurring?

Setting breakpoints close to where you suspect the issue lies

50
New cards

What should you do if you find a line of code causing difficulty?

Step into the line(s) of code to investigate further

51
New cards

What is the significance of confirming user input in a program?

To ensure that the data being processed is valid and expected

52
New cards

What is the role of interpolation in debugging physical properties?

To estimate values between known data points

53
New cards

What is a common debugging task flow in programming?

Read in data, perform calculations, and display results

54
New cards

What should you consider after fixing a bug?

Whether similar issues might exist in other parts of the code