Skip to content

Commit e47fc25

Browse files
authored
small changes to exceptions section
1 parent c4c6693 commit e47fc25

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

week6/w6.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# **xSoc Python Course** - Week 6\n",
88
"\n",
9-
"### *Efficiency, Compactness, Readability*\n",
9+
"### *Exceptions, Efficiency, Compactness & Readability*\n",
1010
"\n",
1111
"🖋️ *Written by Alia & Keegan from the [Computing Society](https://go.uwcs.uk/links)*"
1212
]
@@ -43,9 +43,9 @@
4343
"cell_type": "markdown",
4444
"metadata": {},
4545
"source": [
46-
"Seems fine? But what if the user decides they *don't* want to enter a number, what if, e.g., they enter \"Hello\"? Python doesn't know how to convert a string to an integer, so it will throw a **ValueError** and exit the program.\n",
46+
"Seems fine? But what if the user decides they *don't* want to enter a number, what if, e.g., they enter \"Hello\"? Python doesn't know how to convert a string to an integer, so it will throw a `ValueError` and exit the program.\n",
4747
"\n",
48-
"In reality, entering the wrong type of data isn't the end of the world. To stop Python from exiting immeadiately, we can surround any potentially problem-causing code in a `try-expect` block like this:"
48+
"In reality, entering the wrong type of data isn't the end of the world. To stop Python from exiting immediately, we can surround any potentially problem-causing code in a `try-except` block like this:"
4949
]
5050
},
5151
{
@@ -66,7 +66,7 @@
6666
"cell_type": "markdown",
6767
"metadata": {},
6868
"source": [
69-
"The `try` statement tells the Python interpreter that something could go wrong in the following statements, but we know and have ways to deal with it. \n",
69+
"The `try` statement tells the Python interpreter that something could go wrong in the following statements, but we know and have ways to deal with it. Any statements after the `try-except` block will execute normally, even if a `ValueError` is raised.\n",
7070
"\n",
7171
"Note: we need `num *= 2` and `print(num)` in the `try` block because if the user inputs something wrong, `num` won't be defined. If the statements were *after* the try statement, this could cause an error as `num` wouldn't be defined.\n",
7272
"\n",
@@ -95,7 +95,7 @@
9595
"source": [
9696
"All exceptions are a type of class, all inheriting from the **Exception** class. Also, certain exceptions are also subclasses of other exceptions, e.g. `ZeroDivisionError` is a subclass of `ArithmeticError`, here's a full hierarchy: \n",
9797
"\n",
98-
"***Image of Exception hierarchy goes here***"
98+
"![Image of Exception hierarchy goes here](Picture3.png)"
9999
]
100100
},
101101
{
@@ -129,7 +129,7 @@
129129
"source": [
130130
"Try running the above block and input a string. Now input 0. We've caused two different errors, but the same statement is being executed. Why?\n",
131131
"\n",
132-
"Since all exceptions are a subclass of **Exception**, Python considers them to be of type *Exception*. Why does this matter? Python executes the *first relevant* catch statement - in this case it will *always* be an Exception, so the first statement will execute *regardless* of what type of exception we're throwing. You need to make sure that you put any catch statements for subclasses *above* those of their parent classes, otherwise the subclasses will never execute:"
132+
"Since all exceptions are a subclass of **Exception**, Python considers them to be of type **Exception**. Why does this matter? Python executes the *first relevant* except statement - in this case it will *always* be an Exception, so the first statement will execute *regardless* of what type of exception we're throwing. You need to make sure that you put any except statements for subclasses *above* those of their parent classes, otherwise the subclasses will never execute:"
133133
]
134134
},
135135
{
@@ -184,7 +184,7 @@
184184
"cell_type": "markdown",
185185
"metadata": {},
186186
"source": [
187-
"We can also write our own custom exceptions. We define them the same way we define a class, making sure to say it inherits from **Exception**. Then, we can call it anywhere in our code by using `raise`:"
187+
"We can also write our own custom exceptions. We define them the same way we define a class, making sure it inherits from **Exception**. Then, we can call it anywhere in our code by using `raise`:"
188188
]
189189
},
190190
{
@@ -396,7 +396,7 @@
396396
"cell_type": "markdown",
397397
"metadata": {},
398398
"source": [
399-
"***There should be a diagram of the exploding recursive call tree here.***"
399+
"![diagram of the exploding recursive call tree](Picture4.jpg)"
400400
]
401401
},
402402
{
@@ -476,7 +476,7 @@
476476
"cell_type": "markdown",
477477
"metadata": {},
478478
"source": [
479-
"***Image of first 6-7 rows of Pascal's Triangle Here, with n on the y axis going down, and k on the x-axis going right***"
479+
"![Image of first 6-7 rows of Pascal's Triangle](pascals.png)"
480480
]
481481
},
482482
{
@@ -640,14 +640,14 @@
640640
"cell_type": "markdown",
641641
"metadata": {},
642642
"source": [
643-
"The fancier name for this is a **binary search**, because at each step, we're dividing the search space we have left into 2. So, how much faster is this method than a regular, linear search? Well, for small lists you won't see much improvement, but for larger lists, say, with $n$ items, we only need to check $\\log(n)$ of them in the worst case! The difference couldn't be clearer:"
643+
"The fancier name for this is a **Binary Search**, because at each step, we're dividing the search space we have left into 2. So, how much faster is this method than a regular, linear search? Well, for small lists you won't see much improvement, but for larger lists, say, with $n$ items, we only need to check $\\log(n)$ of them in the worst case! The difference couldn't be clearer:"
644644
]
645645
},
646646
{
647647
"cell_type": "markdown",
648648
"metadata": {},
649649
"source": [
650-
"***Comparison between y = x and y = log(x) on a graph***"
650+
"![Comparison between y = x and y = log(x) on a graph](Picture5.jpg)"
651651
]
652652
},
653653
{
@@ -1208,7 +1208,7 @@
12081208
"orig_nbformat": 4,
12091209
"vscode": {
12101210
"interpreter": {
1211-
"hash": "bb33f6d328f18c07440802b8c66874c52744b86bff5cfe8eb1d71afeb55a2150"
1211+
"hash": "b852fe1f214fe6a0387799bd52159c64dfd73c3955c21916f0ce4da0f34f6d48"
12121212
}
12131213
}
12141214
},

0 commit comments

Comments
 (0)