Skip to content

Commit 53f7030

Browse files
committed
2 parents 249e395 + ac89cfc commit 53f7030

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

week6/w6.ipynb

Lines changed: 10 additions & 11 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+
"### *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",
@@ -139,7 +139,7 @@
139139
"source": [
140140
"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",
141141
"\n",
142-
"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:"
142+
"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:"
143143
]
144144
},
145145
{
@@ -194,7 +194,7 @@
194194
"cell_type": "markdown",
195195
"metadata": {},
196196
"source": [
197-
"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`:"
197+
"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`:"
198198
]
199199
},
200200
{
@@ -497,7 +497,7 @@
497497
"metadata": {},
498498
"source": [
499499
"![pascal.png](attachment:pascal.png)"
500-
]
500+
]
501501
},
502502
{
503503
"cell_type": "markdown",
@@ -671,7 +671,7 @@
671671
"cell_type": "markdown",
672672
"metadata": {},
673673
"source": [
674-
"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:"
674+
"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:"
675675
]
676676
},
677677
{
@@ -684,7 +684,7 @@
684684
"metadata": {},
685685
"source": [
686686
"![Picture3.png](attachment:Picture3.png)"
687-
]
687+
]
688688
},
689689
{
690690
"cell_type": "markdown",
@@ -1370,8 +1370,7 @@
13701370
},
13711371
"vscode": {
13721372
"interpreter": {
1373-
"hash": "7c57092efe4ff60dfd9ba12cd3127c3cb8001227526172b4b54478afc6e523e7"
1374-
}
1373+
"hash": "7c57092efe4ff60dfd9ba12cd3127c3cb8001227526172b4b54478afc6e523e7"}
13751374
}
13761375
},
13771376
"nbformat": 4,

0 commit comments

Comments
 (0)