Skip to content

Commit 005ccab

Browse files
committed
lesson -4
1 parent 065cfe9 commit 005ccab

File tree

1 file changed

+269
-0
lines changed

1 file changed

+269
-0
lines changed

Lesson-4.ipynb

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "bdc4946b-43bb-4bf3-aff0-4473917363ae",
6+
"metadata": {},
7+
"source": [
8+
"Python Errors\n",
9+
"Python errors are messages that Python gives you when something goes wrong in your code.\n",
10+
"\n",
11+
"SyntaxError: This happens when you have a typo or incorrect syntax."
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"id": "b38b4a9f-3fe2-4a49-b847-f672ef1dc007",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"print(\"Hello world"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "6f223503-048d-4567-b0ef-a9280921ff65",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"SyntaxError: EOL while scanning string literal"
32+
]
33+
},
34+
{
35+
"cell_type": "markdown",
36+
"id": "b4691206-dac4-479d-8246-970988b794e6",
37+
"metadata": {},
38+
"source": [
39+
"IndentationError: This happens when the indentation (spaces or tabs) is incorrect."
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"id": "11a02d7b-164e-4345-8c1d-df2103ef4127",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"if True:\n",
50+
"print(\"Hello\")"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"id": "0ae94598-3ed4-48cb-ab81-32bc908b2fd9",
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"IndentationError: expected an indented block"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"id": "11d6d922-27be-4b28-aa32-741ef5319290",
66+
"metadata": {},
67+
"source": [
68+
"NameError: This happens when you try to use a variable that hasn’t been defined."
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"id": "a75c5de6-eace-4c32-85a2-2b9139b84062",
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"print(x)"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"id": "0cabcdce-064d-4f5e-9264-87c02861afbf",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"NameError: name 'x' is not defined"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"id": "703f383c-186f-47a0-821e-8b1562732a61",
94+
"metadata": {},
95+
"source": [
96+
"TypeError: This happens when an operation is applied to an object of inappropriate type."
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": null,
102+
"id": "6cf01916-c907-4246-a64b-9dcdaa865ba0",
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"print(\"Hello\" + 5)"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"id": "9e5ea9ed-7d2b-4623-89c7-4eaafec40e27",
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"TypeError: can only concatenate str (not \"int\") to str"
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": null,
122+
"id": "6d6b6fae-b34d-4c1b-baea-c6baf6b36431",
123+
"metadata": {},
124+
"outputs": [],
125+
"source": [
126+
"print(\"Hello\" + str(5))"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"id": "39125771-d296-4221-9da1-0f44c18ad35d",
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"Hello5"
137+
]
138+
},
139+
{
140+
"cell_type": "markdown",
141+
"id": "b5073df7-02be-4188-b059-fa4ea0febfa6",
142+
"metadata": {},
143+
"source": [
144+
"Keywords: not, and, or\n",
145+
"These keywords are used to combine conditional statements.\n",
146+
"\n",
147+
"not: Inverts the boolean value."
148+
]
149+
},
150+
{
151+
"cell_type": "markdown",
152+
"id": "241c326f-b284-4209-9b4f-3daab1866845",
153+
"metadata": {},
154+
"source": [
155+
"<img src= \"python-logical-operators.webp\">"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": null,
161+
"id": "80ab6628-bb93-4e43-89f9-a417837bcf1d",
162+
"metadata": {},
163+
"outputs": [],
164+
"source": [
165+
"door_locked = False\n",
166+
"if not door_locked:\n",
167+
" print(\"You can enter.\")"
168+
]
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": null,
173+
"id": "0c0364f6-9657-4ee5-a05b-1d1da03ec914",
174+
"metadata": {},
175+
"outputs": [],
176+
"source": [
177+
"#OUTPUT\n",
178+
"You can enter."
179+
]
180+
},
181+
{
182+
"cell_type": "markdown",
183+
"id": "395e7131-686c-4400-a2b7-38b7873349c8",
184+
"metadata": {},
185+
"source": [
186+
"and: Both conditions must be true.\n",
187+
"\n",
188+
"Example: Checking if you have a ticket and it's a weekday\n",
189+
"python\n"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": null,
195+
"id": "d9ea428d-c587-4522-be66-9e9f75710f53",
196+
"metadata": {},
197+
"outputs": [],
198+
"source": [
199+
"has_ticket = True\n",
200+
"is_weekday = True\n",
201+
"if has_ticket and is_weekday:\n",
202+
" print(\"You can go to work.\")"
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": null,
208+
"id": "f861a29f-562b-45ca-a74e-9314b49ec01c",
209+
"metadata": {},
210+
"outputs": [],
211+
"source": [
212+
"#OUTPUT\n",
213+
"You can go to work."
214+
]
215+
},
216+
{
217+
"cell_type": "markdown",
218+
"id": "0eaebb7e-fc24-405e-bbc1-6b031e4af940",
219+
"metadata": {},
220+
"source": [
221+
"or: At least one condition must be true.\n",
222+
"Example: Checking if it’s sunny or you have an umbrella"
223+
]
224+
},
225+
{
226+
"cell_type": "markdown",
227+
"id": "ee9a9d72-c6aa-4b1b-9912-70b9613b401f",
228+
"metadata": {},
229+
"source": [
230+
"is_sunny = False\n",
231+
"has_umbrella = True\n",
232+
"if is_sunny or has_umbrella:\n",
233+
" print(\"You can go outside.\")"
234+
]
235+
},
236+
{
237+
"cell_type": "code",
238+
"execution_count": null,
239+
"id": "70f54597-562e-4d91-a417-411ef1a5e4a3",
240+
"metadata": {},
241+
"outputs": [],
242+
"source": [
243+
"#OUTPUT\n",
244+
"You can go outside."
245+
]
246+
}
247+
],
248+
"metadata": {
249+
"kernelspec": {
250+
"display_name": "Python 3 (ipykernel)",
251+
"language": "python",
252+
"name": "python3"
253+
},
254+
"language_info": {
255+
"codemirror_mode": {
256+
"name": "ipython",
257+
"version": 3
258+
},
259+
"file_extension": ".py",
260+
"mimetype": "text/x-python",
261+
"name": "python",
262+
"nbconvert_exporter": "python",
263+
"pygments_lexer": "ipython3",
264+
"version": "3.12.4"
265+
}
266+
},
267+
"nbformat": 4,
268+
"nbformat_minor": 5
269+
}

0 commit comments

Comments
 (0)