Skip to content

Commit 0b8f86c

Browse files
committed
Added exception handling chapter
1 parent 3992e9f commit 0b8f86c

File tree

3 files changed

+447
-9
lines changed

3 files changed

+447
-9
lines changed

content/04_data_flow_control.ipynb

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@
244244
"metadata": {},
245245
"outputs": [],
246246
"source": [
247-
"# for-else"
247+
"for item in [1, 3, 5, 7, 9]:\n",
248+
" if item % 2 == 0:\n",
249+
" print(item)"
248250
]
249251
},
250252
{
@@ -314,7 +316,13 @@
314316
"metadata": {},
315317
"outputs": [],
316318
"source": [
317-
"# while-else"
319+
"num_list = [1, 2, 3, 4, 5]\n",
320+
"count = 0\n",
321+
"while count != len(num_list):\n",
322+
" print(num_list[count])\n",
323+
" count += 1\n",
324+
"else:\n",
325+
" print(\"All elements have been printed\")"
318326
]
319327
},
320328
{
@@ -349,6 +357,45 @@
349357
" print(item)"
350358
]
351359
},
360+
{
361+
"attachments": {},
362+
"cell_type": "markdown",
363+
"metadata": {},
364+
"source": [
365+
"## for-else and while-else"
366+
]
367+
},
368+
{
369+
"cell_type": "code",
370+
"execution_count": null,
371+
"metadata": {},
372+
"outputs": [],
373+
"source": [
374+
"for item in [1, 3, 5, 7, 9]:\n",
375+
" if item % 2 == 0:\n",
376+
" print(item)\n",
377+
"else:\n",
378+
" print(\"There are no even numbers in the list!\")"
379+
]
380+
},
381+
{
382+
"cell_type": "code",
383+
"execution_count": null,
384+
"metadata": {},
385+
"outputs": [],
386+
"source": [
387+
"num_list = [1, 2, 3, 4, 5]\n",
388+
"count = 0\n",
389+
"while count != len(num_list):\n",
390+
" print(num_list[count])\n",
391+
" count += 1\n",
392+
"\n",
393+
" if num_list[count] == 4:\n",
394+
" break\n",
395+
"else:\n",
396+
" print(\"All elements have been printed\")"
397+
]
398+
},
352399
{
353400
"attachments": {},
354401
"cell_type": "markdown",

content/10_object_oriented_programming.ipynb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,28 @@
743743
"print(f\"I have {rectangle.get_side_count()} sides!\")"
744744
]
745745
},
746+
{
747+
"cell_type": "code",
748+
"execution_count": null,
749+
"metadata": {},
750+
"outputs": [],
751+
"source": [
752+
"class Square(Rectangle):\n",
753+
" def __init__(self, length) -> None:\n",
754+
" self.length = length\n",
755+
" self.breadth = length"
756+
]
757+
},
758+
{
759+
"cell_type": "code",
760+
"execution_count": null,
761+
"metadata": {},
762+
"outputs": [],
763+
"source": [
764+
"square = Square(4)\n",
765+
"print(square.area())"
766+
]
767+
},
746768
{
747769
"attachments": {},
748770
"cell_type": "markdown",
@@ -1342,6 +1364,40 @@
13421364
"john == john1"
13431365
]
13441366
},
1367+
{
1368+
"cell_type": "code",
1369+
"execution_count": null,
1370+
"metadata": {},
1371+
"outputs": [],
1372+
"source": [
1373+
"from dataclasses import dataclass"
1374+
]
1375+
},
1376+
{
1377+
"cell_type": "code",
1378+
"execution_count": null,
1379+
"metadata": {},
1380+
"outputs": [],
1381+
"source": [
1382+
"@dataclass\n",
1383+
"class Person:\n",
1384+
" \"\"\"Child class\"\"\"\n",
1385+
" name: str\n",
1386+
" age: int\n",
1387+
" job: str = None\n",
1388+
" eye_color: str = \"black\""
1389+
]
1390+
},
1391+
{
1392+
"cell_type": "code",
1393+
"execution_count": null,
1394+
"metadata": {},
1395+
"outputs": [],
1396+
"source": [
1397+
"tom = Person(\"Tom\", 40, \"Engineer\")\n",
1398+
"print(tom)"
1399+
]
1400+
},
13451401
{
13461402
"attachments": {},
13471403
"cell_type": "markdown",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy