-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment_11.py
More file actions
59 lines (42 loc) · 2.5 KB
/
Copy pathAssignment_11.py
File metadata and controls
59 lines (42 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1. To create an assert statement that throws an AssertionError if the variable `spam` is a negative integer:
```python
assert spam >= 0, "spam must be a non-negative integer"
```
2. To write an assert statement that triggers an AssertionError if the variables `eggs` and `bacon` contain strings that are the same as each other, even if their cases are different:
```python
assert eggs.lower() != bacon.lower(), "eggs and bacon must be different strings"
```
3. To create an assert statement that throws an AssertionError every time:
```python
assert False, "This assert statement always raises an AssertionError"
```
4. The two lines that must be present in your software to call `logging.debug()` are:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```
5. The two lines that your program must have in order to have `logging.debug()` send a logging message to a file named `programLog.txt` are:
```python
import logging
logging.basicConfig(filename='programLog.txt', level=logging.DEBUG)
```
6. The five levels of logging are:
- `logging.DEBUG`
- `logging.INFO`
- `logging.WARNING`
- `logging.ERROR`
- `logging.CRITICAL`
7. To disable all logging messages, you would add the following line of code:
```python
logging.basicConfig(level=logging.CRITICAL)
```
8. Using logging messages is better than using `print()` to display the same message because:
- Logging messages can be configured to different levels, allowing you to control the verbosity of the output.
- Logging messages can be easily disabled or redirected to a file, whereas `print()` statements are more difficult to manage.
- Logging messages provide more context, such as the file, line number, and function where the message was generated.
9. The differences between the Step Over, Step In, and Step Out buttons in the debugger are:
- Step Over: Executes the current line of code and moves to the next line, without stepping into any function calls.
- Step In: Executes the current line of code and moves into any function calls.
- Step Out: Executes the remaining lines of the current function and returns to the caller.
10. After you click the Continue button, the debugger will stop when it encounters the next breakpoint, an exception is raised, or the program completes.
11. The concept of a breakpoint is a point in your code where the debugger will pause the execution of your program, allowing you to inspect variables, step through the code, and debug your application.