Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:04,400 --> 00:00:07,200
hi i'm rona and together we will learn
2
00:00:07,200 --> 00:00:10,960
python this course is structured in 17
3
00:00:10,960 --> 00:00:12,960
lessons in each lesson we will learn
4
00:00:12,960 --> 00:00:15,360
some new concept and build a project
5
00:00:15,360 --> 00:00:17,680
based on that and previous knowledge
6
00:00:17,680 --> 00:00:20,000
that means along the way it gets more
7
00:00:20,000 --> 00:00:22,720
and more advanced we will start simple
8
00:00:22,720 --> 00:00:25,359
by learning what are variables what are
9
00:00:25,359 --> 00:00:27,359
lists and dictionaries how can you use
10
00:00:27,359 --> 00:00:28,880
them in your programming how can you
11
00:00:28,880 --> 00:00:31,679
make program flow with if statements and
12
00:00:31,679 --> 00:00:34,320
loops we will use functions to structure
13
00:00:34,320 --> 00:00:36,559
your code also we will use randomness to
14
00:00:36,559 --> 00:00:38,719
create small awesome games we will learn
15
00:00:38,719 --> 00:00:41,280
how to read and process csv files if you
16
00:00:41,280 --> 00:00:42,719
don't know what any of these things are
17
00:00:42,719 --> 00:00:44,320
don't worry we'll get there we will
18
00:00:44,320 --> 00:00:47,200
learn about object oriented programming
19
00:00:47,200 --> 00:00:49,680
and start by creating a card game that
20
00:00:49,680 --> 00:00:51,360
we can play we will learn how to
21
00:00:51,360 --> 00:00:54,160
visualize data and we will use numpy and
22
00:00:54,160 --> 00:00:56,960
pandas to work with data these are some
23
00:00:56,960 --> 00:00:59,760
of the key libraries you need to master
24
00:00:59,760 --> 00:01:02,480
we will learn about recursive functions
25
00:01:02,480 --> 00:01:04,159
and how to use that
26
00:01:04,159 --> 00:01:06,640
we will learn about list comprehension
27
00:01:06,640 --> 00:01:08,960
and finally in the capstone project we
28
00:01:08,960 --> 00:01:11,439
will build our own machine learning
29
00:01:11,439 --> 00:01:13,680
model we will build it from scratch yeah
30
00:01:13,680 --> 00:01:15,360
that's right we're not gonna use some
31
00:01:15,360 --> 00:01:17,360
library to build it we're gonna build
32
00:01:17,360 --> 00:01:19,040
every single piece of the machine
33
00:01:19,040 --> 00:01:20,799
learning model and we will test it to
34
00:01:20,799 --> 00:01:23,439
see how it performs comparing to a naive
35
00:01:23,439 --> 00:01:25,759
classical way to solve the problem for
36
00:01:25,759 --> 00:01:27,759
me this is exciting and i want to share
37
00:01:27,759 --> 00:01:30,320
this passion with you i'm owner i have a
38
00:01:30,320 --> 00:01:32,479
master degree and a phd in computer
39
00:01:32,479 --> 00:01:34,320
science i have more than 10 years of
40
00:01:34,320 --> 00:01:35,920
professional programming experience i
41
00:01:35,920 --> 00:01:37,920
love python and i want to share that
42
00:01:37,920 --> 00:01:40,240
passion with you and show you why it's
43
00:01:40,240 --> 00:01:41,759
so popular
44
00:01:41,759 --> 00:01:44,159
see you
45
00:01:46,320 --> 00:01:48,000
if you're new to programming or new to
46
00:01:48,000 --> 00:01:50,159
python in general and you wonder what
47
00:01:50,159 --> 00:01:52,720
people are using python for luckily
48
00:01:52,720 --> 00:01:54,320
they're made surveys for that so let's
49
00:01:54,320 --> 00:01:56,240
dive into that the main things that
50
00:01:56,240 --> 00:01:59,200
people use python for are data analysis
51
00:01:59,200 --> 00:02:01,840
web development machine learning devops
52
00:02:01,840 --> 00:02:04,159
and programming web parses scrapers and
53
00:02:04,159 --> 00:02:06,479
crawlers and so on you can see the full
54
00:02:06,479 --> 00:02:08,639
list here this course will mainly focus
55
00:02:08,639 --> 00:02:10,160
on how you can get started with data
56
00:02:10,160 --> 00:02:12,400
analysis and machine learning why are
57
00:02:12,400 --> 00:02:14,400
people so excited by python i mean i
58
00:02:14,400 --> 00:02:17,040
know why i am but why are people well
59
00:02:17,040 --> 00:02:18,800
some of the key features that people
60
00:02:18,800 --> 00:02:22,319
love are simple syntax syntactic sugar
61
00:02:22,319 --> 00:02:24,879
easy to learn right that sounds like the
62
00:02:24,879 --> 00:02:27,280
perfect beginner programming language
63
00:02:27,280 --> 00:02:28,959
and it is
64
00:02:28,959 --> 00:02:31,599
also it's easy to write and read code
65
00:02:31,599 --> 00:02:33,840
it's a high-level language basically
66
00:02:33,840 --> 00:02:36,160
list comprehensions people love that
67
00:02:36,160 --> 00:02:38,720
kind of stuff and we will cover all that
68
00:02:38,720 --> 00:02:41,519
in this course so don't worry about it
69
00:02:41,519 --> 00:02:44,239
and the list goes on why people love it
70
00:02:44,239 --> 00:02:46,239
if you're looking for a job well is
71
00:02:46,239 --> 00:02:48,000
python the right language and how long
72
00:02:48,000 --> 00:02:50,239
does it take right how long do you need
73
00:02:50,239 --> 00:02:52,000
to have experience with python in order
74
00:02:52,000 --> 00:02:54,160
to get the job so let's first dive into
75
00:02:54,160 --> 00:02:56,000
the job roles and see what are people
76
00:02:56,000 --> 00:02:58,159
what label do they put on themselves
77
00:02:58,159 --> 00:03:00,879
well the main one is developer and
78
00:03:00,879 --> 00:03:03,599
programmer and i must say i'm in that
79
00:03:03,599 --> 00:03:05,599
group as well i'm a freelance developer
80
00:03:05,599 --> 00:03:07,840
at current stage and
81
00:03:07,840 --> 00:03:09,360
yeah most people say that but they're
82
00:03:09,360 --> 00:03:11,599
also architects and data analysts i
83
00:03:11,599 --> 00:03:13,440
wouldn't go too much into the because
84
00:03:13,440 --> 00:03:14,959
most people they call themselves
85
00:03:14,959 --> 00:03:17,440
developers or programmers so how much
86
00:03:17,440 --> 00:03:19,599
experience do people have actually well
87
00:03:19,599 --> 00:03:21,440
they have three to five years of python
88
00:03:21,440 --> 00:03:23,680
and that sounds like a long time but
89
00:03:23,680 --> 00:03:25,440
there's a catch this is actually not
90
00:03:25,440 --> 00:03:26,799
professional experience if you look at
91
00:03:26,799 --> 00:03:29,200
that professional coding experience most
92
00:03:29,200 --> 00:03:30,879
have less than a year unfortunately we
93
00:03:30,879 --> 00:03:32,319
cannot conclude it will take less than a
94
00:03:32,319 --> 00:03:34,239
year for you to get a job the trick
95
00:03:34,239 --> 00:03:35,920
question is how long does it take from a
96
00:03:35,920 --> 00:03:38,080
starting python to get a job
97
00:03:38,080 --> 00:03:40,480
well you can see here that the python
98
00:03:40,480 --> 00:03:42,480
experience in general on this survey
99
00:03:42,480 --> 00:03:44,799
well it seems like around three years
100
00:03:44,799 --> 00:03:46,879
most more than half have less than three
101
00:03:46,879 --> 00:03:49,519
years experience also professionally
102
00:03:49,519 --> 00:03:51,599
most have less than a year does that
103
00:03:51,599 --> 00:03:52,959
mean it takes less than a year to get a
104
00:03:52,959 --> 00:03:55,120
job no we cannot conclude that i'm sorry
105
00:03:55,120 --> 00:03:57,599
to say that but i do personally know
106
00:03:57,599 --> 00:04:00,560
people that started learning python and
107
00:04:00,560 --> 00:04:03,280
got their first job in within half a
108
00:04:03,280 --> 00:04:04,159
year
109
00:04:04,159 --> 00:04:06,080
but if you have commitment you can do
110
00:04:06,080 --> 00:04:08,640
exactly the same are you excited i'm
111
00:04:08,640 --> 00:04:12,599
excited let's get started
112
00:04:14,159 --> 00:04:16,478
this course is structured in 17 lessons
113
00:04:16,478 --> 00:04:18,238
and in each lesson there will be two
114
00:04:18,238 --> 00:04:20,478
jupyter notebooks the jupyter notebooks
115
00:04:20,478 --> 00:04:23,120
contain the coding environment that we
116
00:04:23,120 --> 00:04:25,520
work in and these are available for you
117
00:04:25,520 --> 00:04:28,080
so you can follow along and also there's
118
00:04:28,080 --> 00:04:30,639
a project at each lessons they're
119
00:04:30,639 --> 00:04:32,479
starting quite easy and there's
120
00:04:32,479 --> 00:04:34,400
description of what you should do
121
00:04:34,400 --> 00:04:36,479
after you've done that you can see my
122
00:04:36,479 --> 00:04:38,880
solution how i would do it in the videos
123
00:04:38,880 --> 00:04:41,440
as well along with that there's a e-book
124
00:04:41,440 --> 00:04:43,280
which actually follows you through all
125
00:04:43,280 --> 00:04:45,360
you need to do so if you download this
126
00:04:45,360 --> 00:04:47,840
ebook here you can actually go step by
127
00:04:47,840 --> 00:04:49,680
step through the lessons as well and it
128
00:04:49,680 --> 00:04:51,120
will show you everything you need to do
129
00:04:51,120 --> 00:04:52,880
right how to install anaconda how to
130
00:04:52,880 --> 00:04:55,040
download the zip files containing all
131
00:04:55,040 --> 00:04:56,639
the jupyter notebooks so you're already
132
00:04:56,639 --> 00:04:59,120
in your environment if you like to work
133
00:04:59,120 --> 00:05:01,360
with an ebook where you can see all the
134
00:05:01,360 --> 00:05:04,479
things we learned well this is a great
135
00:05:04,479 --> 00:05:06,800
resource the projects we make along the
136
00:05:06,800 --> 00:05:09,280
way become more and more advanced in the
137
00:05:09,280 --> 00:05:11,199
end we like to make this reinforcement
138
00:05:11,199 --> 00:05:14,000
learning a machine learning model where
139
00:05:14,000 --> 00:05:15,280
we actually
140
00:05:15,280 --> 00:05:18,240
do all the coding from scratch we will
141
00:05:18,240 --> 00:05:21,680
use no libraries actually to implement
142
00:05:21,680 --> 00:05:22,479
it
143
00:05:22,479 --> 00:05:23,919
if you just want to get started and you
144
00:05:23,919 --> 00:05:25,600
don't want to install anything well you
145
00:05:25,600 --> 00:05:29,360
can do that too go to my github here and
146
00:05:29,360 --> 00:05:30,639
actually down here you can see you can
147
00:05:30,639 --> 00:05:32,160
actually access
148
00:05:32,160 --> 00:05:34,320
all the jupyter notebooks directly in
149
00:05:34,320 --> 00:05:36,880
colab and if you don't know what that is
150
00:05:36,880 --> 00:05:38,560
well don't worry about it i'll just show
151
00:05:38,560 --> 00:05:41,039
you here that is actually owned by
152
00:05:41,039 --> 00:05:42,400
google and
153
00:05:42,400 --> 00:05:43,440
when you
154
00:05:43,440 --> 00:05:44,800
you can load the jupyter notebooks in
155
00:05:44,800 --> 00:05:46,479
there and then you can actually execute
156
00:05:46,479 --> 00:05:48,800
the code in there
157
00:05:48,800 --> 00:05:51,280
directly so you can get the experience
158
00:05:51,280 --> 00:05:54,000
that you're looking for so are you ready
159
00:05:54,000 --> 00:05:57,680
i'm ready let's get started
160
00:05:59,680 --> 00:06:01,440
so before we get started you should get
161
00:06:01,440 --> 00:06:04,479
anaconda anaconda gives you everything
162
00:06:04,479 --> 00:06:05,919
you need it gives you the jupyter
163
00:06:05,919 --> 00:06:09,039
notebooks and the python environment so
164
00:06:09,039 --> 00:06:11,360
how do you get all that well you go to
165
00:06:11,360 --> 00:06:14,000
anacondas page and you download it here
166
00:06:14,000 --> 00:06:16,000
you just click here
167
00:06:16,000 --> 00:06:17,680
you should choose the operating system
168
00:06:17,680 --> 00:06:20,960
that you're using i'm using mac here so
169
00:06:20,960 --> 00:06:23,199
you should use a graphical installer and
170
00:06:23,199 --> 00:06:24,720
then it just downloads and it's
171
00:06:24,720 --> 00:06:26,960
available in a moment and after you
172
00:06:26,960 --> 00:06:29,600
download it just install it well after
173
00:06:29,600 --> 00:06:32,080
you installed anaconda you need to get
174
00:06:32,080 --> 00:06:34,400
the resources from this course and the
175
00:06:34,400 --> 00:06:36,960
resources are available in my github
176
00:06:36,960 --> 00:06:39,520
repository there's a link for that and
177
00:06:39,520 --> 00:06:41,280
what you do is actually just click here
178
00:06:41,280 --> 00:06:44,080
and then you download the zip file here
179
00:06:44,080 --> 00:06:45,919
the zip file contains everything you
180
00:06:45,919 --> 00:06:48,720
need in order to complete this course
181
00:06:48,720 --> 00:06:51,039
let's try to get started with anaconda
182
00:06:51,039 --> 00:06:52,800
so after you installed it you should be
183
00:06:52,800 --> 00:06:56,000
able to open the anaconda navigator and
184
00:06:56,000 --> 00:06:57,759
in that one you should just launch
185
00:06:57,759 --> 00:06:59,599
jupiter notebook when you press it a
186
00:06:59,599 --> 00:07:01,199
terminal will jump up then you should
187
00:07:01,199 --> 00:07:02,400
come to this picture
188
00:07:02,400 --> 00:07:05,199
and you probably downloaded the zip file
189
00:07:05,199 --> 00:07:07,039
if you did like that well you just go
190
00:07:07,039 --> 00:07:09,199
here and click on that and here are all
191
00:07:09,199 --> 00:07:11,840
the files available and in the first
192
00:07:11,840 --> 00:07:13,599
session we're gonna work with hello
193
00:07:13,599 --> 00:07:15,520
world so that is the one you should
194
00:07:15,520 --> 00:07:18,080
click and then it opens here now you're
195
00:07:18,080 --> 00:07:22,400
ready and i'm ready let's get started
196
00:07:24,800 --> 00:07:27,039
so in this first lecture we will get
197
00:07:27,039 --> 00:07:30,160
started with python we will start using
198
00:07:30,160 --> 00:07:32,319
our first jupyter notebook and learn
199
00:07:32,319 --> 00:07:34,639
along the way and in the end of this
200
00:07:34,639 --> 00:07:37,039
first lesson here you'll get ready to
201
00:07:37,039 --> 00:07:39,199
make your first project so are you
202
00:07:39,199 --> 00:07:41,840
excited i am let's get started
203
00:07:41,840 --> 00:07:43,759
so we're inside this jupyter notebook
204
00:07:43,759 --> 00:07:45,599
and if you're unfamiliar with it well
205
00:07:45,599 --> 00:07:47,199
jupiter notebook is an environment where
206
00:07:47,199 --> 00:07:50,160
you can write text and execute code i'll
207
00:07:50,160 --> 00:07:51,680
show you in a moment don't worry about
208
00:07:51,680 --> 00:07:52,479
it
209
00:07:52,479 --> 00:07:54,479
so the first thing here is called hello
210
00:07:54,479 --> 00:07:57,360
world so there's a story behind that
211
00:07:57,360 --> 00:07:59,120
the hello world thing why is it that
212
00:07:59,120 --> 00:08:01,039
every programmer does this hello world
213
00:08:01,039 --> 00:08:04,080
as a first program well there's a link
214
00:08:04,080 --> 00:08:06,240
there it's a funny story and you should
215
00:08:06,240 --> 00:08:08,160
know it that everybody does that as
216
00:08:08,160 --> 00:08:09,840
their first program that's just how you
217
00:08:09,840 --> 00:08:12,400
are that's how it is to be a programmer
218
00:08:12,400 --> 00:08:15,039
make the hello world and be like us
219
00:08:15,039 --> 00:08:15,919
right
220
00:08:15,919 --> 00:08:18,240
awesome
221
00:08:18,240 --> 00:08:19,919
so
222
00:08:19,919 --> 00:08:21,280
should we do that
223
00:08:21,280 --> 00:08:23,360
yeah i think so because one of the
224
00:08:23,360 --> 00:08:26,240
advantages of python is actually the
225
00:08:26,240 --> 00:08:28,560
hello world thing it is so simple if
226
00:08:28,560 --> 00:08:30,400
you've seen other programming languages
227
00:08:30,400 --> 00:08:32,399
you'll see wow why do you need all these
228
00:08:32,399 --> 00:08:34,880
things well in python you only need to
229
00:08:34,880 --> 00:08:36,719
use a print statement
230
00:08:36,719 --> 00:08:39,200
print which will print to the screen and
231
00:08:39,200 --> 00:08:40,799
you just write hello
232
00:08:40,799 --> 00:08:42,320
world
233
00:08:42,320 --> 00:08:45,040
executed so how did i do that how did i
234
00:08:45,040 --> 00:08:47,040
do that what happened here right so i
235
00:08:47,040 --> 00:08:50,320
wrote print hello world in quotes
236
00:08:50,320 --> 00:08:52,320
and then it printed hello world down
237
00:08:52,320 --> 00:08:53,519
here without the quotes that's the
238
00:08:53,519 --> 00:08:55,440
output of the print statement and how
239
00:08:55,440 --> 00:08:57,279
did i execute this one well you can
240
00:08:57,279 --> 00:08:59,839
execute it by either pressing this one
241
00:08:59,839 --> 00:09:02,560
up here the run here or you can execute
242
00:09:02,560 --> 00:09:06,720
it by pressing shift enter
243
00:09:06,839 --> 00:09:10,240
so if you download the e-book it's all
244
00:09:10,240 --> 00:09:11,760
explained there too if you forget about
245
00:09:11,760 --> 00:09:14,160
it so don't worry about that but you
246
00:09:14,160 --> 00:09:15,920
always know you can always just use the
247
00:09:15,920 --> 00:09:18,480
bottom-ups here well that was it the
248
00:09:18,480 --> 00:09:19,600
story behind
249
00:09:19,600 --> 00:09:21,839
the storybound hello world read it it's
250
00:09:21,839 --> 00:09:23,839
funny
251
00:09:23,839 --> 00:09:26,240
the sin of python and what is that it's
252
00:09:26,240 --> 00:09:28,720
kind of a joke in some way but it's also
253
00:09:28,720 --> 00:09:31,360
good guidelines and i included it here
254
00:09:31,360 --> 00:09:32,880
because it's kind of like computer
255
00:09:32,880 --> 00:09:34,880
science humor and on the other hand it's
256
00:09:34,880 --> 00:09:36,480
also good guidelines when you do
257
00:09:36,480 --> 00:09:37,600
programming
258
00:09:37,600 --> 00:09:40,480
and the code to get it don't worry about
259
00:09:40,480 --> 00:09:43,200
it it's just called import this and
260
00:09:43,200 --> 00:09:45,279
this is not the
261
00:09:45,279 --> 00:09:46,880
this is actually the way you import the
262
00:09:46,880 --> 00:09:48,880
libraries but this library only prints
263
00:09:48,880 --> 00:09:51,680
this the sin of python so if you execute
264
00:09:51,680 --> 00:09:53,839
that cell here we'll get the sent of
265
00:09:53,839 --> 00:09:57,040
python by tim peters
266
00:09:57,040 --> 00:09:58,720
so i'm not going to go through all these
267
00:09:58,720 --> 00:10:00,959
here together with you because
268
00:10:00,959 --> 00:10:02,320
i just wanted to emphasize that these
269
00:10:02,320 --> 00:10:03,680
are just guidelines and this kind of
270
00:10:03,680 --> 00:10:05,279
sets you into the mindset how does the
271
00:10:05,279 --> 00:10:07,440
programmer think right so it's just
272
00:10:07,440 --> 00:10:10,000
beautiful it's better than ugly what
273
00:10:10,000 --> 00:10:11,920
why is that right everybody agrees with
274
00:10:11,920 --> 00:10:13,760
that but in computer science maybe it's
275
00:10:13,760 --> 00:10:16,560
like you need to understand that you
276
00:10:16,560 --> 00:10:19,040
need to make things in a nice and easy
277
00:10:19,040 --> 00:10:21,279
to understand way and there's also a
278
00:10:21,279 --> 00:10:23,200
saying called simple is better than
279
00:10:23,200 --> 00:10:24,320
complex
280
00:10:24,320 --> 00:10:25,120
and
281
00:10:25,120 --> 00:10:26,560
actually the third one here simple is
282
00:10:26,560 --> 00:10:28,800
better than complex you need to simplify
283
00:10:28,800 --> 00:10:30,720
things you need to understand when you
284
00:10:30,720 --> 00:10:33,040
program things often very easily becomes
285
00:10:33,040 --> 00:10:35,680
very complex and nobody understands them
286
00:10:35,680 --> 00:10:38,640
and this is saying actually that you
287
00:10:38,640 --> 00:10:40,800
write the code once but you read it
288
00:10:40,800 --> 00:10:44,480
multiple times right so when you add new
289
00:10:44,480 --> 00:10:46,320
features you need to read the other code
290
00:10:46,320 --> 00:10:48,640
in order to understand it when you debug
291
00:10:48,640 --> 00:10:50,079
that is when the program doesn't work
292
00:10:50,079 --> 00:10:51,680
you need to read the code again but you
293
00:10:51,680 --> 00:10:54,320
only write it once right so we as
294
00:10:54,320 --> 00:10:56,640
programmers we are actually responsible
295
00:10:56,640 --> 00:10:59,200
to make it readable and actually look at
296
00:10:59,200 --> 00:11:03,600
that readable readability counts right
297
00:11:03,600 --> 00:11:05,760
you're an author you need to make a
298
00:11:05,760 --> 00:11:07,279
journey you may need to make it
299
00:11:07,279 --> 00:11:09,120
beautiful you need to make it simple you
300
00:11:09,120 --> 00:11:11,839
need to make it readable
301
00:11:11,839 --> 00:11:12,800
wow
302
00:11:12,800 --> 00:11:14,720
that were just a few things from the sin
303
00:11:14,720 --> 00:11:16,160
of python
304
00:11:16,160 --> 00:11:17,600
read about it
305
00:11:17,600 --> 00:11:19,600
have fun with it learn about computer
306
00:11:19,600 --> 00:11:22,480
science humor i would say but it is kind
307
00:11:22,480 --> 00:11:25,200
of on the edge of humor or serious
308
00:11:25,200 --> 00:11:27,600
that's up for you to judge
309
00:11:27,600 --> 00:11:30,560
so let's get started what is the goal of
310
00:11:30,560 --> 00:11:31,839
this
311
00:11:31,839 --> 00:11:34,000
lesson here right so the main goal is
312
00:11:34,000 --> 00:11:36,000
obviously to get started with python and
313
00:11:36,000 --> 00:11:39,279
we did that with the print hello world
314
00:11:39,279 --> 00:11:41,200
we need to get a bit more started right
315
00:11:41,200 --> 00:11:43,040
yeah okay i agree
316
00:11:43,040 --> 00:11:45,200
okay and then get comfortable with
317
00:11:45,200 --> 00:11:47,279
jupiter notebook this is the jupiter
318
00:11:47,279 --> 00:11:49,200
notebook you can use it quite simple by
319
00:11:49,200 --> 00:11:51,680
running and executing and yeah running
320
00:11:51,680 --> 00:11:55,279
is executing i'm talking crazier
321
00:11:55,279 --> 00:11:56,560
and
322
00:11:56,560 --> 00:11:58,320
the key thing we want to know is how to
323
00:11:58,320 --> 00:11:59,680
input
324
00:11:59,680 --> 00:12:02,560
user input and how to print it back
325
00:12:02,560 --> 00:12:04,959
right and we will learn a few string
326
00:12:04,959 --> 00:12:07,120
methods capitalize lower is decimal and
327
00:12:07,120 --> 00:12:08,800
replace in this one and this will
328
00:12:08,800 --> 00:12:10,320
actually get you started so you can
329
00:12:10,320 --> 00:12:12,800
solve your first project on your own and
330
00:12:12,800 --> 00:12:14,720
when you solve it on your own i'll show
331
00:12:14,720 --> 00:12:16,800
you how i would solve it
332
00:12:16,800 --> 00:12:20,560
good let's get started down here
333
00:12:20,560 --> 00:12:23,279
so the print is an amazing tool you can
334
00:12:23,279 --> 00:12:24,480
print out
335
00:12:24,480 --> 00:12:26,480
things and i say things you can print
336
00:12:26,480 --> 00:12:29,440
whatever let's just try to take a
337
00:12:29,440 --> 00:12:32,639
look at that right so print it can print
338
00:12:32,639 --> 00:12:34,720
for instance a string a string is these
339
00:12:34,720 --> 00:12:37,040
quoted here
340
00:12:37,040 --> 00:12:38,639
double quoted it can also be single
341
00:12:38,639 --> 00:12:40,160
quoted so you can print a string and
342
00:12:40,160 --> 00:12:42,240
then you can comma separate it if you
343
00:12:42,240 --> 00:12:43,839
comma separated you can put something
344
00:12:43,839 --> 00:12:45,920
else in it it can be 10 and it can be
345
00:12:45,920 --> 00:12:48,560
2.2 for instance
346
00:12:48,560 --> 00:12:50,959
and what it does it prints this line
347
00:12:50,959 --> 00:12:52,560
here with the string hey without the
348
00:12:52,560 --> 00:12:54,639
quotes then it prints 10 and then prints
349
00:12:54,639 --> 00:12:58,959
2.2 with a space between you'll see this
350
00:12:58,959 --> 00:13:00,880
way of printing is actually a great way
351
00:13:00,880 --> 00:13:03,279
to use it it can have any number of
352
00:13:03,279 --> 00:13:05,279
arguments in it and
353
00:13:05,279 --> 00:13:06,959
well i love to do it like that the other
354
00:13:06,959 --> 00:13:09,120
way i would love to use print is with
355
00:13:09,120 --> 00:13:11,200
formatted strings which we will learn
356
00:13:11,200 --> 00:13:15,680
about later in the course okay
357
00:13:16,160 --> 00:13:16,959
so
358
00:13:16,959 --> 00:13:18,959
first thing first now we need to know
359
00:13:18,959 --> 00:13:21,440
how to print things and uh well that's
360
00:13:21,440 --> 00:13:22,880
not funny right you can just sit and
361
00:13:22,880 --> 00:13:25,040
print a novel or you can print the send
362
00:13:25,040 --> 00:13:27,040
of python here but how fun is that to
363
00:13:27,040 --> 00:13:29,519
run that multiple times not really so
364
00:13:29,519 --> 00:13:31,600
you want to interact with the user and
365
00:13:31,600 --> 00:13:33,440
the user is the person in front of the
366
00:13:33,440 --> 00:13:37,600
computer so how do you do that well
367
00:13:37,600 --> 00:13:39,420
let's try input right
368
00:13:39,420 --> 00:13:40,560
[Music]
369
00:13:40,560 --> 00:13:41,760
input
370
00:13:41,760 --> 00:13:44,480
well let's execute shift enter remember
371
00:13:44,480 --> 00:13:47,199
execute whoa a line came there let's
372
00:13:47,199 --> 00:13:50,480
write something on that line
373
00:13:50,959 --> 00:13:53,120
i write my name
374
00:13:53,120 --> 00:13:55,120
i press enter boom
375
00:13:55,120 --> 00:13:56,800
and it returned
376
00:13:56,800 --> 00:13:58,240
it just kept
377
00:13:58,240 --> 00:14:00,399
on there look here i also made an
378
00:14:00,399 --> 00:14:02,480
assignment here if you see here right so
379
00:14:02,480 --> 00:14:06,000
the input assigns the value to s so how
380
00:14:06,000 --> 00:14:08,639
it works in programming is that the
381
00:14:08,639 --> 00:14:11,040
right side that is input here
382
00:14:11,040 --> 00:14:13,279
is assigned to the left side here and
383
00:14:13,279 --> 00:14:15,040
the left side is a variable we'll learn
384
00:14:15,040 --> 00:14:17,360
more about variables in the next lesson
385
00:14:17,360 --> 00:14:20,880
here so for now just know that you can
386
00:14:20,880 --> 00:14:23,600
you put the input from
387
00:14:23,600 --> 00:14:27,199
to typed in over to s so if we look at s
388
00:14:27,199 --> 00:14:28,800
this is how you can look at s you can
389
00:14:28,800 --> 00:14:30,880
either print it or just execute it here
390
00:14:30,880 --> 00:14:32,800
if you execute s here you'll see it's a
391
00:14:32,800 --> 00:14:34,800
string single quoted string here it
392
00:14:34,800 --> 00:14:36,160
doesn't matter it's the same thing in
393
00:14:36,160 --> 00:14:38,399
python single or double quoted and it's
394
00:14:38,399 --> 00:14:41,920
called it has a value
395
00:14:41,920 --> 00:14:45,199
awesome so far so good so another thing
396
00:14:45,199 --> 00:14:47,040
you can do is actually you can in this
397
00:14:47,040 --> 00:14:49,680
input here it is actually you can put a
398
00:14:49,680 --> 00:14:50,880
string in that
399
00:14:50,880 --> 00:14:51,920
so
400
00:14:51,920 --> 00:14:54,399
just to learn teach you a few things
401
00:14:54,399 --> 00:14:56,000
with jupiter notebook you can actually
402
00:14:56,000 --> 00:14:59,600
press shift tab here and as you see here
403
00:14:59,600 --> 00:15:00,800
then the
404
00:15:00,800 --> 00:15:02,800
the dock string as it's called that is
405
00:15:02,800 --> 00:15:04,720
the documentation of it
406
00:15:04,720 --> 00:15:05,839
pops up
407
00:15:05,839 --> 00:15:07,600
so
408
00:15:07,600 --> 00:15:10,240
input it says prompt none by default it
409
00:15:10,240 --> 00:15:11,920
can be a bit confusing to read
410
00:15:11,920 --> 00:15:13,440
in the beginning but
411
00:15:13,440 --> 00:15:14,959
what is this is read a string from
412
00:15:14,959 --> 00:15:16,800
standard input the
413
00:15:16,800 --> 00:15:19,360
trailing new line is stripped that is it
414
00:15:19,360 --> 00:15:21,040
doesn't take the new line when you press
415
00:15:21,040 --> 00:15:23,519
enter right uh the prompt string is
416
00:15:23,519 --> 00:15:25,199
given if print
417
00:15:25,199 --> 00:15:27,760
is printed to standard output without a
418
00:15:27,760 --> 00:15:30,000
trailing new line before reading input
419
00:15:30,000 --> 00:15:34,160
so let's try to put a prompt here so
420
00:15:34,160 --> 00:15:35,680
what
421
00:15:35,680 --> 00:15:38,839
what is your name right and question
422
00:15:38,839 --> 00:15:41,199
mark many people like to put a space
423
00:15:41,199 --> 00:15:43,120
between behind here and i'll show you
424
00:15:43,120 --> 00:15:44,800
why
425
00:15:44,800 --> 00:15:46,880
so what the space does is it actually
426
00:15:46,880 --> 00:15:48,320
adds a space here
427
00:15:48,320 --> 00:15:49,279
between
428
00:15:49,279 --> 00:15:51,759
my prompting message here right so what
429
00:15:51,759 --> 00:15:54,000
is your name space just put some space
430
00:15:54,000 --> 00:15:55,759
there it's up to you what is your name
431
00:15:55,759 --> 00:15:57,360
it is
432
00:15:57,360 --> 00:15:59,279
and then i have it here and again i
433
00:15:59,279 --> 00:16:01,440
assigned it to s so there is no question
434
00:16:01,440 --> 00:16:02,560
about it
435
00:16:02,560 --> 00:16:05,199
we print s here and it prints
436
00:16:05,199 --> 00:16:07,040
here and you see the difference when i
437
00:16:07,040 --> 00:16:09,360
use print and i just use a variable is
438
00:16:09,360 --> 00:16:11,040
here it prints it without the quotes
439
00:16:11,040 --> 00:16:13,040
here it shows it's a string with the
440
00:16:13,040 --> 00:16:14,560
quotes okay
441
00:16:14,560 --> 00:16:17,120
so far so good so now we can print
442
00:16:17,120 --> 00:16:20,639
something and we can input something
443
00:16:20,839 --> 00:16:23,519
and let's try to make it a bit more
444
00:16:23,519 --> 00:16:25,440
advanced okay
445
00:16:25,440 --> 00:16:27,199
so
446
00:16:27,199 --> 00:16:29,360
let's say we have a name here we put a
447
00:16:29,360 --> 00:16:30,880
variable and we can call variables
448
00:16:30,880 --> 00:16:32,399
everything and we'll get back to that in
449
00:16:32,399 --> 00:16:34,639
the next lesson and we put input here
450
00:16:34,639 --> 00:16:38,320
and we say what is your name right
451
00:16:38,320 --> 00:16:40,720
that's what we learned so far
452
00:16:40,720 --> 00:16:41,839
and
453
00:16:41,839 --> 00:16:44,480
look i pressed enter without executing
454
00:16:44,480 --> 00:16:46,160
now because it was just enter and then
455
00:16:46,160 --> 00:16:47,759
you have more lines you can multiple
456
00:16:47,759 --> 00:16:49,199
lines of code right
457
00:16:49,199 --> 00:16:52,079
so what we can do is print
458
00:16:52,079 --> 00:16:53,279
hello
459
00:16:53,279 --> 00:16:56,639
and then name here
460
00:16:56,639 --> 00:16:58,320
and what that does is actually prints
461
00:16:58,320 --> 00:16:59,839
the hello
462
00:16:59,839 --> 00:17:02,639
space name as we know right name is the
463
00:17:02,639 --> 00:17:04,400
one that's inputted there right now it's
464
00:17:04,400 --> 00:17:06,319
going to be funny right so now we put h
465
00:17:06,319 --> 00:17:07,119
here
466
00:17:07,119 --> 00:17:08,799
and then we do input here and what
467
00:17:08,799 --> 00:17:10,959
should we ask now
468
00:17:10,959 --> 00:17:14,000
how old are you right
469
00:17:14,000 --> 00:17:15,280
awesome
470
00:17:15,280 --> 00:17:17,439
and then we can say print
471
00:17:17,439 --> 00:17:18,799
you are
472
00:17:18,799 --> 00:17:19,839
h
473
00:17:19,839 --> 00:17:20,959
comma
474
00:17:20,959 --> 00:17:24,240
o or years old right years old
475
00:17:24,240 --> 00:17:27,280
awesome so now we've structured a few
476
00:17:27,280 --> 00:17:29,200
lines of code together right so what
477
00:17:29,200 --> 00:17:31,039
will happen now is first we'll prompt
478
00:17:31,039 --> 00:17:32,799
what is your name then we'll print
479
00:17:32,799 --> 00:17:34,720
afterwards when we get the input right
480
00:17:34,720 --> 00:17:37,200
it will wait until the input is here and
481
00:17:37,200 --> 00:17:38,880
put that value into name and then we'll
482
00:17:38,880 --> 00:17:40,720
print hello and then the name input it
483
00:17:40,720 --> 00:17:42,640
there and then we'll prompt you again
484
00:17:42,640 --> 00:17:44,799
how old are you and
485
00:17:44,799 --> 00:17:46,720
when you press enter it will put that in
486
00:17:46,720 --> 00:17:48,320
h and then it will print you are and
487
00:17:48,320 --> 00:17:51,919
then the h you enter and years old right
488
00:17:51,919 --> 00:17:54,240
so i cross my fingers this will work are
489
00:17:54,240 --> 00:17:56,960
you ready i'm ready
490
00:17:56,960 --> 00:17:59,360
how what is your name okay it's still
491
00:17:59,360 --> 00:18:02,480
luna right
492
00:18:02,480 --> 00:18:03,840
hello
493
00:18:03,840 --> 00:18:06,880
how old are you well i'm 30.
494
00:18:06,880 --> 00:18:07,760
maybe
495
00:18:07,760 --> 00:18:10,160
enter you are 30 years old at least the
496
00:18:10,160 --> 00:18:12,080
computer believes me
497
00:18:12,080 --> 00:18:15,120
i mean that yeah imagine we ran this
498
00:18:15,120 --> 00:18:17,200
program again and we wanted to make it a
499
00:18:17,200 --> 00:18:19,120
bit more advanced actually
500
00:18:19,120 --> 00:18:21,919
this name here what if he enters that in
501
00:18:21,919 --> 00:18:24,000
lower case all the way what do i mean
502
00:18:24,000 --> 00:18:26,799
right so if i execute this one again i
503
00:18:26,799 --> 00:18:28,880
just enter in lower case well what
504
00:18:28,880 --> 00:18:30,960
happens is that it says hello only in
505
00:18:30,960 --> 00:18:33,120
lower case can we make our program a bit
506
00:18:33,120 --> 00:18:35,919
smarter well let's see
507
00:18:35,919 --> 00:18:37,679
this is where functions come into the
508
00:18:37,679 --> 00:18:39,440
picture and a great way to find
509
00:18:39,440 --> 00:18:41,919
functions or methods as they are called
510
00:18:41,919 --> 00:18:44,559
on objects and a great way to find the
511
00:18:44,559 --> 00:18:47,760
methods uh is to write
512
00:18:47,760 --> 00:18:50,960
dot because that will call a method on f
513
00:18:50,960 --> 00:18:52,960
on a function and then you can see the
514
00:18:52,960 --> 00:18:54,799
functions available and the first one is
515
00:18:54,799 --> 00:18:57,280
capitalize so let's use that and then
516
00:18:57,280 --> 00:18:59,039
you call capitalize on name and then you
517
00:18:59,039 --> 00:19:00,240
need the
518
00:19:00,240 --> 00:19:03,039
brackets here in order to
519
00:19:03,039 --> 00:19:05,280
that's how you call methods okay so
520
00:19:05,280 --> 00:19:07,039
let's try to execute again and as you
521
00:19:07,039 --> 00:19:08,559
saw here you can execute the same cell
522
00:19:08,559 --> 00:19:10,480
again and again so we do that shift
523
00:19:10,480 --> 00:19:12,400
enter and it will ask you for your name
524
00:19:12,400 --> 00:19:14,799
and we do that in lower case again here
525
00:19:14,799 --> 00:19:16,320
but you see what happened now is
526
00:19:16,320 --> 00:19:18,320
actually hello honey became capital
527
00:19:18,320 --> 00:19:20,720
because capitalize what it does is it
528
00:19:20,720 --> 00:19:24,559
capitalizes the word there amazing right
529
00:19:24,559 --> 00:19:26,640
and again if you enter 30 it keeps
530
00:19:26,640 --> 00:19:29,039
continuing believing i'm 30 years old
531
00:19:29,039 --> 00:19:31,520
nice so what happened right said
532
00:19:31,520 --> 00:19:33,360
differently you can say that only here
533
00:19:33,360 --> 00:19:35,520
we have the string here una
534
00:19:35,520 --> 00:19:38,240
and we can actually we can actually
535
00:19:38,240 --> 00:19:41,840
assign that string and capitalize it
536
00:19:41,840 --> 00:19:42,799
and you can see you get the
537
00:19:42,799 --> 00:19:44,240
documentation here it returns a
538
00:19:44,240 --> 00:19:46,240
capitalized version
539
00:19:46,240 --> 00:19:48,960
of the string so again this is something
540
00:19:48,960 --> 00:19:51,280
you need to understand sometimes things
541
00:19:51,280 --> 00:19:53,600
return things sometimes they modify
542
00:19:53,600 --> 00:19:56,240
things right so returning means you need
543
00:19:56,240 --> 00:19:58,400
to assign it to a new variable right
544
00:19:58,400 --> 00:20:00,880
here it returns a capitalized version it
545
00:20:00,880 --> 00:20:02,240
doesn't matter because we use the
546
00:20:02,240 --> 00:20:04,880
returning value of this thing here but
547
00:20:04,880 --> 00:20:06,640
if you wrote
548
00:20:06,640 --> 00:20:09,039
let's just show you here if you wrote
549
00:20:09,039 --> 00:20:10,320
this here
550
00:20:10,320 --> 00:20:11,679
and then you
551
00:20:11,679 --> 00:20:14,240
print s here well
552
00:20:14,240 --> 00:20:16,320
i should actually put it with lowercase
553
00:20:16,320 --> 00:20:18,320
thank you for helping me
554
00:20:18,320 --> 00:20:19,600
well
555
00:20:19,600 --> 00:20:21,919
it does capitalize here but when you
556
00:20:21,919 --> 00:20:23,600
print it out it's lowercase again
557
00:20:23,600 --> 00:20:25,600
because it returns it so you need to
558
00:20:25,600 --> 00:20:28,080
keep the returned value and let's just
559
00:20:28,080 --> 00:20:30,960
put it in t here and then you see the
560
00:20:30,960 --> 00:20:35,039
return value is capitalized right
561
00:20:35,039 --> 00:20:36,480
so it's important to understand that
562
00:20:36,480 --> 00:20:38,799
some methods they modify things and some
563
00:20:38,799 --> 00:20:41,200
methods they return new things so you
564
00:20:41,200 --> 00:20:43,120
should be aware of that
565
00:20:43,120 --> 00:20:45,440
just a few more things right
566
00:20:45,440 --> 00:20:47,919
if you you can apply it directly on a
567
00:20:47,919 --> 00:20:51,039
string as i do here or you can do it on
568
00:20:51,039 --> 00:20:53,280
a variable containing a string right so
569
00:20:53,280 --> 00:20:56,000
let's look at some more methods here so
570
00:20:56,000 --> 00:20:57,840
just pressing tab
571
00:20:57,840 --> 00:20:59,440
and you can see a lot of methods
572
00:20:59,440 --> 00:21:02,000
available here right so let's try one
573
00:21:02,000 --> 00:21:04,240
here let's try upper what does it do
574
00:21:04,240 --> 00:21:06,000
well obviously he puts all the
575
00:21:06,000 --> 00:21:07,919
characters to upper right
576
00:21:07,919 --> 00:21:09,120
and
577
00:21:09,120 --> 00:21:10,400
we could do something it's probably
578
00:21:10,400 --> 00:21:11,840
something called lower
579
00:21:11,840 --> 00:21:13,120
and there is
580
00:21:13,120 --> 00:21:15,360
and it will lower case everything right
581
00:21:15,360 --> 00:21:17,039
and another thing is actually sometimes
582
00:21:17,039 --> 00:21:19,440
when you work with strings you want to
583
00:21:19,440 --> 00:21:23,520
know if it's a number or not right so
584
00:21:24,480 --> 00:21:27,360
is decimal
585
00:21:27,360 --> 00:21:30,720
it's a true here right well
586
00:21:30,720 --> 00:21:31,720
so
587
00:21:31,720 --> 00:21:34,720
similarly we could do on this one and
588
00:21:34,720 --> 00:21:37,840
ask if is decimal
589
00:21:37,840 --> 00:21:39,840
and you see that's false obviously right
590
00:21:39,840 --> 00:21:41,679
and this comes in handy when we learn a
591
00:21:41,679 --> 00:21:45,280
bit a bit more about programming because
592
00:21:45,280 --> 00:21:47,840
sometimes we need to convert things that
593
00:21:47,840 --> 00:21:49,760
are inside a string to an integer so
594
00:21:49,760 --> 00:21:51,600
when we learn about variables in the
595
00:21:51,600 --> 00:21:54,000
next lesson you'll learn about different
596
00:21:54,000 --> 00:21:56,000
types of
597
00:21:56,000 --> 00:21:57,360
variables
598
00:21:57,360 --> 00:21:59,520
exciting another great thing is kind of
599
00:21:59,520 --> 00:22:01,360
fun is like actually you can replace
600
00:22:01,360 --> 00:22:03,679
things so let's say we had the name here
601
00:22:03,679 --> 00:22:05,600
and we just put it to be
602
00:22:05,600 --> 00:22:07,360
here that's my name and then you can
603
00:22:07,360 --> 00:22:09,760
actually replace in the name here so
604
00:22:09,760 --> 00:22:11,919
let's try to replace here and we take
605
00:22:11,919 --> 00:22:16,240
the r and we replace that with an s
606
00:22:16,799 --> 00:22:18,400
what's going to happen should we look at
607
00:22:18,400 --> 00:22:20,960
the dock string or should you just guess
608
00:22:20,960 --> 00:22:22,960
well you guessed it right
609
00:22:22,960 --> 00:22:25,440
okay so what replace does it replaces
610
00:22:25,440 --> 00:22:28,000
the capital r with a capital s so my
611
00:22:28,000 --> 00:22:31,600
name is chained from une to soon and
612
00:22:31,600 --> 00:22:33,679
if you're unfamiliar with my region of
613
00:22:33,679 --> 00:22:37,520
the world well these two are both names
614
00:22:37,840 --> 00:22:39,360
the first one is mine the other one is
615
00:22:39,360 --> 00:22:41,280
not so a final thing i just want to show
616
00:22:41,280 --> 00:22:43,520
before we end this lesson here is
617
00:22:43,520 --> 00:22:44,799
actually
618
00:22:44,799 --> 00:22:47,520
well the print here sometimes you want
619
00:22:47,520 --> 00:22:49,600
if you noticed when you print something
620
00:22:49,600 --> 00:22:51,520
here right if you print my name here
621
00:22:51,520 --> 00:22:53,039
again here you see here it actually
622
00:22:53,039 --> 00:22:56,000
makes a new line here and sometimes
623
00:22:56,000 --> 00:22:59,039
let's make it a bit more
624
00:23:01,679 --> 00:23:03,919
you see here it prints it on a new lines
625
00:23:03,919 --> 00:23:05,679
sometimes you want to print on the same
626
00:23:05,679 --> 00:23:07,200
line and you don't want to use the same
627
00:23:07,200 --> 00:23:09,200
print statement so what you can do is
628
00:23:09,200 --> 00:23:10,799
put this end here and then you can
629
00:23:10,799 --> 00:23:12,960
actually say what should the string end
630
00:23:12,960 --> 00:23:15,200
with by default it ends with a new line
631
00:23:15,200 --> 00:23:17,120
but if you put nothing in here as you
632
00:23:17,120 --> 00:23:19,120
see here and we execute that it will
633
00:23:19,120 --> 00:23:21,120
actually not put a new line it will just
634
00:23:21,120 --> 00:23:22,880
put nothing here right so now it says
635
00:23:22,880 --> 00:23:25,760
una and sooner but the problem now is
636
00:23:25,760 --> 00:23:27,520
right okay you wanted the space well you
637
00:23:27,520 --> 00:23:29,280
can actually just say it should end with
638
00:23:29,280 --> 00:23:32,640
a space and it adds a space but
639
00:23:32,640 --> 00:23:35,120
the end here is actually overriding the
640
00:23:35,120 --> 00:23:38,480
default value of a new line right okay
641
00:23:38,480 --> 00:23:41,440
amazing so let's just walk very fast
642
00:23:41,440 --> 00:23:43,520
through so let's just check very fast
643
00:23:43,520 --> 00:23:45,440
what we did we did we learned a bit
644
00:23:45,440 --> 00:23:46,799
about python we learned about jupiter
645
00:23:46,799 --> 00:23:49,120
notebooks how to execute cells and we
646
00:23:49,120 --> 00:23:51,360
can execute cells again we learned about
647
00:23:51,360 --> 00:23:53,279
input and print statements we learned
648
00:23:53,279 --> 00:23:55,600
about how to capitalize lower actually
649
00:23:55,600 --> 00:23:58,320
also upper and is decimal and
650
00:23:58,320 --> 00:24:01,039
replace and finally with the print here
651
00:24:01,039 --> 00:24:03,120
we also learned how to avoid the new
652
00:24:03,120 --> 00:24:05,039
line which is actually quite handy often
653
00:24:05,039 --> 00:24:06,240
when we program
654
00:24:06,240 --> 00:24:09,279
so the next thing is well you need to
655
00:24:09,279 --> 00:24:11,840
get started with your first first
656
00:24:11,840 --> 00:24:14,159
project so i'll just cue you in a moment
657
00:24:14,159 --> 00:24:16,880
i'll help you to get started and after
658
00:24:16,880 --> 00:24:19,600
you solve it yourself well i'll solve it
659
00:24:19,600 --> 00:24:21,360
together with you as well so see you in
660
00:24:21,360 --> 00:24:23,760
a moment
661
00:24:26,159 --> 00:24:27,520
so here i'm going to introduce you to
662
00:24:27,520 --> 00:24:29,360
the first project
663
00:24:29,360 --> 00:24:31,840
and don't worry i'll not show any code
664
00:24:31,840 --> 00:24:34,080
in this one i'll show you how to solve
665
00:24:34,080 --> 00:24:36,480
it or how i would solve it in the next
666
00:24:36,480 --> 00:24:39,440
one so first let's get into jupiter
667
00:24:39,440 --> 00:24:41,679
notebook and see what it says so you
668
00:24:41,679 --> 00:24:43,520
should be in the jupyter notebook called
669
00:24:43,520 --> 00:24:46,559
zero zero projects so 0 projects
670
00:24:46,559 --> 00:24:48,640
identifies this first project and it's
671
00:24:48,640 --> 00:24:50,480
called input and output strings right
672
00:24:50,480 --> 00:24:52,320
here as it says here input and output
673
00:24:52,320 --> 00:24:53,679
strings
674
00:24:53,679 --> 00:24:55,760
so the goal of this one here is
675
00:24:55,760 --> 00:24:57,279
explained here the goal is to get to
676
00:24:57,279 --> 00:24:58,960
know jupiter notebook and execute your
677
00:24:58,960 --> 00:25:00,960
first program
678
00:25:00,960 --> 00:25:03,679
right it's not really programs but it's
679
00:25:03,679 --> 00:25:04,559
small
680
00:25:04,559 --> 00:25:07,520
code snippets so just to get started
681
00:25:07,520 --> 00:25:09,200
right
682
00:25:09,200 --> 00:25:11,520
so description here of what to do well
683
00:25:11,520 --> 00:25:13,760
this project is in three steps and you
684
00:25:13,760 --> 00:25:14,480
should
685
00:25:14,480 --> 00:25:17,039
do them step by step and the purpose is
686
00:25:17,039 --> 00:25:18,400
still just to get comfortable with
687
00:25:18,400 --> 00:25:21,279
jupiter notebook okay are you ready i am
688
00:25:21,279 --> 00:25:24,000
okay so the first one is
689
00:25:24,000 --> 00:25:25,760
just to make sure that we're on the same
690
00:25:25,760 --> 00:25:28,080
page and you try to do your first print
691
00:25:28,080 --> 00:25:30,960
hello world program do that and execute
692
00:25:30,960 --> 00:25:33,520
the cell right so you know how to use a
693
00:25:33,520 --> 00:25:35,200
jupiter notebook and get comfortable
694
00:25:35,200 --> 00:25:36,400
about that
695
00:25:36,400 --> 00:25:38,799
then in the next step here when you've
696
00:25:38,799 --> 00:25:40,400
done that the first step well the next
697
00:25:40,400 --> 00:25:42,320
step here you should use input to get
698
00:25:42,320 --> 00:25:44,159
the name of the user and print hello and
699
00:25:44,159 --> 00:25:46,240
then the name of the user right again
700
00:25:46,240 --> 00:25:48,640
it's very easy you've seen me doing it
701
00:25:48,640 --> 00:25:50,880
but often there's a difference between
702
00:25:50,880 --> 00:25:52,640
seeing people doing it and actually
703
00:25:52,640 --> 00:25:54,640
doing it yourself sometimes there's
704
00:25:54,640 --> 00:25:57,039
small details you don't notice trust me
705
00:25:57,039 --> 00:25:58,960
i've been there i just like seen people
706
00:25:58,960 --> 00:26:01,039
doing stuff and it's like that's easy i
707
00:26:01,039 --> 00:26:03,200
can do that myself but when i'm sitting
708
00:26:03,200 --> 00:26:05,840
at the computer myself then suddenly
709
00:26:05,840 --> 00:26:07,919
it's difficult and there's some details
710
00:26:07,919 --> 00:26:09,039
you didn't see
711
00:26:09,039 --> 00:26:11,600
you first learn programming when you do
712
00:26:11,600 --> 00:26:14,480
it yourself right
713
00:26:14,480 --> 00:26:16,880
step three
714
00:26:16,880 --> 00:26:18,400
use the input to get the name of the
715
00:26:18,400 --> 00:26:21,520
user print i like capital letter and the
716
00:26:21,520 --> 00:26:23,840
name capitalize by using upper right
717
00:26:23,840 --> 00:26:26,159
remember upper
718
00:26:26,159 --> 00:26:28,559
returned everything in capital right
719
00:26:28,559 --> 00:26:30,080
so
720
00:26:30,080 --> 00:26:32,880
are you ready i think this is what you
721
00:26:32,880 --> 00:26:36,080
should do and if you're
722
00:26:36,080 --> 00:26:38,480
if you need help in the next one i'll
723
00:26:38,480 --> 00:26:41,600
show you how i would solve it and
724
00:26:41,600 --> 00:26:44,559
hopefully that will get you started with
725
00:26:44,559 --> 00:26:46,799
jupiter notebook trying to execute some
726
00:26:46,799 --> 00:26:48,960
code yourself and see it's actually not
727
00:26:48,960 --> 00:26:51,200
that difficult
728
00:26:51,200 --> 00:26:52,799
i'm ready
729
00:26:52,799 --> 00:26:54,720
i'm ready i hope you're ready take some
730
00:26:54,720 --> 00:26:57,279
time and finish this off and i'll see
731
00:26:57,279 --> 00:27:00,080
you in the next one
732
00:27:02,159 --> 00:27:04,480
so in this one we're gonna solve the
733
00:27:04,480 --> 00:27:07,440
project together i know it seems easy
734
00:27:07,440 --> 00:27:09,279
and you might think well this is too
735
00:27:09,279 --> 00:27:11,919
easy i know what he's doing but i still
736
00:27:11,919 --> 00:27:14,320
advise you to do it especially if you
737
00:27:14,320 --> 00:27:16,720
haven't done any programming before it
738
00:27:16,720 --> 00:27:19,679
is crucial to get some experience okay
739
00:27:19,679 --> 00:27:21,919
are you ready i'm ready let's get
740
00:27:21,919 --> 00:27:23,520
started
741
00:27:23,520 --> 00:27:24,320
so
742
00:27:24,320 --> 00:27:27,039
again we jump straight down to step one
743
00:27:27,039 --> 00:27:29,360
here and make your first print hello
744
00:27:29,360 --> 00:27:31,760
world program right so what was that
745
00:27:31,760 --> 00:27:34,399
remember the lesson it is basically to
746
00:27:34,399 --> 00:27:37,200
tell the computer to print hello world
747
00:27:37,200 --> 00:27:39,440
and if you read the docu if you read the
748
00:27:39,440 --> 00:27:41,039
story you will also probably know that
749
00:27:41,039 --> 00:27:44,159
it's not as simple as in python as
750
00:27:44,159 --> 00:27:46,880
you've seen here so let's try to do it
751
00:27:46,880 --> 00:27:48,640
right so you need the print statement
752
00:27:48,640 --> 00:27:50,480
here
753
00:27:50,480 --> 00:27:51,520
and
754
00:27:51,520 --> 00:27:53,039
the print statement
755
00:27:53,039 --> 00:27:55,039
will print every string you want so i
756
00:27:55,039 --> 00:27:56,960
used double quotes before i'll just show
757
00:27:56,960 --> 00:27:58,960
you you can also use single quotes and
758
00:27:58,960 --> 00:28:02,480
it will do the same right hello world
759
00:28:02,480 --> 00:28:05,120
comma world capitalized and exclamation
760
00:28:05,120 --> 00:28:07,120
mark and how you execute it you can
761
00:28:07,120 --> 00:28:11,360
either press run up here or you can
762
00:28:11,360 --> 00:28:14,640
execute it by shift enter here you go
763
00:28:14,640 --> 00:28:16,960
you see that wasn't that difficult was
764
00:28:16,960 --> 00:28:19,039
it
765
00:28:20,080 --> 00:28:23,840
okay step two use input to get the name
766
00:28:23,840 --> 00:28:25,919
from the user and print hello and the
767
00:28:25,919 --> 00:28:28,320
name from the user right
768
00:28:28,320 --> 00:28:30,799
it seems doable let's try to do that
769
00:28:30,799 --> 00:28:34,000
together so help me here the input from
770
00:28:34,000 --> 00:28:36,640
the user right you use input but let's
771
00:28:36,640 --> 00:28:39,440
just try to do it right input
772
00:28:39,440 --> 00:28:41,200
what is your name
773
00:28:41,200 --> 00:28:42,880
it's always good to ask and we can use
774
00:28:42,880 --> 00:28:45,039
the comma here so
775
00:28:45,039 --> 00:28:47,039
what we're doing here right now is we
776
00:28:47,039 --> 00:28:49,039
want the name now prompt the name right
777
00:28:49,039 --> 00:28:50,799
and now we need to print it so let's
778
00:28:50,799 --> 00:28:52,559
print
779
00:28:52,559 --> 00:28:55,760
hello comma
780
00:28:55,760 --> 00:28:57,520
but there's a problem right we cannot
781
00:28:57,520 --> 00:28:59,279
print the name now because we don't know
782
00:28:59,279 --> 00:29:01,440
what they typed in so what you needed to
783
00:29:01,440 --> 00:29:04,720
remember is to have a variable here we
784
00:29:04,720 --> 00:29:06,159
can call it name
785
00:29:06,159 --> 00:29:08,960
and then we say hello name here right
786
00:29:08,960 --> 00:29:10,559
and now it should work right because the
787
00:29:10,559 --> 00:29:12,960
key thing is the input here is stored in
788
00:29:12,960 --> 00:29:15,120
the name right remember it executes
789
00:29:15,120 --> 00:29:19,360
executes the right size right side first
790
00:29:19,360 --> 00:29:21,840
and then it stores the value in the left
791
00:29:21,840 --> 00:29:24,559
side of an equation here right so now we
792
00:29:24,559 --> 00:29:26,559
have the value of name
793
00:29:26,559 --> 00:29:28,559
and we can print it let's try it
794
00:29:28,559 --> 00:29:31,679
together right are you excited let's try
795
00:29:31,679 --> 00:29:34,480
shift enter boom what is your name
796
00:29:34,480 --> 00:29:36,240
what is your name
797
00:29:36,240 --> 00:29:38,320
i can't hear sorry i'm
798
00:29:38,320 --> 00:29:41,120
i'll use my name right
799
00:29:41,120 --> 00:29:42,240
hello
800
00:29:42,240 --> 00:29:43,840
oh it works and i'm pretty sure it
801
00:29:43,840 --> 00:29:45,679
worked for your name as well and i'm
802
00:29:45,679 --> 00:29:47,279
pretty sure your name is not owner
803
00:29:47,279 --> 00:29:49,360
because you're not from denmark are you
804
00:29:49,360 --> 00:29:51,200
i'm in denmark actually this name is
805
00:29:51,200 --> 00:29:52,960
also used in some other
806
00:29:52,960 --> 00:29:55,600
countries but
807
00:29:55,600 --> 00:29:58,240
mainly in denmark
808
00:29:58,240 --> 00:30:00,960
step three use the input to get the name
809
00:30:00,960 --> 00:30:02,720
from the user that was actually the same
810
00:30:02,720 --> 00:30:05,039
thing we did up here print i like
811
00:30:05,039 --> 00:30:08,240
capital letter and the name
812
00:30:08,240 --> 00:30:09,760
of the user
813
00:30:09,760 --> 00:30:11,520
so let's try to do that
814
00:30:11,520 --> 00:30:15,520
so again we know we take name input
815
00:30:15,520 --> 00:30:17,600
what is your
816
00:30:17,600 --> 00:30:18,880
your name
817
00:30:18,880 --> 00:30:20,080
question mark
818
00:30:20,080 --> 00:30:22,880
and then we can print and i'm kind of
819
00:30:22,880 --> 00:30:25,440
lazy here right so i just copy this one
820
00:30:25,440 --> 00:30:27,440
here shift copy
821
00:30:27,440 --> 00:30:30,559
insert it here and then comma name
822
00:30:30,559 --> 00:30:31,520
so
823
00:30:31,520 --> 00:30:33,840
if i just do like that it will just
824
00:30:33,840 --> 00:30:36,399
output it as i type it in and we don't
825
00:30:36,399 --> 00:30:38,559
want that we want it to be an upper so
826
00:30:38,559 --> 00:30:41,360
we use this upper function here right so
827
00:30:41,360 --> 00:30:44,080
now we're ready let's try it
828
00:30:44,080 --> 00:30:45,600
name what is your name i'll put it in
829
00:30:45,600 --> 00:30:47,919
all lowercase now because i'm lazy
830
00:30:47,919 --> 00:30:51,279
and i say i like capital letters
831
00:30:51,279 --> 00:30:52,320
okay
832
00:30:52,320 --> 00:30:54,559
so far so good and that was actually it
833
00:30:54,559 --> 00:30:56,480
right that wasn't that scary now we
834
00:30:56,480 --> 00:30:58,799
actually solved the first simple project
835
00:30:58,799 --> 00:31:00,880
together this is the most simple project
836
00:31:00,880 --> 00:31:03,120
it will get more and more advanced along
837
00:31:03,120 --> 00:31:06,159
the way so don't worry let's get to the
838
00:31:06,159 --> 00:31:07,760
next lesson where we're going to learn
839
00:31:07,760 --> 00:31:10,559
about variables
840
00:31:10,559 --> 00:31:12,480
interesting what are variables and
841
00:31:12,480 --> 00:31:15,279
different data types right
842
00:31:15,279 --> 00:31:17,200
maybe you kind of
843
00:31:17,200 --> 00:31:19,600
i i was kind of hinting at their
844
00:31:19,600 --> 00:31:21,519
different data types so let's get into
845
00:31:21,519 --> 00:31:23,440
that are you excited i am let's get
846
00:31:23,440 --> 00:31:25,919
started
847
00:31:28,480 --> 00:31:30,159
in the last lesson we learned how to
848
00:31:30,159 --> 00:31:33,200
input an output and interact with the
849
00:31:33,200 --> 00:31:35,600
user of the program in this one we're
850
00:31:35,600 --> 00:31:38,159
gonna learn about variables and that
851
00:31:38,159 --> 00:31:40,000
actually means we need to learn a bit
852
00:31:40,000 --> 00:31:43,360
about data types okay so let's jump into
853
00:31:43,360 --> 00:31:45,679
jupiter notebook and get started
854
00:31:45,679 --> 00:31:48,480
variables what are variables actually
855
00:31:48,480 --> 00:31:50,880
well a variable is a reserved memory
856
00:31:50,880 --> 00:31:53,200
location what
857
00:31:53,200 --> 00:31:55,919
well said differently if you think of
858
00:31:55,919 --> 00:31:56,880
the
859
00:31:56,880 --> 00:31:59,760
computer has a storage in memory right
860
00:31:59,760 --> 00:32:01,679
and like your brain and it's kind of
861
00:32:01,679 --> 00:32:03,840
like a variable that points as a
862
00:32:03,840 --> 00:32:06,960
specific memory in your brain right ha
863
00:32:06,960 --> 00:32:08,799
that's how it does and a computer is
864
00:32:08,799 --> 00:32:10,799
similar right it just points a specific
865
00:32:10,799 --> 00:32:13,200
area and it says i remember this piece
866
00:32:13,200 --> 00:32:14,799
of information that's what a variable
867
00:32:14,799 --> 00:32:16,960
does
868
00:32:16,960 --> 00:32:19,039
a variable in python program gives a
869
00:32:19,039 --> 00:32:20,799
data to the computer for processing
870
00:32:20,799 --> 00:32:23,120
right as we already saw when we put the
871
00:32:23,120 --> 00:32:25,279
input right we executed the input
872
00:32:25,279 --> 00:32:28,480
statement well it put a value
873
00:32:28,480 --> 00:32:30,960
the user input into a variable called
874
00:32:30,960 --> 00:32:33,120
for instance a name right and this is
875
00:32:33,120 --> 00:32:36,559
the location it points at and stores it
876
00:32:36,559 --> 00:32:38,640
and this is what we can use to process
877
00:32:38,640 --> 00:32:41,279
data inside a program without variables
878
00:32:41,279 --> 00:32:43,200
programs would be pretty boring i would
879
00:32:43,200 --> 00:32:44,720
say
880
00:32:44,720 --> 00:32:47,600
so we need to cover some basic data
881
00:32:47,600 --> 00:32:50,080
types and the basic ones that we are
882
00:32:50,080 --> 00:32:52,320
going to cover are integers floats
883
00:32:52,320 --> 00:32:55,200
strings and booleans there are actually
884
00:32:55,200 --> 00:32:57,360
also complex numbers in python but other
885
00:32:57,360 --> 00:32:59,600
than that these are the basic data types
886
00:32:59,600 --> 00:33:01,120
complex numbers
887
00:33:01,120 --> 00:33:02,480
if you don't know about them don't worry
888
00:33:02,480 --> 00:33:03,919
about them you'll probably never use
889
00:33:03,919 --> 00:33:06,320
them then
890
00:33:06,720 --> 00:33:10,799
before we get started actually with
891
00:33:10,799 --> 00:33:13,039
variables there's something called the
892
00:33:13,039 --> 00:33:16,559
python variable name convention so why
893
00:33:16,559 --> 00:33:19,039
is that so first of all if you just go
894
00:33:19,039 --> 00:33:21,039
crazy and call your
895
00:33:21,039 --> 00:33:22,960
variable names whatever you want
896
00:33:22,960 --> 00:33:25,919
capitalize lower cases up cases and
897
00:33:25,919 --> 00:33:27,279
how you like it
898
00:33:27,279 --> 00:33:30,159
well the code becomes less readable for
899
00:33:30,159 --> 00:33:32,080
other people that is kind of a
900
00:33:32,080 --> 00:33:35,200
convention that we do our names of
901
00:33:35,200 --> 00:33:37,360
variables are like this because then it
902
00:33:37,360 --> 00:33:38,720
makes it easier for other people to
903
00:33:38,720 --> 00:33:40,399
understand what is this this is a
904
00:33:40,399 --> 00:33:42,320
variable because it's this structure
905
00:33:42,320 --> 00:33:44,720
right so what are the rules right uh use
906
00:33:44,720 --> 00:33:46,399
lowercase only
907
00:33:46,399 --> 00:33:48,320
separate words with underscore these are
908
00:33:48,320 --> 00:33:50,480
the main rules right a variable name in
909
00:33:50,480 --> 00:33:53,120
python can be a single lowercase letter
910
00:33:53,120 --> 00:33:55,600
that is like x and i here a lowercase
911
00:33:55,600 --> 00:33:59,200
word word like cars here or a lowercase
912
00:33:59,200 --> 00:34:01,519
words or lowercase words separated by
913
00:34:01,519 --> 00:34:04,080
underscore like my cars right example of
914
00:34:04,080 --> 00:34:06,720
variables like here so finally i just
915
00:34:06,720 --> 00:34:08,320
want to mention that
916
00:34:08,320 --> 00:34:10,320
other programming languages can have
917
00:34:10,320 --> 00:34:13,520
other naming conver conventions right if
918
00:34:13,520 --> 00:34:15,199
you're probably
919
00:34:15,199 --> 00:34:17,359
familiar with something like
920
00:34:17,359 --> 00:34:19,440
java for instance you know that they
921
00:34:19,440 --> 00:34:22,000
love the first word is lowercase then
922
00:34:22,000 --> 00:34:23,679
you separate the words with uppercase
923
00:34:23,679 --> 00:34:26,159
words don't worry about it just keep to
924
00:34:26,159 --> 00:34:27,918
this these are also described in the
925
00:34:27,918 --> 00:34:30,239
ebook that i highly encourage you to
926
00:34:30,239 --> 00:34:31,520
download
927
00:34:31,520 --> 00:34:33,918
good so how do you declare variables
928
00:34:33,918 --> 00:34:36,239
well basically we already know that
929
00:34:36,239 --> 00:34:39,520
right so let's just try it here so let's
930
00:34:39,520 --> 00:34:42,719
try a few ones here right so s
931
00:34:42,719 --> 00:34:47,199
this is a string right
932
00:34:47,199 --> 00:34:48,879
a
933
00:34:48,879 --> 00:34:51,320
assigned to 2 and b assigned to
934
00:34:51,320 --> 00:34:52,480
[Music]
935
00:34:52,480 --> 00:34:56,159
2.3 or 4 it became okay so these are
936
00:34:56,159 --> 00:34:58,000
variables right
937
00:34:58,000 --> 00:34:59,599
so these are all storing things but as
938
00:34:59,599 --> 00:35:02,079
you probably know here right these are
939
00:35:02,079 --> 00:35:04,160
different things we're storing right
940
00:35:04,160 --> 00:35:06,400
we're storing 2 here and 2.4 here and
941
00:35:06,400 --> 00:35:08,560
this is a string so these are some of
942
00:35:08,560 --> 00:35:10,320
the basic data types that we're going to
943
00:35:10,320 --> 00:35:12,640
work with so how can you get a data type
944
00:35:12,640 --> 00:35:14,400
well there's a built-in function called
945
00:35:14,400 --> 00:35:16,560
type as you see here when i type
946
00:35:16,560 --> 00:35:18,800
type it becomes green it signals that
947
00:35:18,800 --> 00:35:20,079
this is a built-in function and you
948
00:35:20,079 --> 00:35:22,079
shouldn't use it for anything else so if
949
00:35:22,079 --> 00:35:23,920
you take the type of
950
00:35:23,920 --> 00:35:27,119
s it will say well i'm a string right
951
00:35:27,119 --> 00:35:29,680
if you take the type of a it will say
952
00:35:29,680 --> 00:35:32,240
well i'm an int an int is an integer
953
00:35:32,240 --> 00:35:34,960
right and if you take the type of b it
954
00:35:34,960 --> 00:35:38,160
will say well i'm a float right let's
955
00:35:38,160 --> 00:35:40,960
just leave the boolean out for a moment
956
00:35:40,960 --> 00:35:42,960
and just start with these and the
957
00:35:42,960 --> 00:35:45,920
boolean is a bit different right
958
00:35:45,920 --> 00:35:47,760
i think booleans are often something
959
00:35:47,760 --> 00:35:48,800
that people have a hard time to
960
00:35:48,800 --> 00:35:50,400
understand the first time they see it
961
00:35:50,400 --> 00:35:52,960
but and why they're useful
962
00:35:52,960 --> 00:35:55,599
these booleans is a key thing actually
963
00:35:55,599 --> 00:35:59,119
and you will know why later
964
00:35:59,119 --> 00:36:02,240
so let's get started so integers right
965
00:36:02,240 --> 00:36:04,640
so what are integers an integer is a
966
00:36:04,640 --> 00:36:06,400
number which is a fraction a whole
967
00:36:06,400 --> 00:36:07,359
number
968
00:36:07,359 --> 00:36:11,440
examples of integers minus 23 minus 5 0
969
00:36:11,440 --> 00:36:13,200
seventy eight one million nine hundred
970
00:36:13,200 --> 00:36:15,359
eighty thousand three hundred fifties
971
00:36:15,359 --> 00:36:16,720
are integers
972
00:36:16,720 --> 00:36:19,040
examples of non-integer integers right
973
00:36:19,040 --> 00:36:20,800
these are not integers three point one
974
00:36:20,800 --> 00:36:23,520
four zero point zero zero one nine
975
00:36:23,520 --> 00:36:25,599
thousand nine hundred ninety nine dot
976
00:36:25,599 --> 00:36:26,400
nine
977
00:36:26,400 --> 00:36:28,720
these are not integers right
978
00:36:28,720 --> 00:36:29,680
so
979
00:36:29,680 --> 00:36:31,839
let's just play around with that for a
980
00:36:31,839 --> 00:36:34,000
moment right so imagine we have two
981
00:36:34,000 --> 00:36:35,680
integers a
982
00:36:35,680 --> 00:36:36,800
and
983
00:36:36,800 --> 00:36:37,839
b
984
00:36:37,839 --> 00:36:39,440
two and three doesn't matter what they
985
00:36:39,440 --> 00:36:41,599
are these are integers right so let's
986
00:36:41,599 --> 00:36:45,520
just ensure that they are type a
987
00:36:45,520 --> 00:36:47,920
and you can actually comma separate here
988
00:36:47,920 --> 00:36:50,079
sometimes you do that
989
00:36:50,079 --> 00:36:52,000
and it will return that they are both
990
00:36:52,000 --> 00:36:53,359
ins right
991
00:36:53,359 --> 00:36:55,280
so a isn't it and b and z i would just
992
00:36:55,280 --> 00:36:56,880
put it on the same line here to get them
993
00:36:56,880 --> 00:36:58,160
both here right
994
00:36:58,160 --> 00:36:59,920
don't worry about this details here
995
00:36:59,920 --> 00:37:01,760
we're not really going to use it
996
00:37:01,760 --> 00:37:04,160
so don't worry about it okay so what i
997
00:37:04,160 --> 00:37:06,800
want to show you is actually you can add
998
00:37:06,800 --> 00:37:10,320
two integers right so you take a plus
999
00:37:10,320 --> 00:37:12,720
a plus b here you'll see that becomes
1000
00:37:12,720 --> 00:37:15,680
five obviously but what is a plus b well
1001
00:37:15,680 --> 00:37:18,880
we can actually try that by type a plus
1002
00:37:18,880 --> 00:37:20,320
e b
1003
00:37:20,320 --> 00:37:22,160
and you say that's an integer right so
1004
00:37:22,160 --> 00:37:23,680
put it more strictly you could say you
1005
00:37:23,680 --> 00:37:26,400
can assign a new variable a now c which
1006
00:37:26,400 --> 00:37:28,880
is equals a plus b and what is the type
1007
00:37:28,880 --> 00:37:31,599
of c well it is an integer right so what
1008
00:37:31,599 --> 00:37:33,760
we learned here is actually that when we
1009
00:37:33,760 --> 00:37:37,599
add two integers it adds like we know it
1010
00:37:37,599 --> 00:37:39,920
should add why do i say that well we'll
1011
00:37:39,920 --> 00:37:43,440
see later right not always add is adding
1012
00:37:43,440 --> 00:37:45,280
when it comes to strings it's something
1013
00:37:45,280 --> 00:37:46,240
different
1014
00:37:46,240 --> 00:37:48,079
and when we add two integers it becomes
1015
00:37:48,079 --> 00:37:49,680
an integer
1016
00:37:49,680 --> 00:37:52,400
so far so good let's move on to the next
1017
00:37:52,400 --> 00:37:53,599
data type
1018
00:37:53,599 --> 00:37:55,280
floats
1019
00:37:55,280 --> 00:37:57,440
what
1020
00:37:57,440 --> 00:38:00,160
a float is a number
1021
00:38:00,160 --> 00:38:02,480
with digits on both sides of a decimal
1022
00:38:02,480 --> 00:38:05,520
point this is in contrast to the integer
1023
00:38:05,520 --> 00:38:08,079
data type which houses an integer or a
1024
00:38:08,079 --> 00:38:09,280
whole number
1025
00:38:09,280 --> 00:38:16,200
example of floats 3.13 9.99 0.0001
1026
00:38:16,320 --> 00:38:18,160
note that float data in python can
1027
00:38:18,160 --> 00:38:20,880
represent a whole number like zero point
1028
00:38:20,880 --> 00:38:22,640
now one point zero or three point zero
1029
00:38:22,640 --> 00:38:23,440
right
1030
00:38:23,440 --> 00:38:26,960
so let's try the same thing here a
1031
00:38:26,960 --> 00:38:29,520
one point one
1032
00:38:29,520 --> 00:38:31,240
b
1033
00:38:31,240 --> 00:38:34,000
2.3 okay
1034
00:38:34,000 --> 00:38:36,480
and just to ensure that they are both
1035
00:38:36,480 --> 00:38:38,079
floats a
1036
00:38:38,079 --> 00:38:40,480
type b
1037
00:38:40,480 --> 00:38:43,119
float float right and
1038
00:38:43,119 --> 00:38:46,960
we expect the same here type a plus b
1039
00:38:46,960 --> 00:38:49,760
it's a float should we also just look at
1040
00:38:49,760 --> 00:38:50,800
what
1041
00:38:50,800 --> 00:38:53,599
a plus b is equal to well it's equal to
1042
00:38:53,599 --> 00:38:57,760
3.4 is that surprising 1.1
1043
00:38:57,760 --> 00:39:00,480
plus 2.3 no it's not surprising that's
1044
00:39:00,480 --> 00:39:02,400
correct
1045
00:39:02,400 --> 00:39:03,920
but i want to
1046
00:39:03,920 --> 00:39:05,920
i want to show a few things more here
1047
00:39:05,920 --> 00:39:08,240
and you can actually add in more cells
1048
00:39:08,240 --> 00:39:10,480
by adding the plus sign here so let's do
1049
00:39:10,480 --> 00:39:12,560
that here so for instance
1050
00:39:12,560 --> 00:39:15,119
imagine actually we have a variable
1051
00:39:15,119 --> 00:39:17,520
which is an integer called i
1052
00:39:17,520 --> 00:39:19,200
equals one right
1053
00:39:19,200 --> 00:39:22,400
type of i is integer right so now we
1054
00:39:22,400 --> 00:39:23,280
know
1055
00:39:23,280 --> 00:39:26,240
but what happens if we take type of i
1056
00:39:26,240 --> 00:39:27,760
plus b
1057
00:39:27,760 --> 00:39:28,880
or a
1058
00:39:28,880 --> 00:39:31,440
so we add here an integer and a float
1059
00:39:31,440 --> 00:39:33,280
let's see what happens well it becomes a
1060
00:39:33,280 --> 00:39:34,800
float
1061
00:39:34,800 --> 00:39:37,599
interesting right
1062
00:39:37,920 --> 00:39:39,280
so
1063
00:39:39,280 --> 00:39:41,200
i plus a
1064
00:39:41,200 --> 00:39:44,560
becomes 2.1 it calculates correct but in
1065
00:39:44,560 --> 00:39:46,560
the calculation it actually converts the
1066
00:39:46,560 --> 00:39:48,560
integer to a float so this is nice to
1067
00:39:48,560 --> 00:39:52,720
know right awesome so far so good
1068
00:39:52,720 --> 00:39:54,160
those were floats
1069
00:39:54,160 --> 00:39:55,760
now let's try to look at the math
1070
00:39:55,760 --> 00:39:57,520
functions here right so i just wanted to
1071
00:39:57,520 --> 00:39:59,280
share a few ones here because there are
1072
00:39:59,280 --> 00:40:00,880
lots of them but these are like built-in
1073
00:40:00,880 --> 00:40:03,119
and they're nice to know absolute the
1074
00:40:03,119 --> 00:40:04,000
power
1075
00:40:04,000 --> 00:40:06,000
and rounding right so we can return the
1076
00:40:06,000 --> 00:40:07,599
absolute value the absolute value is
1077
00:40:07,599 --> 00:40:10,000
just making positive to negatives and so
1078
00:40:10,000 --> 00:40:10,800
on
1079
00:40:10,800 --> 00:40:12,560
so not positive to negatives what i'm
1080
00:40:12,560 --> 00:40:14,400
talking about so abs
1081
00:40:14,400 --> 00:40:16,560
here if we take minus 2 here for
1082
00:40:16,560 --> 00:40:18,319
instance it returns 2. and then we have
1083
00:40:18,319 --> 00:40:21,440
the power here power here we can take 2
1084
00:40:21,440 --> 00:40:23,599
to the power 3 for instance that's 8
1085
00:40:23,599 --> 00:40:26,480
here as you see so 2 times 2 is 4 times
1086
00:40:26,480 --> 00:40:28,880
2 is 8 right so that's what the power
1087
00:40:28,880 --> 00:40:30,400
does it's pretty nice to have that in
1088
00:40:30,400 --> 00:40:32,400
one here i can actually reveal that you
1089
00:40:32,400 --> 00:40:34,240
can actually do that also by multiply
1090
00:40:34,240 --> 00:40:37,200
multiply 3 right so multiply multiply
1091
00:40:37,200 --> 00:40:40,240
means the power 2 as well right but
1092
00:40:40,240 --> 00:40:42,240
again what should you choose well it
1093
00:40:42,240 --> 00:40:44,240
depends also on you if you're familiar
1094
00:40:44,240 --> 00:40:45,839
with this one and you're comfortable
1095
00:40:45,839 --> 00:40:48,240
about that well use this one if you
1096
00:40:48,240 --> 00:40:50,000
don't understand this one well this one
1097
00:40:50,000 --> 00:40:51,839
is more readable what happens here right
1098
00:40:51,839 --> 00:40:55,920
and again readable readability counts
1099
00:40:55,920 --> 00:40:57,920
finally round i find that one very
1100
00:40:57,920 --> 00:41:00,640
interesting right so for instance if you
1101
00:41:00,640 --> 00:41:03,359
took round here and you take
1102
00:41:03,359 --> 00:41:06,960
two point or just a 3.14
1103
00:41:06,960 --> 00:41:09,599
and we round it by one what happens it
1104
00:41:09,599 --> 00:41:11,440
rounds the value right this is this is
1105
00:41:11,440 --> 00:41:12,880
really cool so it rounds a floating
1106
00:41:12,880 --> 00:41:14,960
point so let's take another one here so
1107
00:41:14,960 --> 00:41:18,560
let's take a float here and say 1.2
1108
00:41:18,560 --> 00:41:21,760
oh i can't have multiple
1109
00:41:21,760 --> 00:41:23,200
here we go
1110
00:41:23,200 --> 00:41:24,960
and uh
1111
00:41:24,960 --> 00:41:28,160
let's round this one here around here f
1112
00:41:28,160 --> 00:41:30,240
and what it does is write how many
1113
00:41:30,240 --> 00:41:32,240
digits should we keep i mean let's in
1114
00:41:32,240 --> 00:41:33,680
this case keep
1115
00:41:33,680 --> 00:41:34,800
four
1116
00:41:34,800 --> 00:41:37,520
and we see here it rounds
1117
00:41:37,520 --> 00:41:40,240
two three four five so two three four
1118
00:41:40,240 --> 00:41:42,480
four but it rounds the four to a five
1119
00:41:42,480 --> 00:41:44,400
because we have a five afterwards right
1120
00:41:44,400 --> 00:41:46,480
you know the rounding rules you do
1121
00:41:46,480 --> 00:41:48,400
awesome okay good
1122
00:41:48,400 --> 00:41:50,880
so far so good
1123
00:41:50,880 --> 00:41:52,560
so let's go to strings here and there
1124
00:41:52,560 --> 00:41:53,839
are just a few things i want to show
1125
00:41:53,839 --> 00:41:56,240
here as it already emphasized that we
1126
00:41:56,240 --> 00:41:57,839
talked about you can have a string with
1127
00:41:57,839 --> 00:41:59,760
double quotes and single quotes it
1128
00:41:59,760 --> 00:42:01,280
doesn't really matter right so let's
1129
00:42:01,280 --> 00:42:04,880
have two strings now here
1130
00:42:04,880 --> 00:42:09,359
i am a string and we have s2 here
1131
00:42:09,359 --> 00:42:12,880
double quotes i am another
1132
00:42:12,880 --> 00:42:14,240
string right
1133
00:42:14,240 --> 00:42:16,400
good so what happens if we add them
1134
00:42:16,400 --> 00:42:18,800
together s1 plus s2
1135
00:42:18,800 --> 00:42:21,520
well it concatenates them right so you
1136
00:42:21,520 --> 00:42:23,280
see here i am a string i am another
1137
00:42:23,280 --> 00:42:24,640
string right and
1138
00:42:24,640 --> 00:42:26,160
notice here there is no space between
1139
00:42:26,160 --> 00:42:27,680
here because there is no space between
1140
00:42:27,680 --> 00:42:30,480
here so that's what addition does i told
1141
00:42:30,480 --> 00:42:32,400
you addition does different things well
1142
00:42:32,400 --> 00:42:33,280
i'm
1143
00:42:33,280 --> 00:42:34,960
curious now right
1144
00:42:34,960 --> 00:42:37,040
aren't you i'm curious what happens with
1145
00:42:37,040 --> 00:42:40,400
we have an integer now a 1 here let's
1146
00:42:40,400 --> 00:42:43,599
execute that one and we take s1 and plus
1147
00:42:43,599 --> 00:42:45,040
a
1148
00:42:45,040 --> 00:42:45,920
well
1149
00:42:45,920 --> 00:42:48,319
we get something called type error
1150
00:42:48,319 --> 00:42:49,839
and this is kind of scary in the
1151
00:42:49,839 --> 00:42:51,920
beginning you see this red thing here
1152
00:42:51,920 --> 00:42:53,520
and something goes wrong and you don't
1153
00:42:53,520 --> 00:42:55,920
know what to do don't worry about it we
1154
00:42:55,920 --> 00:42:58,800
as a program you see this so many times
1155
00:42:58,800 --> 00:43:02,000
per day it will become
1156
00:43:02,000 --> 00:43:03,440
bread and butter for you to read these
1157
00:43:03,440 --> 00:43:05,200
things but in the beginning you don't
1158
00:43:05,200 --> 00:43:06,880
know what you to look for right so it
1159
00:43:06,880 --> 00:43:08,800
says type error so that means probably
1160
00:43:08,800 --> 00:43:10,720
something with the types there can only
1161
00:43:10,720 --> 00:43:13,280
concatenate string not int to string
1162
00:43:13,280 --> 00:43:14,800
right so we take a string and try to
1163
00:43:14,800 --> 00:43:16,960
concatenate it to an end right so it
1164
00:43:16,960 --> 00:43:18,560
says we can only concatenate string to
1165
00:43:18,560 --> 00:43:19,839
string so
1166
00:43:19,839 --> 00:43:22,079
what if i wanted to print out something
1167
00:43:22,079 --> 00:43:24,000
like that well this is actually where i
1168
00:43:24,000 --> 00:43:25,359
want to show you something else called
1169
00:43:25,359 --> 00:43:28,079
the formatted string right so i'll just
1170
00:43:28,079 --> 00:43:29,920
shortly introduce it there and a
1171
00:43:29,920 --> 00:43:31,920
formatted string is actually a string
1172
00:43:31,920 --> 00:43:34,160
where you put an f in front for format
1173
00:43:34,160 --> 00:43:36,000
so i am
1174
00:43:36,000 --> 00:43:36,960
a
1175
00:43:36,960 --> 00:43:38,079
string
1176
00:43:38,079 --> 00:43:39,280
with an
1177
00:43:39,280 --> 00:43:42,560
int here and how you can put it in is
1178
00:43:42,560 --> 00:43:44,480
use curly brackets and put the variable
1179
00:43:44,480 --> 00:43:46,800
in here which is called a here and then
1180
00:43:46,800 --> 00:43:48,880
you actually have that a is put in here
1181
00:43:48,880 --> 00:43:50,319
and you can have string something
1182
00:43:50,319 --> 00:43:51,599
afterwards here
1183
00:43:51,599 --> 00:43:54,079
and more text
1184
00:43:54,079 --> 00:43:54,960
right
1185
00:43:54,960 --> 00:43:57,280
so as you see here it outputs the one
1186
00:43:57,280 --> 00:43:59,440
here so now we can actually add an
1187
00:43:59,440 --> 00:44:02,000
integer inside the string here by using
1188
00:44:02,000 --> 00:44:04,160
this formatted here and formatted is
1189
00:44:04,160 --> 00:44:05,920
really really nice to use and you can
1190
00:44:05,920 --> 00:44:07,599
have multiple variables in here and you
1191
00:44:07,599 --> 00:44:09,520
can actually also make calculations in
1192
00:44:09,520 --> 00:44:11,440
here you can actually add 2 here and
1193
00:44:11,440 --> 00:44:14,160
then we'll execute this expression in
1194
00:44:14,160 --> 00:44:16,319
here and return that as a value here as
1195
00:44:16,319 --> 00:44:19,200
you see because a is 1 remember and
1196
00:44:19,200 --> 00:44:22,400
added 2 it's 3 1 plus two is three yeah
1197
00:44:22,400 --> 00:44:22,720
it is
1198
00:44:22,720 --> 00:44:24,319
[Laughter]
1199
00:44:24,319 --> 00:44:27,680
awesome right so here we have it right
1200
00:44:27,680 --> 00:44:30,000
this is amazing okay so these were just
1201
00:44:30,000 --> 00:44:31,920
a few things i wanted to show you and
1202
00:44:31,920 --> 00:44:33,920
don't worry about not remembering
1203
00:44:33,920 --> 00:44:36,400
everything here there's an e-book
1204
00:44:36,400 --> 00:44:38,880
did you download it you should
1205
00:44:38,880 --> 00:44:39,760
good
1206
00:44:39,760 --> 00:44:41,920
boolean
1207
00:44:41,920 --> 00:44:43,839
so booleans are kind of funny right it's
1208
00:44:43,839 --> 00:44:44,560
like
1209
00:44:44,560 --> 00:44:48,079
true and false booleans are used to
1210
00:44:48,079 --> 00:44:50,800
actually make program flows to decide
1211
00:44:50,800 --> 00:44:53,359
either do this or that right
1212
00:44:53,359 --> 00:44:54,400
but
1213
00:44:54,400 --> 00:44:56,480
often people say well the world is not
1214
00:44:56,480 --> 00:44:58,720
that black and white and that might be
1215
00:44:58,720 --> 00:45:00,560
true and computer programs are often
1216
00:45:00,560 --> 00:45:02,880
black and white and i'll say yeah but in
1217
00:45:02,880 --> 00:45:05,760
the end you are the same right for
1218
00:45:05,760 --> 00:45:08,319
instance does it rain and you say ah
1219
00:45:08,319 --> 00:45:10,880
it's not real rain it's like in between
1220
00:45:10,880 --> 00:45:13,359
i can't really answer that but in the
1221
00:45:13,359 --> 00:45:15,680
end either you take your umbrella or you
1222
00:45:15,680 --> 00:45:16,880
don't
1223
00:45:16,880 --> 00:45:20,240
right that's the programming so you make
1224
00:45:20,240 --> 00:45:21,839
some kind of decision based on that and
1225
00:45:21,839 --> 00:45:23,920
you can model that logic maybe you don't
1226
00:45:23,920 --> 00:45:26,560
model it as easy as you do in your brain
1227
00:45:26,560 --> 00:45:28,640
with a computer program but in the end
1228
00:45:28,640 --> 00:45:31,119
the outcome of it is black and white
1229
00:45:31,119 --> 00:45:34,319
either you took the umbrella or not
1230
00:45:34,319 --> 00:45:36,720
there's nothing in between you cannot
1231
00:45:36,720 --> 00:45:38,800
it's not quantum physics this year where
1232
00:45:38,800 --> 00:45:40,640
you are in between states and i'm not
1233
00:45:40,640 --> 00:45:42,400
into quantum physics i don't understand
1234
00:45:42,400 --> 00:45:45,040
that kind of stuff right we are still in
1235
00:45:45,040 --> 00:45:47,520
the old type of world without quantum
1236
00:45:47,520 --> 00:45:49,680
physics states where everything just
1237
00:45:49,680 --> 00:45:50,960
splatters around and you don't know
1238
00:45:50,960 --> 00:45:53,920
what's happening in this world good
1239
00:45:53,920 --> 00:45:55,040
so
1240
00:45:55,040 --> 00:45:56,720
when people criticize this black and
1241
00:45:56,720 --> 00:45:58,000
white thinking
1242
00:45:58,000 --> 00:46:01,040
false and true thinking well in the end
1243
00:46:01,040 --> 00:46:03,040
the outcome is always like that in your
1244
00:46:03,040 --> 00:46:05,520
life as well so what are the booleans
1245
00:46:05,520 --> 00:46:09,200
well it's true and it's
1246
00:46:11,440 --> 00:46:13,680
and it's false
1247
00:46:13,680 --> 00:46:15,760
so you can execute them right and they
1248
00:46:15,760 --> 00:46:17,760
return it and notice please note there's
1249
00:46:17,760 --> 00:46:19,520
a capital here it's important that you
1250
00:46:19,520 --> 00:46:22,720
use capital true and capital capital s t
1251
00:46:22,720 --> 00:46:24,960
and capital f in true and false
1252
00:46:24,960 --> 00:46:26,000
so
1253
00:46:26,000 --> 00:46:28,400
what can this do for you well it's like
1254
00:46:28,400 --> 00:46:30,000
you can assign that to a variable as
1255
00:46:30,000 --> 00:46:32,079
well right so you have a true variable
1256
00:46:32,079 --> 00:46:35,359
here you can execute that variable here
1257
00:46:35,359 --> 00:46:37,359
and it returns true but you can also
1258
00:46:37,359 --> 00:46:39,520
execute something and we'll get
1259
00:46:39,520 --> 00:46:41,440
back to more of that later so don't
1260
00:46:41,440 --> 00:46:43,359
worry but you can have an expression
1261
00:46:43,359 --> 00:46:47,280
like here right so 10 is greater than 5
1262
00:46:47,280 --> 00:46:49,839
right and we execute that and then b is
1263
00:46:49,839 --> 00:46:50,960
true
1264
00:46:50,960 --> 00:46:52,960
so as you see here what's happening here
1265
00:46:52,960 --> 00:46:55,839
again with an equal sign we execute this
1266
00:46:55,839 --> 00:46:58,480
right side of the equation 10 is larger
1267
00:46:58,480 --> 00:47:00,160
than 5 and that's true right so we
1268
00:47:00,160 --> 00:47:02,400
execute that and assign that to b so b
1269
00:47:02,400 --> 00:47:03,760
becomes true
1270
00:47:03,760 --> 00:47:05,040
if you want to play more around with
1271
00:47:05,040 --> 00:47:06,720
that you can use this bool function
1272
00:47:06,720 --> 00:47:08,319
again it becomes green here because it's
1273
00:47:08,319 --> 00:47:10,240
a built in function and you can try to
1274
00:47:10,240 --> 00:47:12,880
do your statements right so you can say
1275
00:47:12,880 --> 00:47:16,400
2 is larger than
1276
00:47:16,400 --> 00:47:17,200
4
1277
00:47:17,200 --> 00:47:18,800
that's false right and then you can
1278
00:47:18,800 --> 00:47:21,280
still play around with that right
1279
00:47:21,280 --> 00:47:23,440
i know right now we covered so many
1280
00:47:23,440 --> 00:47:24,880
things so i'm not going to put more on
1281
00:47:24,880 --> 00:47:26,720
that and again don't worry if you don't
1282
00:47:26,720 --> 00:47:28,079
remember it you're not supposed to
1283
00:47:28,079 --> 00:47:29,359
remember
1284
00:47:29,359 --> 00:47:31,280
all these things by heart
1285
00:47:31,280 --> 00:47:33,119
you will when you use it on a daily
1286
00:47:33,119 --> 00:47:34,960
basis but in the beginning don't worry
1287
00:47:34,960 --> 00:47:36,800
we've all been there we'll you need to
1288
00:47:36,800 --> 00:47:38,880
look up everything we're on as a
1289
00:47:38,880 --> 00:47:40,640
programmer with more experience it's
1290
00:47:40,640 --> 00:47:42,319
just different things you look ups but
1291
00:47:42,319 --> 00:47:44,240
you always be looking things up because
1292
00:47:44,240 --> 00:47:46,400
you don't remember everything by heart
1293
00:47:46,400 --> 00:47:47,200
okay
1294
00:47:47,200 --> 00:47:48,960
so don't worry about it so what did we
1295
00:47:48,960 --> 00:47:51,760
cover well basically we covered what
1296
00:47:51,760 --> 00:47:53,359
variables are
1297
00:47:53,359 --> 00:47:55,359
the basic data types integer floats
1298
00:47:55,359 --> 00:47:57,760
strings and booleans and
1299
00:47:57,760 --> 00:47:59,760
now you should be ready to make the
1300
00:47:59,760 --> 00:48:01,599
project i'll introduce the project in
1301
00:48:01,599 --> 00:48:04,400
the next one and are you excited i am so
1302
00:48:04,400 --> 00:48:07,800
let's get started
1303
00:48:09,520 --> 00:48:13,200
making projects is the best way to learn
1304
00:48:13,200 --> 00:48:15,119
you need to get your fingers dirty you
1305
00:48:15,119 --> 00:48:17,040
need to type in code even though you
1306
00:48:17,040 --> 00:48:19,599
think you remember stuff often it turns
1307
00:48:19,599 --> 00:48:21,680
out it's a bit more complex than you
1308
00:48:21,680 --> 00:48:25,599
think because programmers no programs
1309
00:48:25,599 --> 00:48:28,240
need to be 100 accurate because a
1310
00:48:28,240 --> 00:48:30,480
computer doesn't have any guesswork it
1311
00:48:30,480 --> 00:48:32,160
cannot guess what you're thinking you
1312
00:48:32,160 --> 00:48:35,359
need to type it in 100 accurate
1313
00:48:35,359 --> 00:48:38,000
so that's why it's very important to try
1314
00:48:38,000 --> 00:48:40,240
these things because it will ensure you
1315
00:48:40,240 --> 00:48:43,359
have all the details correct so
1316
00:48:43,359 --> 00:48:45,200
are you excited let's introduce this
1317
00:48:45,200 --> 00:48:46,720
project here and in the next one i'm
1318
00:48:46,720 --> 00:48:49,760
going to show you how i would solve it
1319
00:48:49,760 --> 00:48:51,119
so in this one
1320
00:48:51,119 --> 00:48:54,400
we need to do some basic calculations we
1321
00:48:54,400 --> 00:48:56,880
need to be in a stage where we do stuff
1322
00:48:56,880 --> 00:48:58,240
we know
1323
00:48:58,240 --> 00:49:00,880
so we should have learned anything so
1324
00:49:00,880 --> 00:49:03,280
so we don't use anything we don't know
1325
00:49:03,280 --> 00:49:04,160
right
1326
00:49:04,160 --> 00:49:04,960
good
1327
00:49:04,960 --> 00:49:07,119
so the goal is to
1328
00:49:07,119 --> 00:49:09,839
use jupiter notebook as a massive
1329
00:49:09,839 --> 00:49:12,160
calculator basically and understand how
1330
00:49:12,160 --> 00:49:14,400
cells keep track of calculations
1331
00:49:14,400 --> 00:49:16,559
so the description is create some
1332
00:49:16,559 --> 00:49:18,800
formulas and have some fun with basic
1333
00:49:18,800 --> 00:49:20,240
math okay
1334
00:49:20,240 --> 00:49:22,400
are you ready so the first one here so
1335
00:49:22,400 --> 00:49:24,079
again we have some steps in this one
1336
00:49:24,079 --> 00:49:26,400
here and step one is making a conversion
1337
00:49:26,400 --> 00:49:29,119
from kilograms to pounds
1338
00:49:29,119 --> 00:49:31,680
so we use this formula here for pounds
1339
00:49:31,680 --> 00:49:34,680
that it is kilograms multiplied by
1340
00:49:34,680 --> 00:49:38,079
2.2046 that's very accurate right
1341
00:49:38,079 --> 00:49:38,880
so
1342
00:49:38,880 --> 00:49:41,839
as we already know this right this was a
1343
00:49:41,839 --> 00:49:43,839
float here at least and then multiplying
1344
00:49:43,839 --> 00:49:45,200
with a
1345
00:49:45,200 --> 00:49:46,720
and if you put an integer in the
1346
00:49:46,720 --> 00:49:48,559
kilograms with a float it will become a
1347
00:49:48,559 --> 00:49:51,119
float as you can check
1348
00:49:51,119 --> 00:49:53,359
so make the cell and use some variables
1349
00:49:53,359 --> 00:49:55,200
right so you need to use variables in
1350
00:49:55,200 --> 00:49:58,319
this one this is also a goal right so
1351
00:49:58,319 --> 00:50:02,240
that one are you comfortable try it out
1352
00:50:02,240 --> 00:50:03,760
step two
1353
00:50:03,760 --> 00:50:06,400
make calculations of circumference of a
1354
00:50:06,400 --> 00:50:07,839
circle
1355
00:50:07,839 --> 00:50:10,160
the cell should be defined
1356
00:50:10,160 --> 00:50:12,400
should define the radius right so we
1357
00:50:12,400 --> 00:50:13,359
need to
1358
00:50:13,359 --> 00:50:15,119
make a radius and then we use the
1359
00:50:15,119 --> 00:50:17,839
following formula that the circumference
1360
00:50:17,839 --> 00:50:22,480
is 2 times pi times r and we use
1361
00:50:22,480 --> 00:50:25,119
pi to be 3.14
1362
00:50:25,119 --> 00:50:27,359
and use a variable name pi right
1363
00:50:27,359 --> 00:50:29,359
it's difficult to use this character the
1364
00:50:29,359 --> 00:50:31,280
pi character here in programming you
1365
00:50:31,280 --> 00:50:32,800
will know that
1366
00:50:32,800 --> 00:50:33,520
and
1367
00:50:33,520 --> 00:50:35,440
then let the cell return the
1368
00:50:35,440 --> 00:50:37,359
circumference right so are you
1369
00:50:37,359 --> 00:50:39,040
comfortable about that so you need to
1370
00:50:39,040 --> 00:50:40,880
make a variable you need to make this
1371
00:50:40,880 --> 00:50:42,480
calculation you need to have another
1372
00:50:42,480 --> 00:50:44,640
variable called pi probably create it
1373
00:50:44,640 --> 00:50:46,160
before you
1374
00:50:46,160 --> 00:50:47,680
create this formula here and then you
1375
00:50:47,680 --> 00:50:50,000
should return the circumference okay
1376
00:50:50,000 --> 00:50:52,880
ready good
1377
00:50:52,880 --> 00:50:54,640
step three
1378
00:50:54,640 --> 00:50:57,599
assign a variable to any number
1379
00:50:57,599 --> 00:50:59,760
this is kind of a fun thing actually any
1380
00:50:59,760 --> 00:51:04,240
number your choice and my advice hmm
1381
00:51:04,240 --> 00:51:06,800
take your favorite number okay it should
1382
00:51:06,800 --> 00:51:08,960
be an integer though okay
1383
00:51:08,960 --> 00:51:11,680
multiply the number by three
1384
00:51:11,680 --> 00:51:13,599
so you do that on another line
1385
00:51:13,599 --> 00:51:16,000
add six to the result from bullet two
1386
00:51:16,000 --> 00:51:17,280
another line
1387
00:51:17,280 --> 00:51:19,520
divide the number by three another line
1388
00:51:19,520 --> 00:51:21,359
subtract the number from bullet one the
1389
00:51:21,359 --> 00:51:23,040
one you put here right
1390
00:51:23,040 --> 00:51:25,040
and from the answer
1391
00:51:25,040 --> 00:51:26,800
from bullet four right so you just take
1392
00:51:26,800 --> 00:51:28,720
this number and subtract one
1393
00:51:28,720 --> 00:51:31,680
and then the answer is two what the
1394
00:51:31,680 --> 00:51:34,720
answer is two what yeah i know this is
1395
00:51:34,720 --> 00:51:37,760
kind of fun right so try it out and try
1396
00:51:37,760 --> 00:51:39,520
to see if you can figure out why this is
1397
00:51:39,520 --> 00:51:41,760
the case right why does it become two
1398
00:51:41,760 --> 00:51:44,079
it's just fun right just having fun with
1399
00:51:44,079 --> 00:51:47,280
math okay that's it i'm excited are you
1400
00:51:47,280 --> 00:51:49,280
excited you should be let's get started
1401
00:51:49,280 --> 00:51:51,680
let's let's do this okay first you do it
1402
00:51:51,680 --> 00:51:54,079
on your own and when you get stuck let's
1403
00:51:54,079 --> 00:51:56,800
continue in the next lesson or the next
1404
00:51:56,800 --> 00:51:59,200
lesson the next part where i'm going to
1405
00:51:59,200 --> 00:52:01,359
show you how i would solve these three
1406
00:52:01,359 --> 00:52:05,839
steps okay are you ready i'm ready
1407
00:52:08,240 --> 00:52:09,119
so
1408
00:52:09,119 --> 00:52:11,760
did you try it yourself you should don't
1409
00:52:11,760 --> 00:52:14,240
cheat yourself this is an opportunity
1410
00:52:14,240 --> 00:52:16,079
where you work with it first and then
1411
00:52:16,079 --> 00:52:17,920
you see how i would solve it even though
1412
00:52:17,920 --> 00:52:19,599
you get stuck and you get frustrated we
1413
00:52:19,599 --> 00:52:21,440
all been there trust me i've been
1414
00:52:21,440 --> 00:52:23,440
sitting with problems i couldn't solve
1415
00:52:23,440 --> 00:52:25,119
and you're just like how do you do that
1416
00:52:25,119 --> 00:52:27,040
when then you see the solution just like
1417
00:52:27,040 --> 00:52:29,200
wow is it that simple and he's like how
1418
00:52:29,200 --> 00:52:31,280
couldn't i figure that one out but trust
1419
00:52:31,280 --> 00:52:33,359
me over time you will in the beginning
1420
00:52:33,359 --> 00:52:34,960
everything is new and everything is
1421
00:52:34,960 --> 00:52:37,599
complex but it will become easier i
1422
00:52:37,599 --> 00:52:39,200
promise you that the only thing you have
1423
00:52:39,200 --> 00:52:42,640
to do is to keep on working and actually
1424
00:52:42,640 --> 00:52:44,800
the more time you spend trying yourself
1425
00:52:44,800 --> 00:52:46,400
even though you don't succeed
1426
00:52:46,400 --> 00:52:49,040
the more you learn i actually realized
1427
00:52:49,040 --> 00:52:51,040
that the more time i spent trying to
1428
00:52:51,040 --> 00:52:52,720
solve something and then seeing the
1429
00:52:52,720 --> 00:52:55,359
solution the more i learned from that
1430
00:52:55,359 --> 00:52:56,720
that means if i got the solution
1431
00:52:56,720 --> 00:52:58,480
immediately without trying myself i
1432
00:52:58,480 --> 00:52:59,839
would forget it the next day it will be
1433
00:52:59,839 --> 00:53:02,559
all gone but if i spent hours maybe
1434
00:53:02,559 --> 00:53:04,720
sometimes days trying to solve something
1435
00:53:04,720 --> 00:53:06,319
and then i got the solution i would
1436
00:53:06,319 --> 00:53:08,400
remember it for i would say almost
1437
00:53:08,400 --> 00:53:09,680
forever
1438
00:53:09,680 --> 00:53:11,200
wow
1439
00:53:11,200 --> 00:53:13,839
now that's an incentive for trying out
1440
00:53:13,839 --> 00:53:16,559
things yourself let's get started though
1441
00:53:16,559 --> 00:53:18,480
i hope you tried it i hope you spent
1442
00:53:18,480 --> 00:53:21,599
some time and now let's get started
1443
00:53:21,599 --> 00:53:22,880
so remember
1444
00:53:22,880 --> 00:53:24,960
we just jumped down to step one and
1445
00:53:24,960 --> 00:53:27,280
let's get started with that one so make
1446
00:53:27,280 --> 00:53:30,480
a conversion from kilograms to pounds
1447
00:53:30,480 --> 00:53:33,119
right we have the formula here and we
1448
00:53:33,119 --> 00:53:35,520
should use variables right so let's make
1449
00:53:35,520 --> 00:53:37,760
a kilogram variable here and let's just
1450
00:53:37,760 --> 00:53:40,839
start with the fun kilograms of four
1451
00:53:40,839 --> 00:53:43,200
right so
1452
00:53:43,200 --> 00:53:45,200
now we actually have the formula here so
1453
00:53:45,200 --> 00:53:46,960
basically what we need to do is to type
1454
00:53:46,960 --> 00:53:50,880
that in actually so lbs equals kilograms
1455
00:53:50,880 --> 00:53:52,640
actually there's a misspelling here i
1456
00:53:52,640 --> 00:53:55,520
can see here it says kb it should be k
1457
00:53:55,520 --> 00:53:57,839
k g here i apologize for that it will
1458
00:53:57,839 --> 00:54:00,800
probably be corrected when you do it
1459
00:54:00,800 --> 00:54:02,079
okay
1460
00:54:02,079 --> 00:54:05,720
times 2.2046
1461
00:54:06,079 --> 00:54:09,200
so again remember multiplication is by
1462
00:54:09,200 --> 00:54:13,760
this asterisk here right and not by nx
1463
00:54:13,760 --> 00:54:16,160
and then we should return it lbs right
1464
00:54:16,160 --> 00:54:18,079
so here we have it right so this is
1465
00:54:18,079 --> 00:54:20,000
actually how you do it and you then you
1466
00:54:20,000 --> 00:54:21,920
can change actually we put one kilo here
1467
00:54:21,920 --> 00:54:24,160
how much should that be well one kilo is
1468
00:54:24,160 --> 00:54:28,000
by the definition 2.2046
1469
00:54:28,000 --> 00:54:30,559
pounds right and then you can add up
1470
00:54:30,559 --> 00:54:33,119
here and you see here the variable is a
1471
00:54:33,119 --> 00:54:34,400
float here even though you put an
1472
00:54:34,400 --> 00:54:35,760
integer here right
1473
00:54:35,760 --> 00:54:38,480
that's how it converts okay good step
1474
00:54:38,480 --> 00:54:40,799
one done
1475
00:54:40,799 --> 00:54:44,240
step two are you ready
1476
00:54:44,640 --> 00:54:46,400
make calculations
1477
00:54:46,400 --> 00:54:49,280
to find the circumference of a circle
1478
00:54:49,280 --> 00:54:51,440
the cell should define the radius let's
1479
00:54:51,440 --> 00:54:54,400
just start doing that right so for short
1480
00:54:54,400 --> 00:54:56,559
we just use r so the radius of our
1481
00:54:56,559 --> 00:54:59,520
circle is 2.5
1482
00:54:59,520 --> 00:55:01,599
how do i know that i just chose that
1483
00:55:01,599 --> 00:55:03,680
value myself you can choose your value
1484
00:55:03,680 --> 00:55:04,799
if you want
1485
00:55:04,799 --> 00:55:06,400
good that was one
1486
00:55:06,400 --> 00:55:08,319
calculate the circumference by the
1487
00:55:08,319 --> 00:55:09,680
formula
1488
00:55:09,680 --> 00:55:13,839
c equals 2 times pi times r
1489
00:55:13,839 --> 00:55:16,160
we don't have pi but it says actually to
1490
00:55:16,160 --> 00:55:18,839
define pi air to be
1491
00:55:18,839 --> 00:55:21,960
3.14 so let's do that first
1492
00:55:21,960 --> 00:55:25,040
3.14 and then we take the formula c
1493
00:55:25,040 --> 00:55:25,920
times
1494
00:55:25,920 --> 00:55:27,280
2
1495
00:55:27,280 --> 00:55:28,400
times
1496
00:55:28,400 --> 00:55:31,200
pi times r and let's return the
1497
00:55:31,200 --> 00:55:32,960
circumference as it says in the last
1498
00:55:32,960 --> 00:55:35,040
bullet execute
1499
00:55:35,040 --> 00:55:36,480
wow
1500
00:55:36,480 --> 00:55:39,480
15.7001
1501
00:55:39,920 --> 00:55:41,359
so
1502
00:55:41,359 --> 00:55:43,359
often you will see these small
1503
00:55:43,359 --> 00:55:46,000
discrepancies with a long
1504
00:55:46,000 --> 00:55:48,720
row of zeros and one or a long row of
1505
00:55:48,720 --> 00:55:51,520
nines and this is due to
1506
00:55:51,520 --> 00:55:54,559
programming that actually sometimes
1507
00:55:54,559 --> 00:55:56,640
it does some rounding along the way and
1508
00:55:56,640 --> 00:55:58,160
it becomes a bit
1509
00:55:58,160 --> 00:56:01,119
inaccurate and this is a common problem
1510
00:56:01,119 --> 00:56:03,280
and that's not a common problem it's
1511
00:56:03,280 --> 00:56:05,440
that's how programming is it's not 100
1512
00:56:05,440 --> 00:56:08,160
accurate as you know it but most of the
1513
00:56:08,160 --> 00:56:09,520
time you won't notice like this one here
1514
00:56:09,520 --> 00:56:11,920
it looks fine but as you saw before you
1515
00:56:11,920 --> 00:56:13,359
can get something like that don't worry
1516
00:56:13,359 --> 00:56:14,720
about it it's
1517
00:56:14,720 --> 00:56:17,680
how it is
1518
00:56:17,680 --> 00:56:19,200
so
1519
00:56:19,200 --> 00:56:21,440
that was
1520
00:56:21,440 --> 00:56:23,920
circumvents step three let's get started
1521
00:56:23,920 --> 00:56:25,280
here
1522
00:56:25,280 --> 00:56:27,520
so let's try this one assign a variable
1523
00:56:27,520 --> 00:56:28,880
to any number
1524
00:56:28,880 --> 00:56:31,599
i'll take one number
1525
00:56:31,599 --> 00:56:32,720
number
1526
00:56:32,720 --> 00:56:34,319
23
1527
00:56:34,319 --> 00:56:37,200
it's not gonna guess my 23. okay
1528
00:56:37,200 --> 00:56:40,240
so now we have assigned a variable 223
1529
00:56:40,240 --> 00:56:42,319
multiply the number by three
1530
00:56:42,319 --> 00:56:43,200
okay
1531
00:56:43,200 --> 00:56:45,599
so number
1532
00:56:45,599 --> 00:56:47,440
and then we need to store that number
1533
00:56:47,440 --> 00:56:49,520
and multiply that by three right so we
1534
00:56:49,520 --> 00:56:52,079
take the number here we take the number
1535
00:56:52,079 --> 00:56:54,160
and multiply by three right so we take
1536
00:56:54,160 --> 00:56:57,200
this number which it's trying to guess
1537
00:56:57,200 --> 00:56:58,880
and then
1538
00:56:58,880 --> 00:57:00,799
are trying to do something
1539
00:57:00,799 --> 00:57:01,599
and
1540
00:57:01,599 --> 00:57:04,319
multiply that by 3 right so we have a
1541
00:57:04,319 --> 00:57:05,760
new
1542
00:57:05,760 --> 00:57:07,599
level here
1543
00:57:07,599 --> 00:57:10,000
so add 6
1544
00:57:10,000 --> 00:57:13,680
add 6 to the result from bullet two
1545
00:57:13,680 --> 00:57:16,559
okay number
1546
00:57:16,559 --> 00:57:17,520
num
1547
00:57:17,520 --> 00:57:21,280
number plus six okay perfect
1548
00:57:21,280 --> 00:57:24,400
divide this number by three okay
1549
00:57:24,400 --> 00:57:25,520
number
1550
00:57:25,520 --> 00:57:27,119
equals num
1551
00:57:27,119 --> 00:57:29,280
number divided by three
1552
00:57:29,280 --> 00:57:30,559
okay
1553
00:57:30,559 --> 00:57:33,200
subtract the number from bullet one
1554
00:57:33,200 --> 00:57:36,079
from the answer and pull it to four so
1555
00:57:36,079 --> 00:57:37,760
okay
1556
00:57:37,760 --> 00:57:39,200
number
1557
00:57:39,200 --> 00:57:42,559
number minus 23 right
1558
00:57:42,559 --> 00:57:44,720
and then it says the answer is two so
1559
00:57:44,720 --> 00:57:47,520
let's get that out here
1560
00:57:47,520 --> 00:57:50,640
number two
1561
00:57:51,520 --> 00:57:54,400
interesting and uh
1562
00:57:54,400 --> 00:57:56,079
i'll leave the fun for you to figure out
1563
00:57:56,079 --> 00:57:57,599
why this is the case
1564
00:57:57,599 --> 00:57:59,920
but uh i'll just try to change this
1565
00:57:59,920 --> 00:58:01,839
number to something else
1566
00:58:01,839 --> 00:58:04,480
it's 56 it's
1567
00:58:04,480 --> 00:58:06,000
oh then i also have to change it down
1568
00:58:06,000 --> 00:58:08,079
here 56.
1569
00:58:08,079 --> 00:58:09,920
i just got confused there a moment right
1570
00:58:09,920 --> 00:58:12,480
and you see it becomes two again right
1571
00:58:12,480 --> 00:58:14,400
so for the curious one it says it says
1572
00:58:14,400 --> 00:58:16,960
2.0 while everything here seems to be
1573
00:58:16,960 --> 00:58:18,960
integers right why is that
1574
00:58:18,960 --> 00:58:21,520
well actually the division here
1575
00:58:21,520 --> 00:58:23,440
it converts
1576
00:58:23,440 --> 00:58:25,119
it to a float so when you divide
1577
00:58:25,119 --> 00:58:26,559
something right
1578
00:58:26,559 --> 00:58:28,960
uh even you you even though you divide
1579
00:58:28,960 --> 00:58:32,079
by an integer it will return a float so
1580
00:58:32,079 --> 00:58:33,680
that's why it's a float down here so
1581
00:58:33,680 --> 00:58:36,400
everything up until here are integers
1582
00:58:36,400 --> 00:58:38,480
but here it becomes float and then it
1583
00:58:38,480 --> 00:58:41,280
continues as a float
1584
00:58:41,280 --> 00:58:43,440
so now you know okay
1585
00:58:43,440 --> 00:58:46,079
wasn't this crazy so
1586
00:58:46,079 --> 00:58:48,559
this is amazing right
1587
00:58:48,559 --> 00:58:51,040
are you ready for the next step i am so
1588
00:58:51,040 --> 00:58:53,119
let's continue our journey together see
1589
00:58:53,119 --> 00:58:55,680
you in a moment
1590
00:58:58,640 --> 00:59:00,880
in the last lesson we learned about data
1591
00:59:00,880 --> 00:59:04,319
types integers floats strings booleans
1592
00:59:04,319 --> 00:59:07,040
right but sometimes you need to convert
1593
00:59:07,040 --> 00:59:08,480
a data types
1594
00:59:08,480 --> 00:59:10,720
for instance say you have a string right
1595
00:59:10,720 --> 00:59:12,640
but you know there's an integer inside
1596
00:59:12,640 --> 00:59:15,280
that string how do you convert that to a
1597
00:59:15,280 --> 00:59:16,720
integer right that string with the
1598
00:59:16,720 --> 00:59:18,799
integer inside to an integer how do you
1599
00:59:18,799 --> 00:59:21,760
do that well don't worry obviously other
1600
00:59:21,760 --> 00:59:23,599
people have the same problem let's try
1601
00:59:23,599 --> 00:59:25,520
to dive into a specific problem and try
1602
00:59:25,520 --> 00:59:27,839
to solve that so let's jump to jupyter
1603
00:59:27,839 --> 00:59:31,040
notebook and get started in this lesson
1604
00:59:31,040 --> 00:59:33,200
here we'll look at type conventions
1605
00:59:33,200 --> 00:59:35,040
we'll learn a bit more about formatted
1606
00:59:35,040 --> 00:59:36,799
strings to become more comfortable about
1607
00:59:36,799 --> 00:59:39,040
that and
1608
00:59:39,040 --> 00:59:41,040
we know that types are not the same we
1609
00:59:41,040 --> 00:59:43,599
already know that but we'll re-look at
1610
00:59:43,599 --> 00:59:45,040
that again
1611
00:59:45,040 --> 00:59:46,640
and then we'll learn how to convert them
1612
00:59:46,640 --> 00:59:48,720
within float and string these are
1613
00:59:48,720 --> 00:59:51,440
built-in functions that we are familiar
1614
00:59:51,440 --> 00:59:52,480
with
1615
00:59:52,480 --> 00:59:54,160
we're already familiar with the concept
1616
00:59:54,160 --> 00:59:55,119
of
1617
00:59:55,119 --> 00:59:57,119
built-in functions and these are also
1618
00:59:57,119 --> 01:00:00,799
good to have in your repository
1619
01:00:00,799 --> 01:00:01,520
so
1620
01:00:01,520 --> 01:00:03,359
let's get started with a specific
1621
01:00:03,359 --> 01:00:05,520
problem as you all we already know we
1622
01:00:05,520 --> 01:00:08,000
know how to query the person for the
1623
01:00:08,000 --> 01:00:08,720
name
1624
01:00:08,720 --> 01:00:10,799
what is your name
1625
01:00:10,799 --> 01:00:12,559
question mark and we put a space here
1626
01:00:12,559 --> 01:00:14,880
and we want to assign that to a variable
1627
01:00:14,880 --> 01:00:16,559
let's call it name
1628
01:00:16,559 --> 01:00:18,880
and now also to get more comfortable
1629
01:00:18,880 --> 01:00:20,960
about formatted string let's use that
1630
01:00:20,960 --> 01:00:22,960
immediately so print
1631
01:00:22,960 --> 01:00:25,599
format string with this f in front here
1632
01:00:25,599 --> 01:00:27,200
right so we have a formatted string and
1633
01:00:27,200 --> 01:00:29,040
then you have the quotes afterwards and
1634
01:00:29,040 --> 01:00:30,720
just say hello
1635
01:00:30,720 --> 01:00:32,240
hello
1636
01:00:32,240 --> 01:00:34,079
and we'll put the variable name here
1637
01:00:34,079 --> 01:00:36,240
name and exclamation mark what that does
1638
01:00:36,240 --> 01:00:38,400
is it prints hello and whatever you
1639
01:00:38,400 --> 01:00:40,720
typed in an exclamation mark right after
1640
01:00:40,720 --> 01:00:43,839
it without no space okay so let's assume
1641
01:00:43,839 --> 01:00:45,440
we want to
1642
01:00:45,440 --> 01:00:47,359
figure out what year the person was born
1643
01:00:47,359 --> 01:00:50,880
right so let's say we input
1644
01:00:50,880 --> 01:00:51,920
what
1645
01:00:51,920 --> 01:00:52,799
e
1646
01:00:52,799 --> 01:00:54,559
what is your
1647
01:00:54,559 --> 01:00:57,520
birth year right
1648
01:00:57,520 --> 01:01:00,079
and to do that we probably want some
1649
01:01:00,079 --> 01:01:01,440
birth
1650
01:01:01,440 --> 01:01:04,160
year variable here and then we'll print
1651
01:01:04,160 --> 01:01:05,760
in the first case here we'll just print
1652
01:01:05,760 --> 01:01:08,720
formatted again formatted here
1653
01:01:08,720 --> 01:01:14,720
u are born in or you were born
1654
01:01:15,440 --> 01:01:17,839
we're born in and then
1655
01:01:17,839 --> 01:01:22,319
here we put the birth year in here
1656
01:01:22,640 --> 01:01:24,480
dot here so let's just try this one
1657
01:01:24,480 --> 01:01:26,720
first and then i'll try to modify it and
1658
01:01:26,720 --> 01:01:28,400
then we'll get a problem later this one
1659
01:01:28,400 --> 01:01:30,400
should work out fine so what is your
1660
01:01:30,400 --> 01:01:32,079
name
1661
01:01:32,079 --> 01:01:34,960
i'll just put my name here hello roona
1662
01:01:34,960 --> 01:01:37,200
and what is your birth year well 1991
1663
01:01:37,200 --> 01:01:41,280
right you were born in 1991 i love that
1664
01:01:41,280 --> 01:01:44,240
this machine makes me so happy good
1665
01:01:44,240 --> 01:01:47,200
perfect well what is the problem here
1666
01:01:47,200 --> 01:01:49,680
nothing but let's try to tweak our
1667
01:01:49,680 --> 01:01:53,119
program a tiny bit let's actually copy
1668
01:01:53,119 --> 01:01:55,119
this one here and put it down in the
1669
01:01:55,119 --> 01:01:56,240
cell here
1670
01:01:56,240 --> 01:01:58,799
and then instead we want to
1671
01:01:58,799 --> 01:02:01,680
print the age right so we make a formula
1672
01:02:01,680 --> 01:02:03,119
string is
1673
01:02:03,119 --> 01:02:04,640
so let's say u
1674
01:02:04,640 --> 01:02:06,960
r
1675
01:02:06,960 --> 01:02:09,280
let me take the
1676
01:02:09,280 --> 01:02:10,559
current year
1677
01:02:10,559 --> 01:02:13,119
it's 21 when i'm making these recordings
1678
01:02:13,119 --> 01:02:16,400
maybe you're watching this later
1679
01:02:16,400 --> 01:02:19,200
but and then we subtract that you are
1680
01:02:19,200 --> 01:02:21,599
years old
1681
01:02:21,599 --> 01:02:24,000
right let's try to execute that so
1682
01:02:24,000 --> 01:02:25,760
as we already saw you can make a
1683
01:02:25,760 --> 01:02:27,760
calculation inside these
1684
01:02:27,760 --> 01:02:30,559
curly brackets here so it will take 2021
1685
01:02:30,559 --> 01:02:34,880
and minus in my case 1991 right and
1686
01:02:34,880 --> 01:02:37,440
print how many years i am or i suppose
1687
01:02:37,440 --> 01:02:38,400
it will
1688
01:02:38,400 --> 01:02:40,880
so what is your name it is owner
1689
01:02:40,880 --> 01:02:44,400
what is your birth year 1991 and boom
1690
01:02:44,400 --> 01:02:46,000
something happened
1691
01:02:46,000 --> 01:02:48,640
it didn't go well did it
1692
01:02:48,640 --> 01:02:50,720
so again as i say when we see these
1693
01:02:50,720 --> 01:02:53,760
things don't get don't go into panic i'm
1694
01:02:53,760 --> 01:02:56,720
here i'll guide you don't worry about it
1695
01:02:56,720 --> 01:02:59,680
but let's read it sometimes
1696
01:02:59,680 --> 01:03:01,920
right read the first one right type
1697
01:03:01,920 --> 01:03:04,079
error so that's the exception that's
1698
01:03:04,079 --> 01:03:05,599
happening here right so right to bottom
1699
01:03:05,599 --> 01:03:06,400
here
1700
01:03:06,400 --> 01:03:08,799
unsupported operand type
1701
01:03:08,799 --> 01:03:11,680
for in and string
1702
01:03:11,680 --> 01:03:13,359
so it points actually on the line the
1703
01:03:13,359 --> 01:03:15,520
line four we don't have line numbers
1704
01:03:15,520 --> 01:03:18,079
here but it says print you are this one
1705
01:03:18,079 --> 01:03:20,720
here old right so it's this line here
1706
01:03:20,720 --> 01:03:22,720
the last line here we change right and
1707
01:03:22,720 --> 01:03:26,079
it says something with int and string ah
1708
01:03:26,079 --> 01:03:28,240
so this one is an into right
1709
01:03:28,240 --> 01:03:31,520
what is birth year
1710
01:03:31,520 --> 01:03:32,480
type
1711
01:03:32,480 --> 01:03:33,920
birth year
1712
01:03:33,920 --> 01:03:36,160
it's a string
1713
01:03:36,160 --> 01:03:39,680
because what input does here
1714
01:03:39,680 --> 01:03:41,599
what input does here it actually reads
1715
01:03:41,599 --> 01:03:43,760
the string from standard input read as
1716
01:03:43,760 --> 01:03:47,359
string from standard input right
1717
01:03:47,599 --> 01:03:50,480
so that basically means it returns a
1718
01:03:50,480 --> 01:03:51,760
string
1719
01:03:51,760 --> 01:03:53,760
and we want to convert that so how can
1720
01:03:53,760 --> 01:03:56,000
we do that well there were some hints in
1721
01:03:56,000 --> 01:03:58,400
the top of this something convert with
1722
01:03:58,400 --> 01:04:00,960
int float and string
1723
01:04:00,960 --> 01:04:02,880
my best guess would be int what does int
1724
01:04:02,880 --> 01:04:04,000
does
1725
01:04:04,000 --> 01:04:06,240
do
1726
01:04:06,400 --> 01:04:07,359
well
1727
01:04:07,359 --> 01:04:08,880
it says convert
1728
01:04:08,880 --> 01:04:12,000
a number or string
1729
01:04:12,160 --> 01:04:15,119
to an integer
1730
01:04:15,359 --> 01:04:17,119
perfect
1731
01:04:17,119 --> 01:04:18,960
so let's take birth here
1732
01:04:18,960 --> 01:04:22,160
convert it to an integer okay let's
1733
01:04:22,160 --> 01:04:24,640
actually just keep this code up here and
1734
01:04:24,640 --> 01:04:27,280
copy it down here
1735
01:04:27,280 --> 01:04:30,559
and then add that to the line here that
1736
01:04:30,559 --> 01:04:32,000
birth year
1737
01:04:32,000 --> 01:04:35,599
equals end of birth year right so what
1738
01:04:35,599 --> 01:04:37,520
we do here we add an additional line
1739
01:04:37,520 --> 01:04:39,839
here which takes the input here the
1740
01:04:39,839 --> 01:04:41,839
string birth year and convert it to
1741
01:04:41,839 --> 01:04:44,640
birth year let's see if that works
1742
01:04:44,640 --> 01:04:46,319
rooney
1743
01:04:46,319 --> 01:04:50,160
1991 enter you are 30 years old i told
1744
01:04:50,160 --> 01:04:52,559
you i was 30 right you didn't believe me
1745
01:04:52,559 --> 01:04:54,799
but even the computer says i'm 30 now
1746
01:04:54,799 --> 01:04:57,280
perfect i love it
1747
01:04:57,280 --> 01:04:58,720
perfect so
1748
01:04:58,720 --> 01:05:01,839
this is the simple way of converting a
1749
01:05:01,839 --> 01:05:03,599
string to an integer so let's just play
1750
01:05:03,599 --> 01:05:06,079
around with that right so int
1751
01:05:06,079 --> 01:05:08,079
we had already here that we could
1752
01:05:08,079 --> 01:05:09,599
convert
1753
01:05:09,599 --> 01:05:12,240
integers like that right so
1754
01:05:12,240 --> 01:05:14,720
what happens if it's not an integer like
1755
01:05:14,720 --> 01:05:18,319
if this is r 4 for instance well it will
1756
01:05:18,319 --> 01:05:19,359
say
1757
01:05:19,359 --> 01:05:21,359
you cannot convert here value error blah
1758
01:05:21,359 --> 01:05:24,079
blah blah right so obviously if it's not
1759
01:05:24,079 --> 01:05:26,720
a clean integer if there's something
1760
01:05:26,720 --> 01:05:28,640
else in it well it doesn't know what to
1761
01:05:28,640 --> 01:05:31,599
do and even with a space no it can it
1762
01:05:31,599 --> 01:05:33,280
actually manages space that's pretty
1763
01:05:33,280 --> 01:05:34,480
nice actually
1764
01:05:34,480 --> 01:05:36,880
actually i didn't know that hahaha i
1765
01:05:36,880 --> 01:05:40,240
learn along with you nice
1766
01:05:40,240 --> 01:05:42,400
perfect right
1767
01:05:42,400 --> 01:05:43,520
good
1768
01:05:43,520 --> 01:05:45,119
and obviously you can have negatives as
1769
01:05:45,119 --> 01:05:48,079
well right so now we know how to convert
1770
01:05:48,079 --> 01:05:51,119
convert a integer
1771
01:05:51,119 --> 01:05:53,599
from a string to an integer
1772
01:05:53,599 --> 01:05:54,640
and
1773
01:05:54,640 --> 01:05:56,000
now you're probably curious there's
1774
01:05:56,000 --> 01:05:57,760
something called float here well we can
1775
01:05:57,760 --> 01:06:00,319
probably do the same here right so if we
1776
01:06:00,319 --> 01:06:02,160
take a float here and we have a string
1777
01:06:02,160 --> 01:06:04,079
here
1778
01:06:04,079 --> 01:06:07,520
we can have 2 here and it returns 2.0 as
1779
01:06:07,520 --> 01:06:08,799
you see here
1780
01:06:08,799 --> 01:06:09,839
and
1781
01:06:09,839 --> 01:06:12,680
you can also have a float here
1782
01:06:12,680 --> 01:06:16,480
3.14 and it will return 3.14 just
1783
01:06:16,480 --> 01:06:18,480
similar to string right and you can
1784
01:06:18,480 --> 01:06:19,680
actually
1785
01:06:19,680 --> 01:06:21,359
take a float and have an integer here
1786
01:06:21,359 --> 01:06:23,359
and it will return it as a float so it
1787
01:06:23,359 --> 01:06:25,680
takes the input just like integer it
1788
01:06:25,680 --> 01:06:27,680
didn't say it has to be a string but it
1789
01:06:27,680 --> 01:06:29,280
takes whatever it takes and tries to
1790
01:06:29,280 --> 01:06:31,680
convert it to a float just like integer
1791
01:06:31,680 --> 01:06:32,720
right
1792
01:06:32,720 --> 01:06:34,000
perfect
1793
01:06:34,000 --> 01:06:35,920
what about the last one the string here
1794
01:06:35,920 --> 01:06:39,039
why is that so awesome right
1795
01:06:39,039 --> 01:06:40,079
okay let's
1796
01:06:40,079 --> 01:06:41,839
dive into it let's have a string here
1797
01:06:41,839 --> 01:06:43,119
for instance
1798
01:06:43,119 --> 01:06:45,359
see the problem here string we know the
1799
01:06:45,359 --> 01:06:49,359
problem this is a string
1800
01:06:49,359 --> 01:06:51,200
let's have i for integer and this is an
1801
01:06:51,200 --> 01:06:52,720
integer 7
1802
01:06:52,720 --> 01:06:56,160
and we know if we take s plus
1803
01:06:56,160 --> 01:06:58,880
i we have a problem right
1804
01:06:58,880 --> 01:07:02,079
but what does string do what do you
1805
01:07:02,079 --> 01:07:04,400
think string does right
1806
01:07:04,400 --> 01:07:06,559
well it says down here
1807
01:07:06,559 --> 01:07:08,559
it will convert
1808
01:07:08,559 --> 01:07:11,359
object into a string create a new string
1809
01:07:11,359 --> 01:07:13,359
object from the given object right so
1810
01:07:13,359 --> 01:07:17,839
let's just try to actually say s
1811
01:07:17,839 --> 01:07:19,200
plus
1812
01:07:19,200 --> 01:07:21,680
i here right so we take this the
1813
01:07:21,680 --> 01:07:24,079
original here so we have the i as an
1814
01:07:24,079 --> 01:07:25,520
integer and convert it to a string let's
1815
01:07:25,520 --> 01:07:27,520
try that boom
1816
01:07:27,520 --> 01:07:30,240
this is a string seven right so it adds
1817
01:07:30,240 --> 01:07:31,920
seven immediately after and remember
1818
01:07:31,920 --> 01:07:34,160
again we didn't have any space after the
1819
01:07:34,160 --> 01:07:36,160
string so there's no space between here
1820
01:07:36,160 --> 01:07:37,280
you need to take care of all these
1821
01:07:37,280 --> 01:07:38,319
things right
1822
01:07:38,319 --> 01:07:40,240
so this is actually basically what you
1823
01:07:40,240 --> 01:07:42,720
can do with conversion right and now you
1824
01:07:42,720 --> 01:07:44,160
know
1825
01:07:44,160 --> 01:07:46,720
how to convert anything
1826
01:07:46,720 --> 01:07:48,799
or try to int
1827
01:07:48,799 --> 01:07:51,839
and if it doesn't you get a failure
1828
01:07:51,839 --> 01:07:54,640
try to convert something to float
1829
01:07:54,640 --> 01:07:57,039
if it doesn't work a failure
1830
01:07:57,039 --> 01:07:58,720
try to convert it to a string if it
1831
01:07:58,720 --> 01:08:00,880
doesn't work failure right
1832
01:08:00,880 --> 01:08:02,880
so these are really really handy so
1833
01:08:02,880 --> 01:08:05,119
let's try to use that in the next
1834
01:08:05,119 --> 01:08:07,680
project of hours are you excited i am
1835
01:08:07,680 --> 01:08:11,839
let's get started see you in a moment
1836
01:08:14,000 --> 01:08:15,520
in this one i'm going to introduce you
1837
01:08:15,520 --> 01:08:17,600
to the project and we're going to make
1838
01:08:17,600 --> 01:08:20,238
an interactive calculator remember the
1839
01:08:20,238 --> 01:08:22,880
last project we made some calculations
1840
01:08:22,880 --> 01:08:25,359
but now we want input from the user
1841
01:08:25,359 --> 01:08:27,279
because now we know how to convert them
1842
01:08:27,279 --> 01:08:29,040
right um
1843
01:08:29,040 --> 01:08:31,679
exciting let's get started so again we
1844
01:08:31,679 --> 01:08:34,960
are in steps later the projects will be
1845
01:08:34,960 --> 01:08:37,198
more complex and we'll have like one
1846
01:08:37,198 --> 01:08:39,120
thing to do but in this one we do three
1847
01:08:39,120 --> 01:08:40,960
smaller things right
1848
01:08:40,960 --> 01:08:43,520
so the goal is to multiply two numbers
1849
01:08:43,520 --> 01:08:45,279
it seems easy but it's going to be input
1850
01:08:45,279 --> 01:08:48,238
from the user of course and then we'll
1851
01:08:48,238 --> 01:08:49,759
try to calculate
1852
01:08:49,759 --> 01:08:51,520
how many days it were since you were
1853
01:08:51,520 --> 01:08:54,880
born and then make a tip calculator so
1854
01:08:54,880 --> 01:08:57,198
let's get started the first one
1855
01:08:57,198 --> 01:08:59,120
input a value from the user and keep it
1856
01:08:59,120 --> 01:09:00,399
in variable a
1857
01:09:00,399 --> 01:09:04,080
input another value for user
1858
01:09:04,080 --> 01:09:06,319
and keep it in variable b and print the
1859
01:09:06,319 --> 01:09:08,399
product of the two values a times b
1860
01:09:08,399 --> 01:09:09,839
right
1861
01:09:09,839 --> 01:09:11,600
awesome
1862
01:09:11,600 --> 01:09:12,640
and
1863
01:09:12,640 --> 01:09:14,319
step two
1864
01:09:14,319 --> 01:09:16,799
input how many years the user is right
1865
01:09:16,799 --> 01:09:18,560
convert the years to an integer
1866
01:09:18,560 --> 01:09:21,279
calculate how many days hours minutes
1867
01:09:21,279 --> 01:09:25,040
and seconds since the user is born right
1868
01:09:25,040 --> 01:09:27,440
perfect
1869
01:09:28,158 --> 01:09:31,679
straightforward right and step three
1870
01:09:31,679 --> 01:09:34,238
here we will make a tip calculator input
1871
01:09:34,238 --> 01:09:35,679
the price convert the price to an
1872
01:09:35,679 --> 01:09:36,640
integer
1873
01:09:36,640 --> 01:09:39,120
input the percentage the user wants to
1874
01:09:39,120 --> 01:09:40,479
tip right
1875
01:09:40,479 --> 01:09:42,479
and convert the percentage to another
1876
01:09:42,479 --> 01:09:44,399
integer
1877
01:09:44,399 --> 01:09:46,000
calculate the tip by the following
1878
01:09:46,000 --> 01:09:47,520
formula tip
1879
01:09:47,520 --> 01:09:50,080
is equal to price times percentage tip
1880
01:09:50,080 --> 01:09:52,960
divided by two round the tip to two
1881
01:09:52,960 --> 01:09:54,880
digits so we also use the round function
1882
01:09:54,880 --> 01:09:58,000
right print the tip bonus adjust the
1883
01:09:58,000 --> 01:09:59,120
code
1884
01:09:59,120 --> 01:10:00,239
to
1885
01:10:00,239 --> 01:10:02,880
take float input off percentage tip
1886
01:10:02,880 --> 01:10:04,800
right so instead of using this as an
1887
01:10:04,800 --> 01:10:06,560
integer you see here you can also do it
1888
01:10:06,560 --> 01:10:08,239
with a float instead for instance if you
1889
01:10:08,239 --> 01:10:12,159
want to tip not 13 but 13.3 percentage
1890
01:10:12,159 --> 01:10:14,640
you can do that awesome right
1891
01:10:14,640 --> 01:10:16,560
uh it's just if you want to play along
1892
01:10:16,560 --> 01:10:18,480
with it so that's a bonus step if you
1893
01:10:18,480 --> 01:10:21,120
want to do that awesome are you ready
1894
01:10:21,120 --> 01:10:23,520
i'm ready let's get started now
1895
01:10:23,520 --> 01:10:25,679
you should get started first and then
1896
01:10:25,679 --> 01:10:27,520
when you have done your solution let's
1897
01:10:27,520 --> 01:10:29,600
try to do it together to see how you can
1898
01:10:29,600 --> 01:10:31,360
do it differently and don't worry if you
1899
01:10:31,360 --> 01:10:34,000
do it different than i do it's normal
1900
01:10:34,000 --> 01:10:36,159
it's not just one way to do it if you
1901
01:10:36,159 --> 01:10:38,239
come with the rec correct solution it
1902
01:10:38,239 --> 01:10:40,000
doesn't matter okay
1903
01:10:40,000 --> 01:10:42,239
as long as you keep the python sent
1904
01:10:42,239 --> 01:10:44,960
remember readability simple and all that
1905
01:10:44,960 --> 01:10:48,640
kind of stuff see you in a moment
1906
01:10:51,280 --> 01:10:54,000
are you ready i think you are so let's
1907
01:10:54,000 --> 01:10:57,120
get started i'm sure i'm all confident
1908
01:10:57,120 --> 01:10:58,880
that you tried it yourself and you want
1909
01:10:58,880 --> 01:11:01,520
to see how i would do it okay so are you
1910
01:11:01,520 --> 01:11:04,080
ready i'm ready so let's jump
1911
01:11:04,080 --> 01:11:06,159
immediately down to step one and see
1912
01:11:06,159 --> 01:11:08,640
what we can do well we need to input a
1913
01:11:08,640 --> 01:11:10,239
value from the user and keep it in
1914
01:11:10,239 --> 01:11:11,840
variable a
1915
01:11:11,840 --> 01:11:13,280
let's do that
1916
01:11:13,280 --> 01:11:15,280
a equals
1917
01:11:15,280 --> 01:11:16,880
input
1918
01:11:16,880 --> 01:11:20,320
input i need to spellcorrect here
1919
01:11:20,320 --> 01:11:23,040
input a
1920
01:11:23,040 --> 01:11:24,480
that's it
1921
01:11:24,480 --> 01:11:26,080
input another value from the user and
1922
01:11:26,080 --> 01:11:28,950
keep it in variable b okay input
1923
01:11:28,950 --> 01:11:31,600
[Music]
1924
01:11:31,600 --> 01:11:34,320
input b
1925
01:11:34,480 --> 01:11:35,280
okay
1926
01:11:35,280 --> 01:11:37,280
print the product of the two
1927
01:11:37,280 --> 01:11:40,640
values a times b let's try to do that
1928
01:11:40,640 --> 01:11:43,280
print should we do it and
1929
01:11:43,280 --> 01:11:46,400
let's do it formatted here and we'll say
1930
01:11:46,400 --> 01:11:47,199
a
1931
01:11:47,199 --> 01:11:49,199
times b
1932
01:11:49,199 --> 01:11:51,130
is
1933
01:11:51,130 --> 01:11:52,480
[Music]
1934
01:11:52,480 --> 01:11:56,800
and let's do oh let's do here a times b
1935
01:11:56,800 --> 01:11:58,239
let's see what happens
1936
01:11:58,239 --> 01:12:00,560
are you ready i am
1937
01:12:00,560 --> 01:12:02,640
boom a
1938
01:12:02,640 --> 01:12:04,880
a number a number a number
1939
01:12:04,880 --> 01:12:06,159
five
1940
01:12:06,159 --> 01:12:07,120
b
1941
01:12:07,120 --> 01:12:08,640
three
1942
01:12:08,640 --> 01:12:09,600
no
1943
01:12:09,600 --> 01:12:11,760
we failed don't worry about it it
1944
01:12:11,760 --> 01:12:13,600
happens all the time
1945
01:12:13,600 --> 01:12:14,719
it says
1946
01:12:14,719 --> 01:12:16,719
tie bearer right these are these types
1947
01:12:16,719 --> 01:12:18,400
they're so annoying right but you'll
1948
01:12:18,400 --> 01:12:19,920
love them in a moment
1949
01:12:19,920 --> 01:12:23,440
can't multiply sequence by non-end of
1950
01:12:23,440 --> 01:12:26,480
type string oh yeah remember input
1951
01:12:26,480 --> 01:12:29,040
returns string so a is a string b is a
1952
01:12:29,040 --> 01:12:31,040
string right and we cannot multiply that
1953
01:12:31,040 --> 01:12:33,679
so we need to convert it so you can do
1954
01:12:33,679 --> 01:12:35,520
it in steps or directly let's do it in
1955
01:12:35,520 --> 01:12:39,440
steps here a equals int a
1956
01:12:39,440 --> 01:12:42,800
b equals int
1957
01:12:43,840 --> 01:12:44,640
b
1958
01:12:44,640 --> 01:12:46,880
let's try to run again are you ready
1959
01:12:46,880 --> 01:12:48,640
i am
1960
01:12:48,640 --> 01:12:49,520
a
1961
01:12:49,520 --> 01:12:50,560
five
1962
01:12:50,560 --> 01:12:51,199
b
1963
01:12:51,199 --> 01:12:52,000
three
1964
01:12:52,000 --> 01:12:54,159
fifteen so
1965
01:12:54,159 --> 01:12:57,520
five times three is fifteen perfect i
1966
01:12:57,520 --> 01:13:00,080
like it i feel comfortable again do you
1967
01:13:00,080 --> 01:13:02,480
i know we need to learn along the way
1968
01:13:02,480 --> 01:13:04,560
making mistakes is the best way to learn
1969
01:13:04,560 --> 01:13:05,920
if you don't make mistakes you will
1970
01:13:05,920 --> 01:13:08,080
never realize if you fully understood it
1971
01:13:08,080 --> 01:13:09,600
if you make mistakes there will be
1972
01:13:09,600 --> 01:13:11,360
something you think why is it that that
1973
01:13:11,360 --> 01:13:13,760
mistake happened okay
1974
01:13:13,760 --> 01:13:15,040
step two
1975
01:13:15,040 --> 01:13:18,400
how many years the user is input right
1976
01:13:18,400 --> 01:13:20,640
so
1977
01:13:20,640 --> 01:13:22,960
years let's just call it years
1978
01:13:22,960 --> 01:13:25,199
or age let's call it h
1979
01:13:25,199 --> 01:13:27,120
input
1980
01:13:27,120 --> 01:13:29,120
how many
1981
01:13:29,120 --> 01:13:32,800
years are you question mark
1982
01:13:32,800 --> 01:13:36,239
convert the years to an integer
1983
01:13:36,239 --> 01:13:39,199
h equals int age now it actually helps
1984
01:13:39,199 --> 01:13:40,159
you right
1985
01:13:40,159 --> 01:13:42,560
calculate how many days hours minutes
1986
01:13:42,560 --> 01:13:44,159
and seconds the user
1987
01:13:44,159 --> 01:13:48,080
since the user is born right
1988
01:13:48,080 --> 01:13:50,000
print
1989
01:13:50,000 --> 01:13:52,159
uh u
1990
01:13:52,159 --> 01:13:54,880
u r
1991
01:13:55,120 --> 01:13:58,640
let's do a float here an h times
1992
01:13:58,640 --> 01:14:02,000
if we just assume we're there 365 days
1993
01:14:02,000 --> 01:14:04,239
then we have you are
1994
01:14:04,239 --> 01:14:06,960
days old right let's try to execute that
1995
01:14:06,960 --> 01:14:09,360
actually and let's put the my age 30 is
1996
01:14:09,360 --> 01:14:11,280
still 30 years old
1997
01:14:11,280 --> 01:14:12,719
and
1998
01:14:12,719 --> 01:14:14,800
what happened here right so what we did
1999
01:14:14,800 --> 01:14:16,800
here it's good to make mistakes right it
2000
01:14:16,800 --> 01:14:18,960
says age times here and you think it
2001
01:14:18,960 --> 01:14:20,320
doesn't complain about anything so
2002
01:14:20,320 --> 01:14:22,159
what's wrong here why doesn't it print
2003
01:14:22,159 --> 01:14:24,400
number of days right because we forgot
2004
01:14:24,400 --> 01:14:26,719
the format string here right
2005
01:14:26,719 --> 01:14:30,640
awesome lesson learned 30 and it'll say
2006
01:14:30,640 --> 01:14:33,199
10 950 days
2007
01:14:33,199 --> 01:14:36,080
whoa i passed the 10 000 mark
2008
01:14:36,080 --> 01:14:38,480
okay and we can continue this journey
2009
01:14:38,480 --> 01:14:39,760
now right so
2010
01:14:39,760 --> 01:14:41,440
i'll do something ugly and copy and
2011
01:14:41,440 --> 01:14:45,760
paste you should always worry about that
2012
01:14:46,880 --> 01:14:48,800
and let's copy one more isn't that what
2013
01:14:48,800 --> 01:14:52,960
we need to do so if we multiply days by
2014
01:14:52,960 --> 01:14:56,239
24 we have hours right
2015
01:14:56,239 --> 01:14:57,440
hours
2016
01:14:57,440 --> 01:14:59,760
and we multiply
2017
01:14:59,760 --> 01:15:03,530
24 by 60 we have minutes
2018
01:15:03,530 --> 01:15:05,360
[Music]
2019
01:15:05,360 --> 01:15:07,000
and if we multiply
2020
01:15:07,000 --> 01:15:10,400
2460 by 60 we have
2021
01:15:10,400 --> 01:15:11,440
seconds
2022
01:15:11,440 --> 01:15:13,760
okay right you see here right so first
2023
01:15:13,760 --> 01:15:16,080
we got the number of days there are 365
2024
01:15:16,080 --> 01:15:18,719
days per year or we just i know no leap
2025
01:15:18,719 --> 01:15:20,080
years or anything
2026
01:15:20,080 --> 01:15:21,920
and then in this one when we get hours
2027
01:15:21,920 --> 01:15:25,199
we multiply that number by 24 then we
2028
01:15:25,199 --> 01:15:26,560
have the number of hours because there
2029
01:15:26,560 --> 01:15:28,960
are 24 hours per day right and then we
2030
01:15:28,960 --> 01:15:31,600
take that number and multiply that by 60
2031
01:15:31,600 --> 01:15:34,159
because there's 60 minutes per hour and
2032
01:15:34,159 --> 01:15:36,320
then we take that number and multiply by
2033
01:15:36,320 --> 01:15:38,960
60 because there are 60 seconds per
2034
01:15:38,960 --> 01:15:41,520
minute right
2035
01:15:41,520 --> 01:15:43,520
let's try it
2036
01:15:43,520 --> 01:15:44,400
boom
2037
01:15:44,400 --> 01:15:47,280
so in my case i'm 10 000 over 10 000
2038
01:15:47,280 --> 01:15:52,159
days i'm more than 250 000 hours old oh
2039
01:15:52,159 --> 01:15:54,800
i don't wanna how much is this 15 over
2040
01:15:54,800 --> 01:15:56,880
15 million minutes
2041
01:15:56,880 --> 01:15:59,360
and how much is this it's almost one
2042
01:15:59,360 --> 01:16:00,800
billion seconds
2043
01:16:00,800 --> 01:16:02,000
whoa
2044
01:16:02,000 --> 01:16:03,280
whoa
2045
01:16:03,280 --> 01:16:05,199
did you cross the one billion mark did
2046
01:16:05,199 --> 01:16:07,520
you
2047
01:16:07,520 --> 01:16:10,239
whoa that's crazy did that count right i
2048
01:16:10,239 --> 01:16:12,640
think so don't do this at home kids this
2049
01:16:12,640 --> 01:16:14,640
is dangerous
2050
01:16:14,640 --> 01:16:17,040
so in step three here we need to make a
2051
01:16:17,040 --> 01:16:20,320
tip calculator and let's just dive into
2052
01:16:20,320 --> 01:16:22,159
it and follow along here right so input
2053
01:16:22,159 --> 01:16:24,560
the tip price uh
2054
01:16:24,560 --> 01:16:27,120
price not the surprise input the price
2055
01:16:27,120 --> 01:16:29,520
input
2056
01:16:29,920 --> 01:16:31,719
yeah let's just write input
2057
01:16:31,719 --> 01:16:33,360
input
2058
01:16:33,360 --> 01:16:34,560
price
2059
01:16:34,560 --> 01:16:37,600
colon what to do convert the price
2060
01:16:37,600 --> 01:16:39,360
convert the price to an integer let's do
2061
01:16:39,360 --> 01:16:40,239
that
2062
01:16:40,239 --> 01:16:42,719
that's always good
2063
01:16:42,719 --> 01:16:44,159
int
2064
01:16:44,159 --> 01:16:45,250
price
2065
01:16:45,250 --> 01:16:46,960
[Music]
2066
01:16:46,960 --> 01:16:48,159
and uh
2067
01:16:48,159 --> 01:16:49,840
input the percentages they use want to
2068
01:16:49,840 --> 01:16:52,080
tip
2069
01:16:52,679 --> 01:16:54,239
percentage
2070
01:16:54,239 --> 01:16:55,120
tip
2071
01:16:55,120 --> 01:16:57,679
and input
2072
01:16:57,679 --> 01:16:59,440
how much
2073
01:16:59,440 --> 01:17:01,600
do you
2074
01:17:01,600 --> 01:17:03,040
want to
2075
01:17:03,040 --> 01:17:04,000
tip
2076
01:17:04,000 --> 01:17:06,719
percentage question mark
2077
01:17:06,719 --> 01:17:08,880
and we need to it says here convert
2078
01:17:08,880 --> 01:17:11,120
percentage to an integer
2079
01:17:11,120 --> 01:17:15,120
percentage tip equals int
2080
01:17:15,120 --> 01:17:16,120
hope
2081
01:17:16,120 --> 01:17:18,480
percentage tip
2082
01:17:18,480 --> 01:17:20,480
and calculate the tip by the four
2083
01:17:20,480 --> 01:17:23,199
following formula let's do that
2084
01:17:23,199 --> 01:17:24,960
tip equals
2085
01:17:24,960 --> 01:17:26,400
price
2086
01:17:26,400 --> 01:17:30,400
times percentage tip divided by 100 and
2087
01:17:30,400 --> 01:17:31,679
then it says
2088
01:17:31,679 --> 01:17:34,800
round the tip to two digits
2089
01:17:34,800 --> 01:17:37,280
tip equals round
2090
01:17:37,280 --> 01:17:38,880
tip comma two
2091
01:17:38,880 --> 01:17:42,000
and then it says printer tip
2092
01:17:42,000 --> 01:17:43,360
print
2093
01:17:43,360 --> 01:17:45,440
tip let's just make format the string
2094
01:17:45,440 --> 01:17:47,440
here tip so we need the f in front of
2095
01:17:47,440 --> 01:17:49,600
here are you ready let's just dive into
2096
01:17:49,600 --> 01:17:50,480
it
2097
01:17:50,480 --> 01:17:52,480
input price let's say i tipped one
2098
01:17:52,480 --> 01:17:53,600
hundred dollars
2099
01:17:53,600 --> 01:17:55,199
how much do you want to tip let's say 15
2100
01:17:55,199 --> 01:17:56,719
percent
2101
01:17:56,719 --> 01:17:59,360
your chip 15 that's pretty nice
2102
01:17:59,360 --> 01:18:01,600
let's make something a bit more advanced
2103
01:18:01,600 --> 01:18:04,400
230 dollars i want to tip
2104
01:18:04,400 --> 01:18:06,480
17 16
2105
01:18:06,480 --> 01:18:07,110
17
2106
01:18:07,110 --> 01:18:08,400
[Music]
2107
01:18:08,400 --> 01:18:10,960
39.1
2108
01:18:10,960 --> 01:18:12,640
wow right
2109
01:18:12,640 --> 01:18:14,560
okay so the bonus adjust the code to
2110
01:18:14,560 --> 01:18:16,960
take a float input in percentage tip so
2111
01:18:16,960 --> 01:18:19,360
the problem right now if i added a float
2112
01:18:19,360 --> 01:18:22,560
here you see here if it's at 10.3
2113
01:18:22,560 --> 01:18:24,960
percent here it will get a value error
2114
01:18:24,960 --> 01:18:27,920
because this is not a
2115
01:18:27,920 --> 01:18:29,920
integer anymore right because we convert
2116
01:18:29,920 --> 01:18:31,520
it to
2117
01:18:31,520 --> 01:18:33,280
an integer on this line is this this
2118
01:18:33,280 --> 01:18:34,719
line here right
2119
01:18:34,719 --> 01:18:37,120
and how do you change that well you just
2120
01:18:37,120 --> 01:18:39,040
put it to a float here
2121
01:18:39,040 --> 01:18:42,800
and execute again and then say 110.3
2122
01:18:42,800 --> 01:18:47,199
for the game and your tip is 14 10.4 now
2123
01:18:47,199 --> 01:18:48,000
right
2124
01:18:48,000 --> 01:18:49,520
you should do the math
2125
01:18:49,520 --> 01:18:52,560
awesome isn't that crazy i think so i
2126
01:18:52,560 --> 01:18:53,520
like it
2127
01:18:53,520 --> 01:18:56,880
and this is amazing right and actually
2128
01:18:56,880 --> 01:18:58,159
the next thing is going to be amazing
2129
01:18:58,159 --> 01:18:59,840
we're going to learn about flows in
2130
01:18:59,840 --> 01:19:01,679
programs how can you make flows right
2131
01:19:01,679 --> 01:19:03,679
now we always have the same flow in the
2132
01:19:03,679 --> 01:19:05,920
program you do the same thing and no
2133
01:19:05,920 --> 01:19:07,280
matter what it will always do the same
2134
01:19:07,280 --> 01:19:08,800
thing in the same order this is like a
2135
01:19:08,800 --> 01:19:11,040
basic recipe right in the kitchen you do
2136
01:19:11,040 --> 01:19:13,840
this things in the same order now
2137
01:19:13,840 --> 01:19:15,520
can we do something in one case and do
2138
01:19:15,520 --> 01:19:17,600
something in another case well we can
2139
01:19:17,600 --> 01:19:19,760
and we will learn how to do that so are
2140
01:19:19,760 --> 01:19:21,520
you excited i'm excited let's get
2141
01:19:21,520 --> 01:19:23,840
started
2142
01:19:26,880 --> 01:19:30,080
so far we covered how you can take input
2143
01:19:30,080 --> 01:19:31,920
how you can convert that input and make
2144
01:19:31,920 --> 01:19:34,239
awesome calculations based on that but
2145
01:19:34,239 --> 01:19:36,960
there's a piece missing right you don't
2146
01:19:36,960 --> 01:19:37,840
know
2147
01:19:37,840 --> 01:19:39,920
how to make a flow in a program what do
2148
01:19:39,920 --> 01:19:42,400
i mean well so far you're following the
2149
01:19:42,400 --> 01:19:45,120
same recipe no matter how the input from
2150
01:19:45,120 --> 01:19:46,560
the user is
2151
01:19:46,560 --> 01:19:49,280
but in reality you know you do things
2152
01:19:49,280 --> 01:19:51,520
based on input right for instance if
2153
01:19:51,520 --> 01:19:53,360
it's raining you might be bringing your
2154
01:19:53,360 --> 01:19:55,360
umbrella outside right
2155
01:19:55,360 --> 01:19:57,280
so if it's not raining you don't right
2156
01:19:57,280 --> 01:19:59,440
you want to be able to express that kind
2157
01:19:59,440 --> 01:20:01,840
of logic in your programming and this is
2158
01:20:01,840 --> 01:20:03,520
where program flows come into the
2159
01:20:03,520 --> 01:20:04,400
picture
2160
01:20:04,400 --> 01:20:06,239
in this lesson we will learn about if
2161
01:20:06,239 --> 01:20:09,360
statements yes and they are awesome they
2162
01:20:09,360 --> 01:20:11,199
are connected to the booleans remember
2163
01:20:11,199 --> 01:20:13,520
those those are a bit awkward true or
2164
01:20:13,520 --> 01:20:14,960
false right
2165
01:20:14,960 --> 01:20:16,880
we're going to dive into those and see
2166
01:20:16,880 --> 01:20:19,199
how they can help you making flows and
2167
01:20:19,199 --> 01:20:22,159
programs so are you excited i am let's
2168
01:20:22,159 --> 01:20:24,480
get started so inside jupiter notebook
2169
01:20:24,480 --> 01:20:27,120
we have about program flows it says here
2170
01:20:27,120 --> 01:20:29,440
the goal is to learn about if statements
2171
01:20:29,440 --> 01:20:31,280
use if statements to make program
2172
01:20:31,280 --> 01:20:34,560
perform based on variables right
2173
01:20:34,560 --> 01:20:35,360
so
2174
01:20:35,360 --> 01:20:37,840
that's the goal of this listener so
2175
01:20:37,840 --> 01:20:39,920
let's look at the boolean expressions
2176
01:20:39,920 --> 01:20:42,880
again and we need to master a lot of
2177
01:20:42,880 --> 01:20:46,960
them down there or some of them at least
2178
01:20:46,960 --> 01:20:48,000
so
2179
01:20:48,000 --> 01:20:50,159
if you have variables a and b you can
2180
01:20:50,159 --> 01:20:52,800
make equality test as a boolean and you
2181
01:20:52,800 --> 01:20:55,199
notice that there are two equal signs
2182
01:20:55,199 --> 01:20:57,120
where a single equal signs would assign
2183
01:20:57,120 --> 01:21:01,040
something 2 will evaluate if a equals b
2184
01:21:01,040 --> 01:21:03,280
not equals it is with an exclamation
2185
01:21:03,280 --> 01:21:05,040
mark and an equal sign
2186
01:21:05,040 --> 01:21:07,840
and a less than it's a less than sign
2187
01:21:07,840 --> 01:21:10,480
less than or equal less than equal
2188
01:21:10,480 --> 01:21:12,960
a greater than greater mean sign greater
2189
01:21:12,960 --> 01:21:16,080
than or equal greater or equal sign that
2190
01:21:16,080 --> 01:21:18,880
all makes sense kind of i think so
2191
01:21:18,880 --> 01:21:20,400
at least i think so
2192
01:21:20,400 --> 01:21:22,719
so let's try some examples to see how
2193
01:21:22,719 --> 01:21:23,600
this
2194
01:21:23,600 --> 01:21:26,320
gibberish here becomes code down here
2195
01:21:26,320 --> 01:21:29,040
let's turn it into some coding examples
2196
01:21:29,040 --> 01:21:30,320
before i
2197
01:21:30,320 --> 01:21:32,080
so we can get ready for the project
2198
01:21:32,080 --> 01:21:34,000
right that's all we want to do we want
2199
01:21:34,000 --> 01:21:36,639
some programming projects so let's get
2200
01:21:36,639 --> 01:21:38,000
started
2201
01:21:38,000 --> 01:21:40,400
so let's say 8 10
2202
01:21:40,400 --> 01:21:43,440
and b 12.
2203
01:21:43,440 --> 01:21:44,480
okay
2204
01:21:44,480 --> 01:21:45,840
so
2205
01:21:45,840 --> 01:21:48,159
we need to know these if statements up
2206
01:21:48,159 --> 01:21:50,400
here that we talked about how can we use
2207
01:21:50,400 --> 01:21:53,280
those so the syntax is as follow if
2208
01:21:53,280 --> 01:21:55,040
then we put a boolean expression let's
2209
01:21:55,040 --> 01:21:58,560
say a equal equals b
2210
01:21:58,560 --> 01:22:00,000
and then a colon
2211
01:22:00,000 --> 01:22:02,239
so that's the syntax and when i type
2212
01:22:02,239 --> 01:22:04,239
enter something happened here you see
2213
01:22:04,239 --> 01:22:05,920
here my
2214
01:22:05,920 --> 01:22:08,080
computer didn't put it all the way out
2215
01:22:08,080 --> 01:22:10,480
here it didn't indented the code as it's
2216
01:22:10,480 --> 01:22:12,239
called because what's intended
2217
01:22:12,239 --> 01:22:14,719
afterwards will be executed if this sign
2218
01:22:14,719 --> 01:22:16,800
is true so let's just say here let's
2219
01:22:16,800 --> 01:22:19,040
print
2220
01:22:19,040 --> 01:22:20,080
a
2221
01:22:20,080 --> 01:22:21,040
a
2222
01:22:21,040 --> 01:22:22,320
equals
2223
01:22:22,320 --> 01:22:25,120
equals b here right
2224
01:22:25,120 --> 01:22:26,960
so let's execute it and we see here
2225
01:22:26,960 --> 01:22:29,760
nothing happened here because a is not
2226
01:22:29,760 --> 01:22:32,239
equal to b and it will only execute this
2227
01:22:32,239 --> 01:22:34,320
if this is true right so let's try to
2228
01:22:34,320 --> 01:22:36,800
change this value actually and say boom
2229
01:22:36,800 --> 01:22:39,760
a equals b now right you see because
2230
01:22:39,760 --> 01:22:41,600
this is the case right
2231
01:22:41,600 --> 01:22:42,719
awesome
2232
01:22:42,719 --> 01:22:45,040
so this way here you can have all kinds
2233
01:22:45,040 --> 01:22:46,880
of expressions here we can have
2234
01:22:46,880 --> 01:22:47,920
something
2235
01:22:47,920 --> 01:22:50,239
let's just take a and b equals 12 again
2236
01:22:50,239 --> 01:22:52,719
here and say if a is
2237
01:22:52,719 --> 01:22:56,239
less than b then print
2238
01:22:56,239 --> 01:22:59,440
a is less than b right
2239
01:22:59,440 --> 01:23:02,320
and it will execute that right but if we
2240
01:23:02,320 --> 01:23:05,440
change obviously b to b8 here it will
2241
01:23:05,440 --> 01:23:07,040
not print anything right it makes sense
2242
01:23:07,040 --> 01:23:09,040
right so now we can
2243
01:23:09,040 --> 01:23:12,480
make model programs that do something in
2244
01:23:12,480 --> 01:23:16,239
one case if that case is true
2245
01:23:16,239 --> 01:23:18,639
that leads us to the next thing
2246
01:23:18,639 --> 01:23:20,239
sometimes you don't want to do one thing
2247
01:23:20,239 --> 01:23:21,840
in one case and another thing in another
2248
01:23:21,840 --> 01:23:24,080
one right okay let's try to do that
2249
01:23:24,080 --> 01:23:26,960
so let's say a equals
2250
01:23:26,960 --> 01:23:27,760
10
2251
01:23:27,760 --> 01:23:29,360
b equals 12.
2252
01:23:29,360 --> 01:23:31,600
so if a is
2253
01:23:31,600 --> 01:23:32,840
greater than
2254
01:23:32,840 --> 01:23:36,400
b in print
2255
01:23:36,560 --> 01:23:37,840
a is
2256
01:23:37,840 --> 01:23:41,280
greater than b
2257
01:23:41,280 --> 01:23:42,239
but
2258
01:23:42,239 --> 01:23:44,800
then let's do an else what does else do
2259
01:23:44,800 --> 01:23:46,639
let's say
2260
01:23:46,639 --> 01:23:50,719
a is not greater than b okay let's try
2261
01:23:50,719 --> 01:23:52,560
to execute this
2262
01:23:52,560 --> 01:23:55,040
so what we say here is
2263
01:23:55,040 --> 01:23:56,639
a is not greater than b that means we
2264
01:23:56,639 --> 01:23:57,840
execute the
2265
01:23:57,840 --> 01:24:00,159
else part here why is that because a is
2266
01:24:00,159 --> 01:24:02,639
10 and 10 is not greater than b so this
2267
01:24:02,639 --> 01:24:04,320
is why this
2268
01:24:04,320 --> 01:24:06,639
command line here was executed
2269
01:24:06,639 --> 01:24:09,840
if we changed a to let's say 15 then it
2270
01:24:09,840 --> 01:24:11,600
would actually say a is greater than b
2271
01:24:11,600 --> 01:24:13,360
right
2272
01:24:13,360 --> 01:24:15,760
just a warning here right so this is
2273
01:24:15,760 --> 01:24:18,960
computers are very pedantic so if a is
2274
01:24:18,960 --> 01:24:22,320
equals to 12 as b does then it will say
2275
01:24:22,320 --> 01:24:25,840
a is not greater than b right
2276
01:24:25,840 --> 01:24:28,080
because in this case we don't have this
2277
01:24:28,080 --> 01:24:30,960
case here it's not equal it's
2278
01:24:30,960 --> 01:24:32,880
you know again up here
2279
01:24:32,880 --> 01:24:35,120
it distinguishes between less and less
2280
01:24:35,120 --> 01:24:37,280
than equal and greater and greater than
2281
01:24:37,280 --> 01:24:38,960
equal right
2282
01:24:38,960 --> 01:24:41,199
both areas so these are two specific
2283
01:24:41,199 --> 01:24:42,840
cases right
2284
01:24:42,840 --> 01:24:45,920
awesome so if i change this one to equal
2285
01:24:45,920 --> 01:24:47,920
sign as well right it will say a is
2286
01:24:47,920 --> 01:24:49,360
greater than b and this is not true
2287
01:24:49,360 --> 01:24:51,199
actually right so let's just remove that
2288
01:24:51,199 --> 01:24:52,480
again
2289
01:24:52,480 --> 01:24:55,600
awesome isn't that great i think so
2290
01:24:55,600 --> 01:24:57,360
uh
2291
01:24:57,360 --> 01:25:00,560
perfect we can also have multiple flows
2292
01:25:00,560 --> 01:25:03,199
like this one here so let's say a again
2293
01:25:03,199 --> 01:25:07,120
10 b equals 12. so if a
2294
01:25:07,120 --> 01:25:10,239
greater than b we'll say print
2295
01:25:10,239 --> 01:25:13,840
a is greater than b
2296
01:25:13,840 --> 01:25:15,840
then we have something called alif
2297
01:25:15,840 --> 01:25:18,159
it's called else if but it's called alif
2298
01:25:18,159 --> 01:25:20,800
in the python and let's say a equal
2299
01:25:20,800 --> 01:25:23,679
equals b and then say print
2300
01:25:23,679 --> 01:25:24,960
a is
2301
01:25:24,960 --> 01:25:27,120
equal to
2302
01:25:27,120 --> 01:25:28,000
b
2303
01:25:28,000 --> 01:25:29,520
not b b
2304
01:25:29,520 --> 01:25:30,719
and then we're going to have the else in
2305
01:25:30,719 --> 01:25:33,679
the end here and then we'll print
2306
01:25:33,679 --> 01:25:35,040
a is
2307
01:25:35,040 --> 01:25:35,920
less
2308
01:25:35,920 --> 01:25:38,080
than b right
2309
01:25:38,080 --> 01:25:40,639
perfect so a is less than b here and we
2310
01:25:40,639 --> 01:25:43,360
can try equals
2311
01:25:43,360 --> 01:25:45,920
and we can try
2312
01:25:45,920 --> 01:25:48,400
13 here so a is greater than b right so
2313
01:25:48,400 --> 01:25:50,560
you see how you can model flow now right
2314
01:25:50,560 --> 01:25:52,159
based on this the only one we didn't
2315
01:25:52,159 --> 01:25:54,400
really try where this not equals let's
2316
01:25:54,400 --> 01:25:56,719
just try to do that
2317
01:25:56,719 --> 01:26:00,400
a equals 10 b equals 12.
2318
01:26:00,400 --> 01:26:04,080
if a not equals b then
2319
01:26:04,080 --> 01:26:05,600
print
2320
01:26:05,600 --> 01:26:08,880
a does not equal
2321
01:26:08,880 --> 01:26:10,800
b right and this is the case here and if
2322
01:26:10,800 --> 01:26:12,080
they were equal
2323
01:26:12,080 --> 01:26:14,880
obviously they were equal right so see
2324
01:26:14,880 --> 01:26:17,280
what kind of power this gives us right
2325
01:26:17,280 --> 01:26:18,960
now we can actually do a lot of things
2326
01:26:18,960 --> 01:26:21,199
and in the project we'll do a car
2327
01:26:21,199 --> 01:26:22,480
insurance
2328
01:26:22,480 --> 01:26:24,800
company and we'll do calculations based
2329
01:26:24,800 --> 01:26:27,280
on that it will be amazing so if you're
2330
01:26:27,280 --> 01:26:29,120
ready i think you should dive into that
2331
01:26:29,120 --> 01:26:30,960
because that's where we really learned
2332
01:26:30,960 --> 01:26:32,400
something is doing something and it's
2333
01:26:32,400 --> 01:26:34,239
it's going to be amazing actually so our
2334
01:26:34,239 --> 01:26:35,600
first real
2335
01:26:35,600 --> 01:26:37,920
more real life big project so let's get
2336
01:26:37,920 --> 01:26:41,280
started with that see you in a moment
2337
01:26:43,520 --> 01:26:45,040
are you ready for this project it's
2338
01:26:45,040 --> 01:26:47,199
gonna be amazing it's our first kind of
2339
01:26:47,199 --> 01:26:50,320
real project we'll see some diagrams and
2340
01:26:50,320 --> 01:26:53,440
try to turn that diagram into code are
2341
01:26:53,440 --> 01:26:55,600
you ready i think so let's get started
2342
01:26:55,600 --> 01:26:57,760
this is a car insurance it's very
2343
01:26:57,760 --> 01:27:00,480
simplified and to be honest i don't know
2344
01:27:00,480 --> 01:27:02,159
if that's how they calculate it it's
2345
01:27:02,159 --> 01:27:04,239
just to simplify have an example that's
2346
01:27:04,239 --> 01:27:05,600
more real life
2347
01:27:05,600 --> 01:27:08,159
so the goal is to in to car insurance to
2348
01:27:08,159 --> 01:27:10,159
calculate a car insurance based on the
2349
01:27:10,159 --> 01:27:11,920
following decision tree right what is a
2350
01:27:11,920 --> 01:27:13,920
decision tree well it will make sense in
2351
01:27:13,920 --> 01:27:16,400
a moment so the decision tree takes kind
2352
01:27:16,400 --> 01:27:18,080
of input from the top first you'll
2353
01:27:18,080 --> 01:27:20,080
figure out what the gender is if it's
2354
01:27:20,080 --> 01:27:22,639
male or female and based on that you'll
2355
01:27:22,639 --> 01:27:25,120
go down let's say for instance you're
2356
01:27:25,120 --> 01:27:26,639
male and you're
2357
01:27:26,639 --> 01:27:29,440
you're are 30 years old are male and 30
2358
01:27:29,440 --> 01:27:31,440
years old right
2359
01:27:31,440 --> 01:27:34,239
then i'll go this way and my age is
2360
01:27:34,239 --> 01:27:35,760
is
2361
01:27:35,760 --> 01:27:38,159
greater than 26 right you need to say
2362
01:27:38,159 --> 01:27:40,000
that the age here is greater than 26 and
2363
01:27:40,000 --> 01:27:42,960
then i have to pay 99 of something right
2364
01:27:42,960 --> 01:27:46,400
if i was less than 26 or equal and it
2365
01:27:46,400 --> 01:27:49,360
would be 23 and if i was female then
2366
01:27:49,360 --> 01:27:51,199
it's depending on what type of car you
2367
01:27:51,199 --> 01:27:53,760
have if it's a sports car or not then if
2368
01:27:53,760 --> 01:27:56,159
it's a sports car you'll pay 21 and if
2369
01:27:56,159 --> 01:27:57,600
not you'll be
2370
01:27:57,600 --> 01:27:59,360
paying 10 so you can see there are
2371
01:27:59,360 --> 01:28:00,880
different decisions based on if you're
2372
01:28:00,880 --> 01:28:02,960
male or female if you're male it depends
2373
01:28:02,960 --> 01:28:05,040
on your age if you're female it depends
2374
01:28:05,040 --> 01:28:05,760
of
2375
01:28:05,760 --> 01:28:07,199
depends on if you
2376
01:28:07,199 --> 01:28:10,639
ride a sports car or not right so
2377
01:28:10,639 --> 01:28:12,320
description this is a fictional car
2378
01:28:12,320 --> 01:28:15,040
insurance company called car crash
2379
01:28:15,040 --> 01:28:17,120
they calculate their yearly insurance
2380
01:28:17,120 --> 01:28:19,120
price based on the current market price
2381
01:28:19,120 --> 01:28:21,520
of the car so given the market price of
2382
01:28:21,520 --> 01:28:23,280
the car market price
2383
01:28:23,280 --> 01:28:25,040
then the year the insurance price is
2384
01:28:25,040 --> 01:28:27,520
nine percent of the market price if the
2385
01:28:27,520 --> 01:28:30,159
male is above 26 years old right
2386
01:28:30,159 --> 01:28:32,239
as we see in the decision tree we have
2387
01:28:32,239 --> 01:28:34,400
four possible price calculations create
2388
01:28:34,400 --> 01:28:36,159
a program which takes input based on
2389
01:28:36,159 --> 01:28:38,080
that calculate the correct price for all
2390
01:28:38,080 --> 01:28:42,080
four cases right so this looks scary try
2391
01:28:42,080 --> 01:28:44,080
it out yourself then i'll help you in a
2392
01:28:44,080 --> 01:28:47,120
moment okay are you ready i am let's get
2393
01:28:47,120 --> 01:28:49,600
started
2394
01:28:52,159 --> 01:28:54,320
now this is exciting did you try it out
2395
01:28:54,320 --> 01:28:56,000
yourself please let me know in the
2396
01:28:56,000 --> 01:28:57,679
comments how it went for you and what
2397
01:28:57,679 --> 01:29:00,320
was the problems i love to hear
2398
01:29:00,320 --> 01:29:01,760
what are you struggling with and what's
2399
01:29:01,760 --> 01:29:04,800
difficult to understand but now let's
2400
01:29:04,800 --> 01:29:06,480
see how you
2401
01:29:06,480 --> 01:29:08,719
one way to solve it how i would solve it
2402
01:29:08,719 --> 01:29:10,960
on this level where we at now right
2403
01:29:10,960 --> 01:29:12,880
remember we will learn more maybe later
2404
01:29:12,880 --> 01:29:15,040
we would solve it in a different way so
2405
01:29:15,040 --> 01:29:17,760
let's get started
2406
01:29:17,760 --> 01:29:20,000
so this is the decision tree that we are
2407
01:29:20,000 --> 01:29:22,239
working with right so in the beginning
2408
01:29:22,239 --> 01:29:24,080
we need to figure out if it's male or
2409
01:29:24,080 --> 01:29:27,360
female and based on that if it's a male
2410
01:29:27,360 --> 01:29:30,639
if it's less or equal 26 or not if it's
2411
01:29:30,639 --> 01:29:33,360
a female whether she
2412
01:29:33,360 --> 01:29:36,400
drives a sports car or not right
2413
01:29:36,400 --> 01:29:38,000
so how do you structure this right we
2414
01:29:38,000 --> 01:29:40,480
have if statements right so how do you
2415
01:29:40,480 --> 01:29:42,080
do that right
2416
01:29:42,080 --> 01:29:44,400
again i assume we
2417
01:29:44,400 --> 01:29:46,639
know all the text here we
2418
01:29:46,639 --> 01:29:48,400
should have a market price but let's
2419
01:29:48,400 --> 01:29:50,159
leave the market price out for now and
2420
01:29:50,159 --> 01:29:52,400
try to figure out how we model this
2421
01:29:52,400 --> 01:29:54,960
decision tree here so a good advice is
2422
01:29:54,960 --> 01:29:57,520
not to over complicate things and try it
2423
01:29:57,520 --> 01:29:59,360
along the way right
2424
01:29:59,360 --> 01:30:01,600
so let's just look at this first one and
2425
01:30:01,600 --> 01:30:03,760
ensure we are doing this correct right
2426
01:30:03,760 --> 01:30:05,520
so the first one is figure out if we
2427
01:30:05,520 --> 01:30:08,480
have a male or female that we are
2428
01:30:08,480 --> 01:30:10,560
interacting with right so how do you do
2429
01:30:10,560 --> 01:30:12,080
that well
2430
01:30:12,080 --> 01:30:13,760
we should ask them for their gender
2431
01:30:13,760 --> 01:30:16,639
right so input
2432
01:30:16,639 --> 01:30:20,000
what is your gender
2433
01:30:20,000 --> 01:30:22,719
male slash female right so they know
2434
01:30:22,719 --> 01:30:26,639
they should answer in that kind right
2435
01:30:26,639 --> 01:30:29,199
perfect so when they enter that it can
2436
01:30:29,199 --> 01:30:30,560
be either
2437
01:30:30,560 --> 01:30:32,719
mrf right that's what we're looking for
2438
01:30:32,719 --> 01:30:33,760
and
2439
01:30:33,760 --> 01:30:36,239
a good thing is always to
2440
01:30:36,239 --> 01:30:38,560
convert the input to a specific type so
2441
01:30:38,560 --> 01:30:40,320
we don't have to take all the cases
2442
01:30:40,320 --> 01:30:42,800
lowercase and uppercase and so forth
2443
01:30:42,800 --> 01:30:45,840
so for this one we will just immediately
2444
01:30:45,840 --> 01:30:48,560
put it to uppercase so gender upper
2445
01:30:48,560 --> 01:30:50,560
right
2446
01:30:50,560 --> 01:30:53,120
so now for the if statement so if
2447
01:30:53,120 --> 01:30:56,239
gender equals equals male right so we
2448
01:30:56,239 --> 01:30:58,000
know it's uppercase so we can just do it
2449
01:30:58,000 --> 01:30:59,440
as male right
2450
01:30:59,440 --> 01:31:02,400
then let's just see if it works print
2451
01:31:02,400 --> 01:31:03,000
male
2452
01:31:03,000 --> 01:31:04,320
[Music]
2453
01:31:04,320 --> 01:31:05,760
elif
2454
01:31:05,760 --> 01:31:07,440
gender
2455
01:31:07,440 --> 01:31:09,920
equals equals female so why would i want
2456
01:31:09,920 --> 01:31:12,320
not just make else here well you could
2457
01:31:12,320 --> 01:31:14,639
do that but sometimes people put wrong
2458
01:31:14,639 --> 01:31:17,600
formatted input there right so
2459
01:31:17,600 --> 01:31:19,520
print
2460
01:31:19,520 --> 01:31:21,440
female
2461
01:31:21,440 --> 01:31:23,840
and then we can say else
2462
01:31:23,840 --> 01:31:25,040
print
2463
01:31:25,040 --> 01:31:27,600
unknown
2464
01:31:27,679 --> 01:31:29,440
or wrong format let's just say wrong
2465
01:31:29,440 --> 01:31:32,320
format wrong format
2466
01:31:32,320 --> 01:31:33,199
okay
2467
01:31:33,199 --> 01:31:35,760
so this is basically trying to capture
2468
01:31:35,760 --> 01:31:38,239
the first step here if it's male or
2469
01:31:38,239 --> 01:31:40,000
female so let's just focus on that and
2470
01:31:40,000 --> 01:31:42,080
let's try to evaluate that
2471
01:31:42,080 --> 01:31:44,880
so what is your gender well male male it
2472
01:31:44,880 --> 01:31:47,840
works what is your gender capital m it
2473
01:31:47,840 --> 01:31:49,440
also works obviously
2474
01:31:49,440 --> 01:31:52,239
what is your gender female it works
2475
01:31:52,239 --> 01:31:53,440
what is your
2476
01:31:53,440 --> 01:31:55,840
gender okay let's say g
2477
01:31:55,840 --> 01:31:58,480
well wrong format right
2478
01:31:58,480 --> 01:31:59,360
so
2479
01:31:59,360 --> 01:32:00,560
this is
2480
01:32:00,560 --> 01:32:02,960
one way because then we don't falsely
2481
01:32:02,960 --> 01:32:05,360
assume it's a female if we write
2482
01:32:05,360 --> 01:32:07,199
something wrong right so
2483
01:32:07,199 --> 01:32:08,080
just
2484
01:32:08,080 --> 01:32:10,239
for that so let's go to the next one
2485
01:32:10,239 --> 01:32:12,159
right so now we have a place in the code
2486
01:32:12,159 --> 01:32:13,520
where we actually know we are have a
2487
01:32:13,520 --> 01:32:15,840
male then we need to figure out if it's
2488
01:32:15,840 --> 01:32:19,360
he's less or equal to 26 or not right
2489
01:32:19,360 --> 01:32:21,840
okay let's do that
2490
01:32:21,840 --> 01:32:23,040
so
2491
01:32:23,040 --> 01:32:27,760
let's take h here and then set input
2492
01:32:27,760 --> 01:32:28,800
input
2493
01:32:28,800 --> 01:32:32,719
what is your age
2494
01:32:32,719 --> 01:32:34,560
and we convert that
2495
01:32:34,560 --> 01:32:37,040
to an integer immediately and then we
2496
01:32:37,040 --> 01:32:40,880
say if age less equals 26
2497
01:32:40,880 --> 01:32:44,080
and then we say print
2498
01:32:44,080 --> 01:32:46,480
less
2499
01:32:47,040 --> 01:32:49,120
less equal
2500
01:32:49,120 --> 01:32:52,239
e equal
2501
01:32:52,239 --> 01:32:53,120
to
2502
01:32:53,120 --> 01:32:55,360
26
2503
01:32:55,360 --> 01:32:56,800
and else
2504
01:32:56,800 --> 01:32:59,199
print
2505
01:33:00,000 --> 01:33:03,920
more than 26 okay so let's try to
2506
01:33:03,920 --> 01:33:05,840
execute that we take male
2507
01:33:05,840 --> 01:33:06,960
how old
2508
01:33:06,960 --> 01:33:10,080
what's your age 20 less than equal to 26
2509
01:33:10,080 --> 01:33:12,239
let's try again male
2510
01:33:12,239 --> 01:33:13,360
30
2511
01:33:13,360 --> 01:33:16,320
you're more than 26 right so now we
2512
01:33:16,320 --> 01:33:17,760
actually have that part of the decision
2513
01:33:17,760 --> 01:33:19,840
tree so let's do the final part here
2514
01:33:19,840 --> 01:33:21,760
with the female and so the female we
2515
01:33:21,760 --> 01:33:24,000
needed to prompt if it's a sports car or
2516
01:33:24,000 --> 01:33:25,199
not right
2517
01:33:25,199 --> 01:33:27,360
okay so let's say
2518
01:33:27,360 --> 01:33:28,800
a car
2519
01:33:28,800 --> 01:33:33,070
type for instance and let's say input
2520
01:33:33,070 --> 01:33:35,600
[Music]
2521
01:33:35,600 --> 01:33:39,840
what is your car type right and we are
2522
01:33:39,840 --> 01:33:42,960
interested in sport
2523
01:33:42,960 --> 01:33:45,760
sports or non-sports
2524
01:33:45,760 --> 01:33:47,199
car right
2525
01:33:47,199 --> 01:33:50,239
perfect so if let's also just convert
2526
01:33:50,239 --> 01:33:51,760
that type
2527
01:33:51,760 --> 01:33:52,719
to
2528
01:33:52,719 --> 01:33:54,320
we don't have to put upper but we did
2529
01:33:54,320 --> 01:33:56,080
that
2530
01:33:56,080 --> 01:33:58,159
card type
2531
01:33:58,159 --> 01:33:59,520
upper
2532
01:33:59,520 --> 01:34:00,480
upper
2533
01:34:00,480 --> 01:34:01,840
and then say if
2534
01:34:01,840 --> 01:34:03,679
car
2535
01:34:03,679 --> 01:34:06,159
type equals equals
2536
01:34:06,159 --> 01:34:09,440
sports now we need to put in a number
2537
01:34:09,440 --> 01:34:12,560
then we say print
2538
01:34:14,880 --> 01:34:16,719
sport car
2539
01:34:16,719 --> 01:34:19,040
sports car
2540
01:34:19,040 --> 01:34:20,960
else
2541
01:34:20,960 --> 01:34:23,159
print
2542
01:34:23,159 --> 01:34:24,880
non-sport
2543
01:34:24,880 --> 01:34:26,000
sport
2544
01:34:26,000 --> 01:34:28,639
sports car it goes well right perfect so
2545
01:34:28,639 --> 01:34:30,080
let's try this one
2546
01:34:30,080 --> 01:34:31,760
we are female
2547
01:34:31,760 --> 01:34:34,239
what the type of car let's just take
2548
01:34:34,239 --> 01:34:35,360
sports
2549
01:34:35,360 --> 01:34:38,000
sports car right let me try again
2550
01:34:38,000 --> 01:34:41,840
uh female and we say false we say
2551
01:34:41,840 --> 01:34:42,719
none
2552
01:34:42,719 --> 01:34:45,119
okay non-sports car right
2553
01:34:45,119 --> 01:34:46,880
so here you have it so now we actually
2554
01:34:46,880 --> 01:34:49,600
have all the cases here and so we have
2555
01:34:49,600 --> 01:34:51,679
built this decision tree now it's time
2556
01:34:51,679 --> 01:34:54,159
to build the logic or the calculations
2557
01:34:54,159 --> 01:34:56,719
based on that so if you remember here we
2558
01:34:56,719 --> 01:34:58,880
need to find the market price and based
2559
01:34:58,880 --> 01:35:01,520
on the market price we should calculate
2560
01:35:01,520 --> 01:35:02,320
the
2561
01:35:02,320 --> 01:35:05,119
yearly payment of the percentage on
2562
01:35:05,119 --> 01:35:06,639
these areas so what we can do is
2563
01:35:06,639 --> 01:35:08,800
actually we can have a variable called
2564
01:35:08,800 --> 01:35:10,719
percentage and
2565
01:35:10,719 --> 01:35:12,239
let's do that
2566
01:35:12,239 --> 01:35:15,040
so let's say percentage
2567
01:35:15,040 --> 01:35:20,480
of 26 here that was then it was 23
2568
01:35:20,480 --> 01:35:22,800
and uh this one here
2569
01:35:22,800 --> 01:35:25,760
percentage it is 9
2570
01:35:25,760 --> 01:35:27,760
and if it was oops
2571
01:35:27,760 --> 01:35:31,119
a female sports car percentage
2572
01:35:31,119 --> 01:35:32,639
it was what was
2573
01:35:32,639 --> 01:35:34,880
21
2574
01:35:34,880 --> 01:35:37,600
and non-sports car female
2575
01:35:37,600 --> 01:35:39,199
percentage
2576
01:35:39,199 --> 01:35:41,119
10.
2577
01:35:41,119 --> 01:35:42,400
and this one here
2578
01:35:42,400 --> 01:35:44,159
percentage
2579
01:35:44,159 --> 01:35:45,760
let's just put it
2580
01:35:45,760 --> 01:35:48,800
to none okay
2581
01:35:48,800 --> 01:35:51,040
so the second thing is we need to know
2582
01:35:51,040 --> 01:35:52,960
the market price so
2583
01:35:52,960 --> 01:35:54,080
you can do that in different ways you
2584
01:35:54,080 --> 01:35:56,239
can ask before or after for instance in
2585
01:35:56,239 --> 01:35:58,239
our scenario here let's just keep the
2586
01:35:58,239 --> 01:36:00,000
structure of program first to figure out
2587
01:36:00,000 --> 01:36:02,320
our male female what age and then we ask
2588
01:36:02,320 --> 01:36:05,239
for the market price of the car right
2589
01:36:05,239 --> 01:36:06,880
market
2590
01:36:06,880 --> 01:36:09,119
price
2591
01:36:09,119 --> 01:36:10,960
input
2592
01:36:10,960 --> 01:36:13,520
what is the market
2593
01:36:13,520 --> 01:36:15,679
price of your
2594
01:36:15,679 --> 01:36:17,119
car
2595
01:36:17,119 --> 01:36:18,080
okay
2596
01:36:18,080 --> 01:36:21,600
and based on that we can actually
2597
01:36:23,280 --> 01:36:26,400
calculate the insurance insurance
2598
01:36:26,400 --> 01:36:29,280
insurance offer which is the market
2599
01:36:29,280 --> 01:36:30,320
price
2600
01:36:30,320 --> 01:36:32,320
market
2601
01:36:32,320 --> 01:36:34,880
okay it was a g their market price
2602
01:36:34,880 --> 01:36:36,719
times percentage
2603
01:36:36,719 --> 01:36:38,800
divided by 100 right then you get the
2604
01:36:38,800 --> 01:36:40,320
market price
2605
01:36:40,320 --> 01:36:41,840
print
2606
01:36:41,840 --> 01:36:45,199
and the formatted prank print you
2607
01:36:45,199 --> 01:36:46,960
okay
2608
01:36:46,960 --> 01:36:51,360
let's just say insurance ensure
2609
01:36:51,360 --> 01:36:52,639
insure
2610
01:36:52,639 --> 01:36:55,250
rents offer
2611
01:36:55,250 --> 01:36:56,320
[Music]
2612
01:36:56,320 --> 01:36:59,440
here an insurance offer here okay let's
2613
01:36:59,440 --> 01:37:04,840
try that so let's do the story here mail
2614
01:37:04,840 --> 01:37:06,480
25
2615
01:37:06,480 --> 01:37:09,760
and the price is let's just say 10 000.
2616
01:37:09,760 --> 01:37:11,679
and then we have an uh
2617
01:37:11,679 --> 01:37:13,679
wrong here because what did why did i
2618
01:37:13,679 --> 01:37:16,000
forget actually i did forget that it is
2619
01:37:16,000 --> 01:37:19,040
to convert this one to an integer right
2620
01:37:19,040 --> 01:37:22,080
so it says here type error i'm really
2621
01:37:22,080 --> 01:37:24,159
fast to read this maybe it wouldn't be
2622
01:37:24,159 --> 01:37:26,000
so fast right but it says unsupported
2623
01:37:26,000 --> 01:37:28,239
operand type division string and it
2624
01:37:28,239 --> 01:37:30,159
right so i know something went wrong
2625
01:37:30,159 --> 01:37:32,560
with a string here and that's the one
2626
01:37:32,560 --> 01:37:34,719
here right
2627
01:37:34,719 --> 01:37:36,960
so what we needed to do is
2628
01:37:36,960 --> 01:37:39,440
convert market
2629
01:37:39,440 --> 01:37:40,880
price to an int
2630
01:37:40,880 --> 01:37:42,080
int
2631
01:37:42,080 --> 01:37:44,320
market price and again i mean
2632
01:37:44,320 --> 01:37:46,719
making mistakes like this is common
2633
01:37:46,719 --> 01:37:48,480
every programmer knows it
2634
01:37:48,480 --> 01:37:50,880
and uh
2635
01:37:50,880 --> 01:37:52,719
it happens all the time
2636
01:37:52,719 --> 01:37:54,239
so here's the offer right it's a pretty
2637
01:37:54,239 --> 01:37:57,199
expensive offer 2 300 for insurance per
2638
01:37:57,199 --> 01:37:58,880
year but you know he's in the wrong
2639
01:37:58,880 --> 01:38:01,280
group so let's just take me
2640
01:38:01,280 --> 01:38:02,880
i don't like this insurance company
2641
01:38:02,880 --> 01:38:04,320
right male 1
2642
01:38:04,320 --> 01:38:07,119
30 i'm still 30 and if i had a car for
2643
01:38:07,119 --> 01:38:09,679
10 000 it's like 900 per year i still
2644
01:38:09,679 --> 01:38:11,440
find it quite expensive but you know
2645
01:38:11,440 --> 01:38:13,760
it's just an example here right and then
2646
01:38:13,760 --> 01:38:15,040
you can play around with that right but
2647
01:38:15,040 --> 01:38:17,520
the key thing is now you learn how to
2648
01:38:17,520 --> 01:38:18,719
turn this
2649
01:38:18,719 --> 01:38:20,880
decision tree into some code isn't that
2650
01:38:20,880 --> 01:38:23,840
amazing i mean come on you can make
2651
01:38:23,840 --> 01:38:26,159
the most advanced decision trees now but
2652
01:38:26,159 --> 01:38:27,840
based on that you can mix the logic
2653
01:38:27,840 --> 01:38:30,239
behind that you can make a program flow
2654
01:38:30,239 --> 01:38:31,520
behind that
2655
01:38:31,520 --> 01:38:34,159
wow that's powerful and that's amazing i
2656
01:38:34,159 --> 01:38:35,679
hope you enjoyed that because that's
2657
01:38:35,679 --> 01:38:38,239
amazing so that was the end of this
2658
01:38:38,239 --> 01:38:39,600
lesson here and then in the next one
2659
01:38:39,600 --> 01:38:41,600
we're gonna dive into randomness to
2660
01:38:41,600 --> 01:38:43,520
create use randomness to create actually
2661
01:38:43,520 --> 01:38:45,040
awesome games it's going to be awesome
2662
01:38:45,040 --> 01:38:48,560
so see you in a moment bye-bye
2663
01:38:50,880 --> 01:38:53,280
so far we covered a lot we can actually
2664
01:38:53,280 --> 01:38:55,840
turn decision diagrams into code now
2665
01:38:55,840 --> 01:38:57,840
isn't that amazing i mean now you can
2666
01:38:57,840 --> 01:39:00,880
make their most crazy structures into
2667
01:39:00,880 --> 01:39:03,199
programs right but they're still missing
2668
01:39:03,199 --> 01:39:04,400
something right
2669
01:39:04,400 --> 01:39:07,600
imagine you want to make a game right
2670
01:39:07,600 --> 01:39:08,639
and
2671
01:39:08,639 --> 01:39:10,560
well what is it you need in the game
2672
01:39:10,560 --> 01:39:12,080
what is it that makes it exciting that
2673
01:39:12,080 --> 01:39:14,239
is something unexpected right something
2674
01:39:14,239 --> 01:39:16,239
you cannot predict and that's where
2675
01:39:16,239 --> 01:39:18,320
randomness coming into the picture right
2676
01:39:18,320 --> 01:39:20,719
imagine you need to
2677
01:39:20,719 --> 01:39:23,119
to model a die right you roll a die
2678
01:39:23,119 --> 01:39:26,080
right it can be a number between one and
2679
01:39:26,080 --> 01:39:28,159
six not between including one and six
2680
01:39:28,159 --> 01:39:29,119
right
2681
01:39:29,119 --> 01:39:30,239
and uh
2682
01:39:30,239 --> 01:39:31,920
how would you model that with all you
2683
01:39:31,920 --> 01:39:34,480
know right now well you couldn't you
2684
01:39:34,480 --> 01:39:36,800
could make a function called no you
2685
01:39:36,800 --> 01:39:38,960
couldn't actually but that's where
2686
01:39:38,960 --> 01:39:41,280
randomness comes into the picture giving
2687
01:39:41,280 --> 01:39:43,199
some you know unexpected something you
2688
01:39:43,199 --> 01:39:45,360
cannot predict this makes games funny
2689
01:39:45,360 --> 01:39:47,900
right it makes it possible to
2690
01:39:47,900 --> 01:39:48,960
[Music]
2691
01:39:48,960 --> 01:39:51,840
make it interactive right
2692
01:39:51,840 --> 01:39:54,639
good let's get started so in jupyter
2693
01:39:54,639 --> 01:39:56,320
notebook the only thing we need to learn
2694
01:39:56,320 --> 01:39:58,800
in this lesson here is random it's a
2695
01:39:58,800 --> 01:40:01,520
library and we'll just import it and
2696
01:40:01,520 --> 01:40:02,880
that will teach you how to import a
2697
01:40:02,880 --> 01:40:05,840
library it's kind of like we did with a
2698
01:40:05,840 --> 01:40:08,560
sin of python we it right but it's not
2699
01:40:08,560 --> 01:40:09,760
the sin of
2700
01:40:09,760 --> 01:40:11,360
python is not really a library because
2701
01:40:11,360 --> 01:40:12,800
it's no functionality just prints the
2702
01:40:12,800 --> 01:40:15,119
sin of python right so what we want to
2703
01:40:15,119 --> 01:40:17,360
do here is import the random library and
2704
01:40:17,360 --> 01:40:19,520
use it and see how it what it is and
2705
01:40:19,520 --> 01:40:21,920
what it does so let's do that so a
2706
01:40:21,920 --> 01:40:25,040
library is like a collection of a lot of
2707
01:40:25,040 --> 01:40:27,280
information and if you're more curious
2708
01:40:27,280 --> 01:40:29,760
about that please check the e-book it's
2709
01:40:29,760 --> 01:40:31,360
also described what the library is in
2710
01:40:31,360 --> 01:40:34,239
that one for this lecture here okay
2711
01:40:34,239 --> 01:40:36,719
so let's get started here so import
2712
01:40:36,719 --> 01:40:39,440
random so this will give access to the
2713
01:40:39,440 --> 01:40:41,520
random library which does a lot of
2714
01:40:41,520 --> 01:40:43,199
random stuff
2715
01:40:43,199 --> 01:40:45,520
so we imported it so nothing happens
2716
01:40:45,520 --> 01:40:47,040
when you import it but it just makes
2717
01:40:47,040 --> 01:40:49,440
available that you can access a random
2718
01:40:49,440 --> 01:40:51,360
thing here how can you see that you can
2719
01:40:51,360 --> 01:40:53,760
say random dot and then you can
2720
01:40:53,760 --> 01:40:55,040
put
2721
01:40:55,040 --> 01:40:56,159
space
2722
01:40:56,159 --> 01:40:58,320
space after here now space tab what's
2723
01:40:58,320 --> 01:40:59,360
meaning and then you see a lot of
2724
01:40:59,360 --> 01:41:00,800
functionality we're not going to cover
2725
01:41:00,800 --> 01:41:02,880
all that we're just going to cover a few
2726
01:41:02,880 --> 01:41:05,679
of them to see what it does right
2727
01:41:05,679 --> 01:41:06,880
so
2728
01:41:06,880 --> 01:41:09,440
a great one is randint and what does it
2729
01:41:09,440 --> 01:41:11,360
do let's look at the documentation
2730
01:41:11,360 --> 01:41:12,560
randint
2731
01:41:12,560 --> 01:41:14,000
well
2732
01:41:14,000 --> 01:41:16,400
quite simple returns random integer in
2733
01:41:16,400 --> 01:41:20,000
range one to b no not one a to b
2734
01:41:20,000 --> 01:41:21,920
including both end points right these
2735
01:41:21,920 --> 01:41:23,280
are often important right does it
2736
01:41:23,280 --> 01:41:24,480
include or doesn't it include the
2737
01:41:24,480 --> 01:41:26,560
endpoints these include right so for
2738
01:41:26,560 --> 01:41:29,679
instance if we wanted to model a die
2739
01:41:29,679 --> 01:41:31,679
it can be one to six because it will
2740
01:41:31,679 --> 01:41:34,080
return a number between one and six both
2741
01:41:34,080 --> 01:41:36,560
inclusive right so roll it
2742
01:41:36,560 --> 01:41:40,400
three roll it six roll it six again roll
2743
01:41:40,400 --> 01:41:42,560
it one right so here you have it right
2744
01:41:42,560 --> 01:41:43,600
now we can
2745
01:41:43,600 --> 01:41:45,360
model a die just with this one here
2746
01:41:45,360 --> 01:41:46,960
right so
2747
01:41:46,960 --> 01:41:48,880
basically if we didn't import this
2748
01:41:48,880 --> 01:41:50,719
random we wouldn't be able to write a
2749
01:41:50,719 --> 01:41:52,800
random dot random that will not work
2750
01:41:52,800 --> 01:41:55,040
right that should be clear to you right
2751
01:41:55,040 --> 01:41:56,320
so that's
2752
01:41:56,320 --> 01:41:58,400
that's the purpose of this import stand
2753
01:41:58,400 --> 01:42:00,719
statement it imports
2754
01:42:00,719 --> 01:42:02,239
the library
2755
01:42:02,239 --> 01:42:04,080
two others that are useful it's like the
2756
01:42:04,080 --> 01:42:06,320
random uniform
2757
01:42:06,320 --> 01:42:09,119
and what the uniform does is as you see
2758
01:42:09,119 --> 01:42:10,000
here
2759
01:42:10,000 --> 01:42:12,880
it gets a random number in the range a
2760
01:42:12,880 --> 01:42:13,760
to b
2761
01:42:13,760 --> 01:42:15,520
or a to b
2762
01:42:15,520 --> 01:42:17,920
i mean it's it's if it includes b or not
2763
01:42:17,920 --> 01:42:19,520
it depending on the rounding right so
2764
01:42:19,520 --> 01:42:21,920
it's it might do it might not do right
2765
01:42:21,920 --> 01:42:23,440
so often you need the uniform random
2766
01:42:23,440 --> 01:42:25,760
number it can be between zero and one
2767
01:42:25,760 --> 01:42:28,639
right so as you see here it will get you
2768
01:42:28,639 --> 01:42:30,639
some crazy
2769
01:42:30,639 --> 01:42:32,719
number here right and it changes and
2770
01:42:32,719 --> 01:42:35,360
it's between zero and one zero is
2771
01:42:35,360 --> 01:42:37,520
inclusive and one might be inclusive
2772
01:42:37,520 --> 01:42:38,880
right
2773
01:42:38,880 --> 01:42:40,719
but as you see here it might not really
2774
01:42:40,719 --> 01:42:43,280
matter it will be so unlikely you hit
2775
01:42:43,280 --> 01:42:45,520
zero or one anyhow and if you're into
2776
01:42:45,520 --> 01:42:48,320
statistics there's also the possibility
2777
01:42:48,320 --> 01:42:51,040
to get a norm
2778
01:42:51,040 --> 01:42:53,440
gaussian or normal distribution and you
2779
01:42:53,440 --> 01:42:54,840
get that by
2780
01:42:54,840 --> 01:42:56,560
random
2781
01:42:56,560 --> 01:42:58,080
cause
2782
01:42:58,080 --> 01:42:59,520
and you see here
2783
01:42:59,520 --> 01:43:02,080
it goes young distribution right
2784
01:43:02,080 --> 01:43:06,400
and yeah i'll just take 0 and 1 here and
2785
01:43:06,400 --> 01:43:07,920
then you can use that and as you see
2786
01:43:07,920 --> 01:43:09,520
here you get
2787
01:43:09,520 --> 01:43:11,920
random numbers based on that okay
2788
01:43:11,920 --> 01:43:14,880
so basically this is all we need to get
2789
01:43:14,880 --> 01:43:16,719
started with the project
2790
01:43:16,719 --> 01:43:18,639
later actually we're gonna add
2791
01:43:18,639 --> 01:43:20,800
use more functionality from this random
2792
01:43:20,800 --> 01:43:23,920
library but uh as we don't have a list
2793
01:43:23,920 --> 01:43:26,080
learned about lists yet it doesn't make
2794
01:43:26,080 --> 01:43:28,239
sense to introduce it now right so when
2795
01:43:28,239 --> 01:43:30,000
later we learn about lists i'm gonna
2796
01:43:30,000 --> 01:43:31,840
show you some more tricks with this
2797
01:43:31,840 --> 01:43:33,760
random library but for now we can
2798
01:43:33,760 --> 01:43:35,520
actually start creating some awesome
2799
01:43:35,520 --> 01:43:38,000
games it's gonna be really fun so let's
2800
01:43:38,000 --> 01:43:41,520
do that so see you in a moment
2801
01:43:44,000 --> 01:43:46,639
so are you ready for another awesome
2802
01:43:46,639 --> 01:43:48,800
project so let's get started right so
2803
01:43:48,800 --> 01:43:50,719
we're gonna actually make two small
2804
01:43:50,719 --> 01:43:52,480
games here and the first one is a math
2805
01:43:52,480 --> 01:43:54,960
game and the other one is rock scissor
2806
01:43:54,960 --> 01:43:57,280
or rock paper scissor game if you don't
2807
01:43:57,280 --> 01:43:58,639
know them don't worry they are kind of
2808
01:43:58,639 --> 01:44:00,960
described here so the first
2809
01:44:00,960 --> 01:44:02,639
simple game will be
2810
01:44:02,639 --> 01:44:04,239
create a math game right
2811
01:44:04,239 --> 01:44:05,520
so the first thing you need to do is
2812
01:44:05,520 --> 01:44:07,920
import random because you need the
2813
01:44:07,920 --> 01:44:09,199
randomness right
2814
01:44:09,199 --> 01:44:10,159
so
2815
01:44:10,159 --> 01:44:11,760
what you want to do here is actually to
2816
01:44:11,760 --> 01:44:13,760
get a random integer in the range one to
2817
01:44:13,760 --> 01:44:15,920
ten and then you get another random
2818
01:44:15,920 --> 01:44:18,080
integer from one to ten and then you
2819
01:44:18,080 --> 01:44:21,440
prompt the user to what is integers
2820
01:44:21,440 --> 01:44:23,119
multiply right so you ask them if for
2821
01:44:23,119 --> 01:44:24,560
instance the first one was three and the
2822
01:44:24,560 --> 01:44:27,119
second one was seven then you ask what
2823
01:44:27,119 --> 01:44:29,280
is three times seven
2824
01:44:29,280 --> 01:44:31,920
and then you print correct if it's
2825
01:44:31,920 --> 01:44:33,360
correct and
2826
01:44:33,360 --> 01:44:35,280
not correct if it is
2827
01:44:35,280 --> 01:44:37,040
and print the correct answer in that
2828
01:44:37,040 --> 01:44:39,119
case okay that makes sense right so this
2829
01:44:39,119 --> 01:44:40,480
is kind of like a math game it's good
2830
01:44:40,480 --> 01:44:42,800
for training your math skills i mean at
2831
01:44:42,800 --> 01:44:44,880
least
2832
01:44:44,880 --> 01:44:46,080
my math
2833
01:44:46,080 --> 01:44:48,880
skills can be corrected
2834
01:44:48,880 --> 01:44:50,960
at least my math skills could be a bit
2835
01:44:50,960 --> 01:44:52,719
better i guess it's been some years
2836
01:44:52,719 --> 01:44:54,480
since i was calculating my head so i'm
2837
01:44:54,480 --> 01:44:56,000
gonna be excited to see in the next one
2838
01:44:56,000 --> 01:44:58,400
if i can answer this fast i'll
2839
01:44:58,400 --> 01:45:00,719
i assume you challenge me right
2840
01:45:00,719 --> 01:45:03,440
good and then for this one here rock
2841
01:45:03,440 --> 01:45:06,000
paper scissor game right so i don't know
2842
01:45:06,000 --> 01:45:07,520
if you know it right so it's like this
2843
01:45:07,520 --> 01:45:09,760
rock scissor paper and then it's like
2844
01:45:09,760 --> 01:45:12,320
you go for one of them it's like scissor
2845
01:45:12,320 --> 01:45:14,719
paper and brock right and you don't
2846
01:45:14,719 --> 01:45:16,800
stand two guys or how many you are and
2847
01:45:16,800 --> 01:45:19,760
it's like rock scissor paper oh i win
2848
01:45:19,760 --> 01:45:22,800
rock scissor paper i win this one is
2849
01:45:22,800 --> 01:45:24,800
rock all the time right
2850
01:45:24,800 --> 01:45:26,639
apparently it's not so smart that's my
2851
01:45:26,639 --> 01:45:29,280
left hand it's not so smart okay good so
2852
01:45:29,280 --> 01:45:31,440
you need to implement that right and uh
2853
01:45:31,440 --> 01:45:33,520
actually there's no description because
2854
01:45:33,520 --> 01:45:35,600
it's gonna be you know a bit tricky
2855
01:45:35,600 --> 01:45:36,400
right
2856
01:45:36,400 --> 01:45:38,960
obviously
2857
01:45:38,960 --> 01:45:40,800
there's some randomness here right so
2858
01:45:40,800 --> 01:45:42,480
how do you do that right so
2859
01:45:42,480 --> 01:45:44,400
at least the computer
2860
01:45:44,400 --> 01:45:46,639
should enter something right rocks is a
2861
01:45:46,639 --> 01:45:50,400
paper and so should user user do right
2862
01:45:50,400 --> 01:45:52,159
so how do you model that how do you do
2863
01:45:52,159 --> 01:45:55,520
that it might be a bit tricky and i left
2864
01:45:55,520 --> 01:45:58,239
it without hints here for you to think
2865
01:45:58,239 --> 01:46:00,000
about it because one of the best way to
2866
01:46:00,000 --> 01:46:02,239
learn programming is to think about it
2867
01:46:02,239 --> 01:46:04,480
and see how would i model this how would
2868
01:46:04,480 --> 01:46:07,119
i do that right and remember you can
2869
01:46:07,119 --> 01:46:08,880
only use what you learned so far so it's
2870
01:46:08,880 --> 01:46:11,760
nothing advanced here and maybe later
2871
01:46:11,760 --> 01:46:13,199
if you had to redo this you would do it
2872
01:46:13,199 --> 01:46:15,199
in a different way but i encourage you
2873
01:46:15,199 --> 01:46:17,119
to sit down and think about it maybe you
2874
01:46:17,119 --> 01:46:19,199
don't come up with a solution but that's
2875
01:46:19,199 --> 01:46:21,360
why i'm here to help you to show how i
2876
01:46:21,360 --> 01:46:23,280
would solve it with the current
2877
01:46:23,280 --> 01:46:25,679
competencies we have at this stage
2878
01:46:25,679 --> 01:46:27,280
and
2879
01:46:27,280 --> 01:46:30,239
yeah but think about it and it actually
2880
01:46:30,239 --> 01:46:32,480
this will help you learn a lot so sit
2881
01:46:32,480 --> 01:46:34,639
down maybe you start with paper in your
2882
01:46:34,639 --> 01:46:36,000
hand and write down some thoughts how
2883
01:46:36,000 --> 01:46:38,239
would i do this and see what you come up
2884
01:46:38,239 --> 01:46:39,840
with and then try to type in some code
2885
01:46:39,840 --> 01:46:41,440
if it doesn't work don't worry about it
2886
01:46:41,440 --> 01:46:43,199
this is a learning journey
2887
01:46:43,199 --> 01:46:45,199
you're not expected to know all these
2888
01:46:45,199 --> 01:46:47,520
things at first stage but
2889
01:46:47,520 --> 01:46:49,600
sitting thinking having problems that
2890
01:46:49,600 --> 01:46:52,000
are difficult will teach you the most
2891
01:46:52,000 --> 01:46:52,800
okay
2892
01:46:52,800 --> 01:46:55,040
so are you excited i am so let's get
2893
01:46:55,040 --> 01:46:57,440
started
2894
01:46:59,840 --> 01:47:01,920
so here in the first one we're actually
2895
01:47:01,920 --> 01:47:03,679
building upon most of the things we know
2896
01:47:03,679 --> 01:47:05,600
except the randomness right
2897
01:47:05,600 --> 01:47:07,440
but let's get started with this one and
2898
01:47:07,440 --> 01:47:09,679
this is like a step by step guide here
2899
01:47:09,679 --> 01:47:12,639
right so first import random
2900
01:47:12,639 --> 01:47:14,719
let's do that
2901
01:47:14,719 --> 01:47:17,760
import random
2902
01:47:17,760 --> 01:47:19,040
executed
2903
01:47:19,040 --> 01:47:20,719
okay
2904
01:47:20,719 --> 01:47:22,800
get a random integer from the range one
2905
01:47:22,800 --> 01:47:24,639
to ten both inclusive remember how that
2906
01:47:24,639 --> 01:47:27,920
was so let's just call it a
2907
01:47:27,920 --> 01:47:29,280
random
2908
01:47:29,280 --> 01:47:31,119
randint
2909
01:47:31,119 --> 01:47:33,600
one to ten right and if you're forget if
2910
01:47:33,600 --> 01:47:35,920
it's inclusive or not the documentation
2911
01:47:35,920 --> 01:47:38,639
here tells it to you right so you get
2912
01:47:38,639 --> 01:47:40,800
the documentation by shift tab inside
2913
01:47:40,800 --> 01:47:42,639
here and then you say return random
2914
01:47:42,639 --> 01:47:44,719
integer and the range a to b including
2915
01:47:44,719 --> 01:47:46,960
both endpoints right that's all that was
2916
01:47:46,960 --> 01:47:49,520
the first one and then b you should get
2917
01:47:49,520 --> 01:47:51,440
another integer right
2918
01:47:51,440 --> 01:47:52,639
random
2919
01:47:52,639 --> 01:47:56,320
randint 1 to 10. perfect
2920
01:47:56,320 --> 01:47:57,600
and now
2921
01:47:57,600 --> 01:48:00,080
prompt the user for
2922
01:48:00,080 --> 01:48:02,320
for what the two integers multiplied is
2923
01:48:02,320 --> 01:48:04,320
right that was
2924
01:48:04,320 --> 01:48:05,920
so
2925
01:48:05,920 --> 01:48:08,080
answer
2926
01:48:08,080 --> 01:48:09,440
input
2927
01:48:09,440 --> 01:48:11,840
and we can make a formatted string here
2928
01:48:11,840 --> 01:48:14,400
and what is
2929
01:48:14,400 --> 01:48:15,760
i'm going to take
2930
01:48:15,760 --> 01:48:17,280
a
2931
01:48:17,280 --> 01:48:19,119
times
2932
01:48:19,119 --> 01:48:20,639
b
2933
01:48:20,639 --> 01:48:22,880
okay and what what should we do with the
2934
01:48:22,880 --> 01:48:23,840
answer
2935
01:48:23,840 --> 01:48:25,520
yes that's right you're good we should
2936
01:48:25,520 --> 01:48:27,440
convert it right answer
2937
01:48:27,440 --> 01:48:29,679
hint
2938
01:48:29,840 --> 01:48:31,600
answer right
2939
01:48:31,600 --> 01:48:33,840
and
2940
01:48:34,159 --> 01:48:35,440
then we need to check right this is
2941
01:48:35,440 --> 01:48:36,639
where the if statement comes into the
2942
01:48:36,639 --> 01:48:38,639
picture if
2943
01:48:38,639 --> 01:48:43,600
answer equals equals a times b and then
2944
01:48:43,600 --> 01:48:46,639
print what should we do print correct
2945
01:48:46,639 --> 01:48:48,480
print
2946
01:48:48,480 --> 01:48:50,639
correct
2947
01:48:50,639 --> 01:48:54,560
let's just do a formatted string here
2948
01:48:55,840 --> 01:48:57,360
a
2949
01:48:57,360 --> 01:48:59,119
times
2950
01:48:59,119 --> 01:49:02,080
b is
2951
01:49:02,080 --> 01:49:04,480
answer right
2952
01:49:04,480 --> 01:49:06,159
else
2953
01:49:06,159 --> 01:49:08,000
print
2954
01:49:08,000 --> 01:49:09,760
format
2955
01:49:09,760 --> 01:49:13,480
in correct
2956
01:49:14,000 --> 01:49:14,410
a
2957
01:49:14,410 --> 01:49:15,760
[Music]
2958
01:49:15,760 --> 01:49:16,960
times
2959
01:49:16,960 --> 01:49:18,159
b
2960
01:49:18,159 --> 01:49:19,440
is
2961
01:49:19,440 --> 01:49:22,159
a times b right
2962
01:49:22,159 --> 01:49:23,520
perfect
2963
01:49:23,520 --> 01:49:24,880
here we go
2964
01:49:24,880 --> 01:49:26,320
let's try to run it
2965
01:49:26,320 --> 01:49:28,880
are you ready to humiliate me
2966
01:49:28,880 --> 01:49:29,920
are you
2967
01:49:29,920 --> 01:49:32,719
okay let's let's see how it goes eight
2968
01:49:32,719 --> 01:49:34,560
times same sixty-four
2969
01:49:34,560 --> 01:49:36,880
yes correct
2970
01:49:36,880 --> 01:49:40,000
two times four it's eight perfect
2971
01:49:40,000 --> 01:49:43,920
two times ten is twenty perfect
2972
01:49:43,920 --> 01:49:44,880
oh
2973
01:49:44,880 --> 01:49:46,800
uh 21
2974
01:49:46,800 --> 01:49:47,840
yes
2975
01:49:47,840 --> 01:49:50,800
4 times 6 times 4 is 24
2976
01:49:50,800 --> 01:49:51,760
awesome
2977
01:49:51,760 --> 01:49:54,480
7 times 9 is
2978
01:49:54,480 --> 01:49:57,840
63 holy smokes it's difficult
2979
01:49:57,840 --> 01:50:00,320
seven times nine is 63 second times it's
2980
01:50:00,320 --> 01:50:02,320
easier
2981
01:50:02,320 --> 01:50:05,199
and uh 40 okay so you get the you get
2982
01:50:05,199 --> 01:50:08,719
the picture so at least i managed
2983
01:50:08,719 --> 01:50:10,639
at some stage i mean if you're really
2984
01:50:10,639 --> 01:50:12,239
really into this game you can also put a
2985
01:50:12,239 --> 01:50:14,239
timing element to see how long people
2986
01:50:14,239 --> 01:50:15,040
are
2987
01:50:15,040 --> 01:50:17,199
uh we will not cover that in this one
2988
01:50:17,199 --> 01:50:19,040
but there's another library called time
2989
01:50:19,040 --> 01:50:20,400
which you can include and then you can
2990
01:50:20,400 --> 01:50:22,239
actually time how fast people are and
2991
01:50:22,239 --> 01:50:24,400
put a score based on that
2992
01:50:24,400 --> 01:50:25,520
it's just a
2993
01:50:25,520 --> 01:50:27,599
way to make it more advanced
2994
01:50:27,599 --> 01:50:29,679
so for the next one here
2995
01:50:29,679 --> 01:50:31,760
we have rock
2996
01:50:31,760 --> 01:50:35,280
rock scissor paper rock paper scissors
2997
01:50:35,280 --> 01:50:36,800
it's called but here's the rock but this
2998
01:50:36,800 --> 01:50:39,599
is what it beats right so
2999
01:50:39,599 --> 01:50:42,639
we have that scissor beats paper and
3000
01:50:42,639 --> 01:50:45,840
paper beats rock and rock beats
3001
01:50:45,840 --> 01:50:48,159
scissor right this is how it is right so
3002
01:50:48,159 --> 01:50:49,920
what we need to do is actually we need
3003
01:50:49,920 --> 01:50:52,400
to prompt the user first for an input
3004
01:50:52,400 --> 01:50:54,480
right so how would you model this right
3005
01:50:54,480 --> 01:50:55,199
so
3006
01:50:55,199 --> 01:50:56,960
so again when you're modeling you it's
3007
01:50:56,960 --> 01:50:58,800
it's nice to say okay what will the
3008
01:50:58,800 --> 01:51:00,960
computer do the computer is can return
3009
01:51:00,960 --> 01:51:03,840
an integer one two three for instance so
3010
01:51:03,840 --> 01:51:06,080
what if we prompt the user to say one
3011
01:51:06,080 --> 01:51:08,400
two or three somehow right instead of
3012
01:51:08,400 --> 01:51:10,239
saying rock scissors paper we could also
3013
01:51:10,239 --> 01:51:11,599
just ask them to write rock scissor
3014
01:51:11,599 --> 01:51:13,920
paper but on the other hand we know we
3015
01:51:13,920 --> 01:51:15,840
need to convert something and what we
3016
01:51:15,840 --> 01:51:18,159
convert yeah that's up to you so
3017
01:51:18,159 --> 01:51:21,199
my suggestion is let's convert the user
3018
01:51:21,199 --> 01:51:23,760
input right
3019
01:51:24,000 --> 01:51:25,599
so let's just make a print statement
3020
01:51:25,599 --> 01:51:28,480
here and it says
3021
01:51:28,719 --> 01:51:29,760
enter
3022
01:51:29,760 --> 01:51:30,600
choice
3023
01:51:30,600 --> 01:51:33,280
[Music]
3024
01:51:33,280 --> 01:51:34,800
one
3025
01:51:34,800 --> 01:51:36,080
rock
3026
01:51:36,080 --> 01:51:37,760
two
3027
01:51:37,760 --> 01:51:40,080
paper
3028
01:51:40,080 --> 01:51:41,440
three
3029
01:51:41,440 --> 01:51:44,239
scissor right
3030
01:51:45,040 --> 01:51:46,880
perfect
3031
01:51:46,880 --> 01:51:49,440
no we just keep it here right and then
3032
01:51:49,440 --> 01:51:52,639
we'll have choice here
3033
01:51:52,639 --> 01:51:55,440
to be input
3034
01:51:56,400 --> 01:51:59,119
and let's just take choice
3035
01:51:59,119 --> 01:52:01,360
choice
3036
01:52:01,360 --> 01:52:02,880
one
3037
01:52:02,880 --> 01:52:04,400
two three
3038
01:52:04,400 --> 01:52:05,760
i don't know if this is nice to write
3039
01:52:05,760 --> 01:52:08,080
like that but we did i did
3040
01:52:08,080 --> 01:52:09,520
okay
3041
01:52:09,520 --> 01:52:11,920
perfect so far so good so now we enter
3042
01:52:11,920 --> 01:52:14,560
something and we need probably to
3043
01:52:14,560 --> 01:52:17,840
convert it to an integer right
3044
01:52:18,320 --> 01:52:20,639
perfect so this is us this is a user
3045
01:52:20,639 --> 01:52:22,880
right so now for the computer right so
3046
01:52:22,880 --> 01:52:24,800
let's just call it computer
3047
01:52:24,800 --> 01:52:26,320
choice
3048
01:52:26,320 --> 01:52:28,840
what can we do yes we can use random
3049
01:52:28,840 --> 01:52:30,560
rand int
3050
01:52:30,560 --> 01:52:32,719
and we can take one two three right both
3051
01:52:32,719 --> 01:52:34,320
inclusive right so now we have two
3052
01:52:34,320 --> 01:52:38,159
integers and that's nice right
3053
01:52:38,159 --> 01:52:40,800
so let's model this so we could actually
3054
01:52:40,800 --> 01:52:43,440
draw out a decision tree but let's see
3055
01:52:43,440 --> 01:52:45,199
if we can figure this one out
3056
01:52:45,199 --> 01:52:46,239
if
3057
01:52:46,239 --> 01:52:48,400
my choice is the same as computer choice
3058
01:52:48,400 --> 01:52:49,840
it's a draw right
3059
01:52:49,840 --> 01:52:51,040
so
3060
01:52:51,040 --> 01:52:52,080
if
3061
01:52:52,080 --> 01:52:53,360
choice
3062
01:52:53,360 --> 01:52:55,650
equals computer choice
3063
01:52:55,650 --> 01:52:57,520
[Music]
3064
01:52:57,520 --> 01:52:59,199
okay we should have double equal sign
3065
01:52:59,199 --> 01:53:01,920
thank you for correcting me here
3066
01:53:01,920 --> 01:53:04,000
then print
3067
01:53:04,000 --> 01:53:06,239
draw right that's the first case here
3068
01:53:06,239 --> 01:53:07,280
right
3069
01:53:07,280 --> 01:53:08,000
and
3070
01:53:08,000 --> 01:53:10,800
then we can actually just take
3071
01:53:10,800 --> 01:53:14,400
my choice right so if choice is equal to
3072
01:53:14,400 --> 01:53:16,560
one right so we have the rock here
3073
01:53:16,560 --> 01:53:19,280
that's one case here i have rock then we
3074
01:53:19,280 --> 01:53:20,960
can make an if statement inside here
3075
01:53:20,960 --> 01:53:22,639
right
3076
01:53:22,639 --> 01:53:24,239
we should actually have else if here so
3077
01:53:24,239 --> 01:53:26,800
we don't take two of them oh
3078
01:53:26,800 --> 01:53:28,000
it makes
3079
01:53:28,000 --> 01:53:31,119
sense right so if i have the rock then
3080
01:53:31,119 --> 01:53:32,480
if computer
3081
01:53:32,480 --> 01:53:34,239
if computer
3082
01:53:34,239 --> 01:53:37,040
choice is equals to we know it's not one
3083
01:53:37,040 --> 01:53:38,800
because that will be covered by the
3084
01:53:38,800 --> 01:53:40,880
first case up here right but if the
3085
01:53:40,880 --> 01:53:44,480
computer i'm rock computer is scissor
3086
01:53:44,480 --> 01:53:47,599
alright let's just start with paper
3087
01:53:47,599 --> 01:53:51,040
then actually computer wins
3088
01:53:51,520 --> 01:53:54,800
computer wins
3089
01:53:54,800 --> 01:53:56,239
we can actually just say else because in
3090
01:53:56,239 --> 01:53:58,719
the other case we know that we win
3091
01:53:58,719 --> 01:54:01,679
right because in the other case it is a
3092
01:54:01,679 --> 01:54:05,040
computer has scissor
3093
01:54:05,920 --> 01:54:06,840
you
3094
01:54:06,840 --> 01:54:10,080
win okay
3095
01:54:10,080 --> 01:54:11,840
else if
3096
01:54:11,840 --> 01:54:15,280
choice is equal to two that is a case
3097
01:54:15,280 --> 01:54:16,880
where
3098
01:54:16,880 --> 01:54:18,719
i have paper
3099
01:54:18,719 --> 01:54:21,360
paper so if computer is rock that's
3100
01:54:21,360 --> 01:54:22,480
number one
3101
01:54:22,480 --> 01:54:25,679
if computer
3102
01:54:27,119 --> 01:54:29,440
computer choice is equal to one
3103
01:54:29,440 --> 01:54:30,639
print
3104
01:54:30,639 --> 01:54:32,639
if computer
3105
01:54:32,639 --> 01:54:35,599
is one and i'm scissor right
3106
01:54:35,599 --> 01:54:38,560
then computer wins
3107
01:54:39,199 --> 01:54:41,679
and in the other case else
3108
01:54:41,679 --> 01:54:43,760
print human right
3109
01:54:43,760 --> 01:54:46,080
you win in the other case computer has
3110
01:54:46,080 --> 01:54:48,080
let's say i have two that's three so
3111
01:54:48,080 --> 01:54:51,040
computer has scissor no computer has
3112
01:54:51,040 --> 01:54:54,239
paper and i have scissor right um oh
3113
01:54:54,239 --> 01:54:56,239
i need to say it correctly right so else
3114
01:54:56,239 --> 01:54:57,840
if
3115
01:54:57,840 --> 01:55:00,560
choice equals equals three we could also
3116
01:55:00,560 --> 01:55:01,920
just have an else
3117
01:55:01,920 --> 01:55:05,280
if computer choice equally equals one
3118
01:55:05,280 --> 01:55:07,119
what happens then
3119
01:55:07,119 --> 01:55:08,719
well if
3120
01:55:08,719 --> 01:55:11,440
i am three that's a scissor and computer
3121
01:55:11,440 --> 01:55:13,040
is one
3122
01:55:13,040 --> 01:55:16,360
it's rock
3123
01:55:19,280 --> 01:55:21,599
then
3124
01:55:24,400 --> 01:55:25,360
so
3125
01:55:25,360 --> 01:55:27,599
did i do it correct and up one of the
3126
01:55:27,599 --> 01:55:29,679
two two it's like
3127
01:55:29,679 --> 01:55:30,960
paper
3128
01:55:30,960 --> 01:55:33,360
and computer was one here right so i'm
3129
01:55:33,360 --> 01:55:35,360
making a mistake here right so this is
3130
01:55:35,360 --> 01:55:36,800
this is this is difficult right so a
3131
01:55:36,800 --> 01:55:38,320
good idea is actually to add comments
3132
01:55:38,320 --> 01:55:40,239
here right so let's do that here so
3133
01:55:40,239 --> 01:55:42,080
choice one it is
3134
01:55:42,080 --> 01:55:43,199
rock
3135
01:55:43,199 --> 01:55:45,520
and choice two is
3136
01:55:45,520 --> 01:55:48,639
paper right so in this case he wins
3137
01:55:48,639 --> 01:55:50,800
right computer here
3138
01:55:50,800 --> 01:55:55,920
is here i am paper and computer is
3139
01:55:56,480 --> 01:55:58,180
rock right so
3140
01:55:58,180 --> 01:55:59,760
[Music]
3141
01:55:59,760 --> 01:56:01,760
so here actually i win
3142
01:56:01,760 --> 01:56:04,320
or computer win no you win
3143
01:56:04,320 --> 01:56:06,810
and then here in computer wins
3144
01:56:06,810 --> 01:56:09,199
[Music]
3145
01:56:09,199 --> 01:56:10,960
and wins
3146
01:56:10,960 --> 01:56:15,560
and in this case here i have
3147
01:56:15,599 --> 01:56:17,280
scissor
3148
01:56:17,280 --> 01:56:19,760
and computer has
3149
01:56:19,760 --> 01:56:20,639
rock
3150
01:56:20,639 --> 01:56:23,040
and here computer wins
3151
01:56:23,040 --> 01:56:26,000
computer wins right
3152
01:56:26,000 --> 01:56:27,119
else
3153
01:56:27,119 --> 01:56:29,360
print
3154
01:56:29,360 --> 01:56:30,800
you in
3155
01:56:30,800 --> 01:56:33,360
okay perfect okay so
3156
01:56:33,360 --> 01:56:35,599
just to make it a bit more fair maybe we
3157
01:56:35,599 --> 01:56:36,719
should have
3158
01:56:36,719 --> 01:56:39,599
computer choice
3159
01:56:39,850 --> 01:56:41,520
[Music]
3160
01:56:41,520 --> 01:56:44,560
let's just have it as
3161
01:56:47,320 --> 01:56:49,760
[Music]
3162
01:56:49,760 --> 01:56:51,679
so we see what the computer got right so
3163
01:56:51,679 --> 01:56:53,119
we can see everything is correct so
3164
01:56:53,119 --> 01:56:54,719
let's try this out it's going to be
3165
01:56:54,719 --> 01:56:57,599
awesome right so i'll just take rock and
3166
01:56:57,599 --> 01:57:00,560
computer took three that sister so i win
3167
01:57:00,560 --> 01:57:02,320
right awesome
3168
01:57:02,320 --> 01:57:04,480
and i'll just take paper and computer
3169
01:57:04,480 --> 01:57:07,520
takes three so paper and the scissor
3170
01:57:07,520 --> 01:57:09,679
that seems correct as well right and i
3171
01:57:09,679 --> 01:57:10,639
take
3172
01:57:10,639 --> 01:57:12,960
scissor and computer took scissors so
3173
01:57:12,960 --> 01:57:16,080
there's a draw perfect and i take
3174
01:57:16,080 --> 01:57:16,960
one
3175
01:57:16,960 --> 01:57:19,040
that's a rock computer takes one as a
3176
01:57:19,040 --> 01:57:20,400
draw right
3177
01:57:20,400 --> 01:57:23,440
so i take two it's a paper and computer
3178
01:57:23,440 --> 01:57:26,639
text paper draw well this is this is fun
3179
01:57:26,639 --> 01:57:29,840
and uh draw again okay so you see here
3180
01:57:29,840 --> 01:57:31,360
now you can play around with it and you
3181
01:57:31,360 --> 01:57:33,599
also saw how easily it becomes confusing
3182
01:57:33,599 --> 01:57:35,679
we didn't make a drawing of it and
3183
01:57:35,679 --> 01:57:38,159
and i was actually making a mistake here
3184
01:57:38,159 --> 01:57:40,880
and that happens all the time
3185
01:57:40,880 --> 01:57:43,520
if you don't make your
3186
01:57:43,520 --> 01:57:46,000
diligence and do the correct work right
3187
01:57:46,000 --> 01:57:48,080
so it's a good way as you also introduce
3188
01:57:48,080 --> 01:57:50,000
something here comments here which are
3189
01:57:50,000 --> 01:57:51,440
these
3190
01:57:51,440 --> 01:57:53,920
hash values here it's like the hashtag
3191
01:57:53,920 --> 01:57:55,360
here
3192
01:57:55,360 --> 01:57:57,199
then afterwards that it's common so it's
3193
01:57:57,199 --> 01:57:59,040
not executed so that's a really nice
3194
01:57:59,040 --> 01:58:02,800
feature to use as well here right so
3195
01:58:02,800 --> 01:58:05,119
this was actually amazing now we
3196
01:58:05,119 --> 01:58:07,040
actually learned about
3197
01:58:07,040 --> 01:58:08,480
randomness and we made an awesome
3198
01:58:08,480 --> 01:58:10,560
projects here with a math game and a
3199
01:58:10,560 --> 01:58:12,800
rock paper scissor game isn't that
3200
01:58:12,800 --> 01:58:14,480
exciting so are you ready for the next
3201
01:58:14,480 --> 01:58:16,639
one i think you are and it's gonna be
3202
01:58:16,639 --> 01:58:18,639
amazing i promise you that see you in a
3203
01:58:18,639 --> 01:58:21,639
moment
3204
01:58:23,920 --> 01:58:26,800
so this is going to be exciting i
3205
01:58:26,800 --> 01:58:28,639
promised you that right so we're going
3206
01:58:28,639 --> 01:58:31,040
to learn about lists so
3207
01:58:31,040 --> 01:58:33,040
lists what a list well you know this you
3208
01:58:33,040 --> 01:58:34,719
know a list on a paper right your list
3209
01:58:34,719 --> 01:58:36,800
of things right in python list is
3210
01:58:36,800 --> 01:58:39,199
basically actually the same thing it's a
3211
01:58:39,199 --> 01:58:40,800
list of
3212
01:58:40,800 --> 01:58:42,560
values or
3213
01:58:42,560 --> 01:58:45,199
list of strings list of whatever you can
3214
01:58:45,199 --> 01:58:46,639
put inside a list and you can put
3215
01:58:46,639 --> 01:58:48,480
everything inside a list right
3216
01:58:48,480 --> 01:58:50,239
so let's get started with them let's
3217
01:58:50,239 --> 01:58:52,000
jump to jupiter notebook get familiar
3218
01:58:52,000 --> 01:58:53,679
with them and see what we're gonna learn
3219
01:58:53,679 --> 01:58:56,480
in this lecture here good so inside
3220
01:58:56,480 --> 01:58:59,119
jupiter notebook it just says lists and
3221
01:58:59,119 --> 01:59:00,800
the goal is to learn about list how to
3222
01:59:00,800 --> 01:59:02,800
get a random element from a list and how
3223
01:59:02,800 --> 01:59:04,800
to make a randomization of a string
3224
01:59:04,800 --> 01:59:06,400
actually which we actually in the
3225
01:59:06,400 --> 01:59:08,880
process is going to use a list and then
3226
01:59:08,880 --> 01:59:11,280
a few nice functions as well we're also
3227
01:59:11,280 --> 01:59:13,440
going to learn a bit of the methods on a
3228
01:59:13,440 --> 01:59:15,679
list inside here so
3229
01:59:15,679 --> 01:59:18,960
what is a list well let's get started
3230
01:59:18,960 --> 01:59:20,639
we don't need to import anything because
3231
01:59:20,639 --> 01:59:23,199
list is a built-in data structure inside
3232
01:59:23,199 --> 01:59:25,520
python and a data structure is just a
3233
01:59:25,520 --> 01:59:29,520
way to have data in a nice way and again
3234
01:59:29,520 --> 01:59:32,960
the list is just a sequence of data
3235
01:59:32,960 --> 01:59:34,960
that's how you can say it
3236
01:59:34,960 --> 01:59:37,599
so let's create a list here so my list
3237
01:59:37,599 --> 01:59:38,880
let's just say
3238
01:59:38,880 --> 01:59:41,040
you created by square brackets and let's
3239
01:59:41,040 --> 01:59:44,320
just put something in here apple
3240
01:59:44,320 --> 01:59:45,920
orange
3241
01:59:45,920 --> 01:59:47,040
and
3242
01:59:47,040 --> 01:59:48,159
banana
3243
01:59:48,159 --> 01:59:51,360
okay so this is my list perfect executed
3244
01:59:51,360 --> 01:59:54,159
my list is here so what is the list well
3245
01:59:54,159 --> 01:59:56,840
let's just take a look at that list
3246
01:59:56,840 --> 01:59:59,119
here execute it
3247
01:59:59,119 --> 02:00:01,679
well it looks like this you see here
3248
02:00:01,679 --> 02:00:04,400
this list here has elements apple orange
3249
02:00:04,400 --> 02:00:06,800
and banana so how do we access elements
3250
02:00:06,800 --> 02:00:08,320
you might wonder
3251
02:00:08,320 --> 02:00:10,320
yes i wondered about that too myself you
3252
02:00:10,320 --> 02:00:12,080
use square brackets actually and then
3253
02:00:12,080 --> 02:00:14,639
you index it by number right so it
3254
02:00:14,639 --> 02:00:16,719
starts by zero so when you count as a
3255
02:00:16,719 --> 02:00:19,360
programmer in almost all programming
3256
02:00:19,360 --> 02:00:22,480
languages you start with zero
3257
02:00:22,480 --> 02:00:24,800
so let's try to execute that
3258
02:00:24,800 --> 02:00:27,679
so zero gets one the first element right
3259
02:00:27,679 --> 02:00:29,119
perfect
3260
02:00:29,119 --> 02:00:31,119
so that's the syntax of that let's try
3261
02:00:31,119 --> 02:00:33,119
to take the second element right so the
3262
02:00:33,119 --> 02:00:36,400
second element is indexed by one
3263
02:00:36,400 --> 02:00:37,840
and you see you get orange here right
3264
02:00:37,840 --> 02:00:39,840
and you can continue like that until you
3265
02:00:39,840 --> 02:00:42,480
get over the end of the list right
3266
02:00:42,480 --> 02:00:44,239
and the nice thing with python is
3267
02:00:44,239 --> 02:00:45,599
actually you can come from the opposite
3268
02:00:45,599 --> 02:00:46,960
direction
3269
02:00:46,960 --> 02:00:48,400
so you can do that with negative
3270
02:00:48,400 --> 02:00:50,320
indexing so
3271
02:00:50,320 --> 02:00:52,320
obviously you cannot start with 0 to
3272
02:00:52,320 --> 02:00:54,159
access this one because since 0 wouldn't
3273
02:00:54,159 --> 02:00:56,159
know which end to start one from so
3274
02:00:56,159 --> 02:00:59,040
that's why you index by -1 minus 2-3
3275
02:00:59,040 --> 02:01:01,360
right so let's take -1 here and you see
3276
02:01:01,360 --> 02:01:02,719
you get banana
3277
02:01:02,719 --> 02:01:05,679
and then you can continue like that with
3278
02:01:05,679 --> 02:01:07,599
-2 right
3279
02:01:07,599 --> 02:01:09,920
so you can have positive indexing
3280
02:01:09,920 --> 02:01:11,760
starting from zero here
3281
02:01:11,760 --> 02:01:13,679
or negative starting with minus one
3282
02:01:13,679 --> 02:01:16,719
minus two minus three and so forth right
3283
02:01:16,719 --> 02:01:20,159
so that was a bit about lists
3284
02:01:20,159 --> 02:01:22,400
in general and you can take an element
3285
02:01:22,400 --> 02:01:24,239
from the list right you can we will use
3286
02:01:24,239 --> 02:01:26,719
something like call pop later and pop
3287
02:01:26,719 --> 02:01:30,560
what does pop do well returns
3288
02:01:30,560 --> 02:01:32,639
uh return
3289
02:01:32,639 --> 02:01:35,280
remove and return item at index and
3290
02:01:35,280 --> 02:01:38,000
default index is -1 so that means the
3291
02:01:38,000 --> 02:01:39,920
default is the last element so let's try
3292
02:01:39,920 --> 02:01:41,119
to do that
3293
02:01:41,119 --> 02:01:42,159
so
3294
02:01:42,159 --> 02:01:43,440
you see here
3295
02:01:43,440 --> 02:01:45,040
it returned banana
3296
02:01:45,040 --> 02:01:46,960
was banana the last one
3297
02:01:46,960 --> 02:01:49,280
it was the last one here right and how
3298
02:01:49,280 --> 02:01:50,910
does my list look like now
3299
02:01:50,910 --> 02:01:53,760
[Music]
3300
02:01:53,760 --> 02:01:55,280
it only has apple and orange we've
3301
02:01:55,280 --> 02:01:56,560
removed it right
3302
02:01:56,560 --> 02:01:57,840
awesome
3303
02:01:57,840 --> 02:01:59,440
so this is what i was talking about
3304
02:01:59,440 --> 02:02:01,520
earlier that sometimes you need to be
3305
02:02:01,520 --> 02:02:02,560
sure
3306
02:02:02,560 --> 02:02:04,880
if the call you're doing is returning
3307
02:02:04,880 --> 02:02:06,880
something new or it does it on the
3308
02:02:06,880 --> 02:02:08,800
object you're working with right here it
3309
02:02:08,800 --> 02:02:10,960
does it on the object the list
3310
02:02:10,960 --> 02:02:12,719
so if we take my list we also need to
3311
02:02:12,719 --> 02:02:15,520
know append something so what should we
3312
02:02:15,520 --> 02:02:18,320
append
3313
02:02:18,320 --> 02:02:20,560
append banana back
3314
02:02:20,560 --> 02:02:21,520
okay
3315
02:02:21,520 --> 02:02:24,719
and let's say see what append does here
3316
02:02:24,719 --> 02:02:27,679
appends object to the end of the list
3317
02:02:27,679 --> 02:02:28,960
perfect
3318
02:02:28,960 --> 02:02:30,320
my list
3319
02:02:30,320 --> 02:02:31,440
my list
3320
02:02:31,440 --> 02:02:33,360
now we have banana back
3321
02:02:33,360 --> 02:02:34,800
amazing right
3322
02:02:34,800 --> 02:02:37,119
so one thing that we also often use is
3323
02:02:37,119 --> 02:02:38,960
we have multiple lists right so let's
3324
02:02:38,960 --> 02:02:41,520
just have another list here
3325
02:02:41,520 --> 02:02:43,599
and let's take some countries here
3326
02:02:43,599 --> 02:02:46,599
france
3327
02:02:46,719 --> 02:02:48,800
denmark i'm
3328
02:02:48,800 --> 02:02:51,280
living there so let's just take that and
3329
02:02:51,280 --> 02:02:54,400
sweden i can see sweden from my
3330
02:02:54,400 --> 02:02:57,040
not from my window exactly but almost
3331
02:02:57,040 --> 02:02:58,480
so
3332
02:02:58,480 --> 02:03:00,320
let's get started so we have another
3333
02:03:00,320 --> 02:03:02,400
list here so how can we concatenate the
3334
02:03:02,400 --> 02:03:04,560
list so often we want to do that right
3335
02:03:04,560 --> 02:03:08,900
so my list plus another list
3336
02:03:08,900 --> 02:03:10,480
[Music]
3337
02:03:10,480 --> 02:03:13,040
you see how easy that is
3338
02:03:13,040 --> 02:03:15,679
so again here it returns a new list in
3339
02:03:15,679 --> 02:03:17,360
this case here right so if you wanted to
3340
02:03:17,360 --> 02:03:21,440
save that one here you can just say
3341
02:03:22,000 --> 02:03:23,280
new list
3342
02:03:23,280 --> 02:03:26,320
to be this piece here right and then new
3343
02:03:26,320 --> 02:03:28,400
list will be the list of all the
3344
02:03:28,400 --> 02:03:30,880
elements right so so far so good so now
3345
02:03:30,880 --> 02:03:32,639
we have a new list with all the elements
3346
02:03:32,639 --> 02:03:35,679
from the my list and another list right
3347
02:03:35,679 --> 02:03:37,040
so these are
3348
02:03:37,040 --> 02:03:38,880
amazing functionality that you need to
3349
02:03:38,880 --> 02:03:41,760
master right so again just a pop return
3350
02:03:41,760 --> 02:03:44,239
the last element and the append
3351
02:03:44,239 --> 02:03:46,719
move put an element in the end and
3352
02:03:46,719 --> 02:03:48,880
concatenate strings by just a simple
3353
02:03:48,880 --> 02:03:51,119
plus sign here right
3354
02:03:51,119 --> 02:03:53,440
and indexing is quite easy so this
3355
02:03:53,440 --> 02:03:55,360
doesn't cover everything you need
3356
02:03:55,360 --> 02:03:57,119
everything about list but it covers what
3357
02:03:57,119 --> 02:03:58,560
you need to get started with them and
3358
02:03:58,560 --> 02:04:01,199
that's enough for this course actually
3359
02:04:01,199 --> 02:04:02,719
obviously you probably figured out there
3360
02:04:02,719 --> 02:04:04,960
are a lot of things you can do and
3361
02:04:04,960 --> 02:04:06,320
if i should go through everything it
3362
02:04:06,320 --> 02:04:08,480
will be an endless
3363
02:04:08,480 --> 02:04:10,560
mass and we will never finish
3364
02:04:10,560 --> 02:04:13,119
let's import random right
3365
02:04:13,119 --> 02:04:15,599
import random remember i promised you
3366
02:04:15,599 --> 02:04:17,760
when we came to lists i will teach you
3367
02:04:17,760 --> 02:04:20,639
something about a random well let's do
3368
02:04:20,639 --> 02:04:21,760
that
3369
02:04:21,760 --> 02:04:24,760
random
3370
02:04:26,079 --> 02:04:28,560
so let's see what random choice does
3371
02:04:28,560 --> 02:04:30,079
chooses a random element from a
3372
02:04:30,079 --> 02:04:31,840
non-empty sequence and
3373
02:04:31,840 --> 02:04:35,440
luckily a list is a sequence
3374
02:04:35,440 --> 02:04:36,960
so let's
3375
02:04:36,960 --> 02:04:39,440
take new list
3376
02:04:39,440 --> 02:04:41,440
and return it returns orange right so it
3377
02:04:41,440 --> 02:04:44,560
returns a random element right so did it
3378
02:04:44,560 --> 02:04:45,920
remove it
3379
02:04:45,920 --> 02:04:46,880
remember
3380
02:04:46,880 --> 02:04:48,639
no it didn't so it just takes a random
3381
02:04:48,639 --> 02:04:50,400
element right so
3382
02:04:50,400 --> 02:04:53,760
if we run this code again here
3383
02:04:53,760 --> 02:04:55,199
it will return a different element or
3384
02:04:55,199 --> 02:04:56,639
most likely a different element in this
3385
02:04:56,639 --> 02:04:58,639
case france here right so you see now
3386
02:04:58,639 --> 02:05:00,880
you can if you have a list of
3387
02:05:00,880 --> 02:05:02,400
whatever
3388
02:05:02,400 --> 02:05:04,840
then it can return
3389
02:05:04,840 --> 02:05:07,440
whatever another thing we will get
3390
02:05:07,440 --> 02:05:09,440
need to use is actually how do we mix it
3391
02:05:09,440 --> 02:05:11,210
up right so random
3392
02:05:11,210 --> 02:05:12,480
[Music]
3393
02:05:12,480 --> 02:05:14,320
i think it's called shuffle
3394
02:05:14,320 --> 02:05:16,079
what does shuffle do
3395
02:05:16,079 --> 02:05:18,320
it
3396
02:05:19,440 --> 02:05:22,800
shuffle list x in place and returns not
3397
02:05:22,800 --> 02:05:24,480
right so shuffle
3398
02:05:24,480 --> 02:05:25,760
takes s
3399
02:05:25,760 --> 02:05:28,639
x right here right perfect
3400
02:05:28,639 --> 02:05:31,060
so new list
3401
02:05:31,060 --> 02:05:32,320
[Music]
3402
02:05:32,320 --> 02:05:33,760
perfect
3403
02:05:33,760 --> 02:05:35,280
so what happened to new list
3404
02:05:35,280 --> 02:05:36,560
[Music]
3405
02:05:36,560 --> 02:05:38,320
it shuffled it right so it shuffled in
3406
02:05:38,320 --> 02:05:41,119
place as it says said here right so
3407
02:05:41,119 --> 02:05:42,960
again here this does it on the list
3408
02:05:42,960 --> 02:05:45,679
right so it has banana france
3409
02:05:45,679 --> 02:05:46,719
orange
3410
02:05:46,719 --> 02:05:48,239
apple
3411
02:05:48,239 --> 02:05:50,239
sweden and denmark right so it's
3412
02:05:50,239 --> 02:05:51,840
shuffled just randomly so if you run
3413
02:05:51,840 --> 02:05:53,679
this one again it will be different
3414
02:05:53,679 --> 02:05:56,960
order of the list as you see there right
3415
02:05:56,960 --> 02:05:59,040
awesome another thing that's often used
3416
02:05:59,040 --> 02:06:01,360
is actually on a string method right and
3417
02:06:01,360 --> 02:06:03,280
this is a bit awkward first time you see
3418
02:06:03,280 --> 02:06:06,000
it right so if you take a string for
3419
02:06:06,000 --> 02:06:07,920
instance this one with the space and
3420
02:06:07,920 --> 02:06:09,840
then you use join right so what does
3421
02:06:09,840 --> 02:06:11,440
join do
3422
02:06:11,440 --> 02:06:13,119
oh it doesn't do it directly on here but
3423
02:06:13,119 --> 02:06:15,280
what join does is
3424
02:06:15,280 --> 02:06:18,400
it takes the list as you see here
3425
02:06:18,400 --> 02:06:21,280
denmark apple orange sweden banana
3426
02:06:21,280 --> 02:06:23,599
france and puts it together but it joins
3427
02:06:23,599 --> 02:06:25,119
it with this
3428
02:06:25,119 --> 02:06:26,960
space we put here so actually if you put
3429
02:06:26,960 --> 02:06:28,719
the space away it will join them without
3430
02:06:28,719 --> 02:06:31,040
the space right so that's what it does
3431
02:06:31,040 --> 02:06:32,800
and this comes in really really handy
3432
02:06:32,800 --> 02:06:33,920
when you have a list and you want to
3433
02:06:33,920 --> 02:06:36,400
present it in some way then it's not
3434
02:06:36,400 --> 02:06:38,400
looking like this here right then you
3435
02:06:38,400 --> 02:06:40,320
can actually do something like this
3436
02:06:40,320 --> 02:06:41,440
and it looks
3437
02:06:41,440 --> 02:06:43,119
just as you please we will use that
3438
02:06:43,119 --> 02:06:44,639
later in the course if you don't
3439
02:06:44,639 --> 02:06:47,199
remember don't worry there's a ebook and
3440
02:06:47,199 --> 02:06:48,480
it will be written in the ebook so you
3441
02:06:48,480 --> 02:06:50,800
can always recall it like that so you
3442
02:06:50,800 --> 02:06:52,159
don't need to remember everything we
3443
02:06:52,159 --> 02:06:54,239
don't do that unless we use it on a
3444
02:06:54,239 --> 02:06:56,239
daily basis then we don't remember
3445
02:06:56,239 --> 02:06:59,199
everything so what can this be used for
3446
02:06:59,199 --> 02:07:01,199
well let's just make something a string
3447
02:07:01,199 --> 02:07:02,320
here
3448
02:07:02,320 --> 02:07:05,280
let's call this awesome
3449
02:07:05,280 --> 02:07:07,520
so i promise you i wanted to show how to
3450
02:07:07,520 --> 02:07:10,800
shuffle something right so
3451
02:07:10,800 --> 02:07:12,400
random
3452
02:07:12,400 --> 02:07:15,280
sample is another function and let's see
3453
02:07:15,280 --> 02:07:17,119
what that does right
3454
02:07:17,119 --> 02:07:18,079
and uh
3455
02:07:18,079 --> 02:07:19,920
what we wanted to do is actually stick
3456
02:07:19,920 --> 02:07:21,840
the length of the string here and add it
3457
02:07:21,840 --> 02:07:22,960
as well
3458
02:07:22,960 --> 02:07:24,639
so if you look at this function here
3459
02:07:24,639 --> 02:07:27,599
let's see what it does
3460
02:07:27,599 --> 02:07:30,239
chooses k unique random elements from
3461
02:07:30,239 --> 02:07:32,880
the population of sequence or set right
3462
02:07:32,880 --> 02:07:34,719
so that's why i have the length of the
3463
02:07:34,719 --> 02:07:36,639
string here right so i use the length
3464
02:07:36,639 --> 02:07:37,599
here
3465
02:07:37,599 --> 02:07:39,679
we haven't really been familiar with the
3466
02:07:39,679 --> 02:07:42,480
length function so far but length
3467
02:07:42,480 --> 02:07:46,079
returns a length of a string here or as
3468
02:07:46,079 --> 02:07:48,880
as of the list or whatever it is right
3469
02:07:48,880 --> 02:07:49,599
so
3470
02:07:49,599 --> 02:07:51,199
returns the number of items in a
3471
02:07:51,199 --> 02:07:53,119
container it says right and string is a
3472
02:07:53,119 --> 02:07:54,880
container list is in container and so
3473
02:07:54,880 --> 02:07:58,000
forth right so this is it takes
3474
02:07:58,000 --> 02:07:59,199
seven
3475
02:07:59,199 --> 02:08:01,280
random samples uniquely random samples
3476
02:08:01,280 --> 02:08:03,199
that means it only takes each one of
3477
02:08:03,199 --> 02:08:04,400
them once
3478
02:08:04,400 --> 02:08:06,560
because they have to be unique
3479
02:08:06,560 --> 02:08:08,639
unique in this sample here so they can
3480
02:08:08,639 --> 02:08:10,560
be duplicates because there are two e's
3481
02:08:10,560 --> 02:08:13,440
for instance here so that is okay
3482
02:08:13,440 --> 02:08:16,079
perfect so now we have the random sample
3483
02:08:16,079 --> 02:08:20,480
here so what can we do now remember join
3484
02:08:20,480 --> 02:08:22,320
[Music]
3485
02:08:22,320 --> 02:08:24,320
what if we join this right
3486
02:08:24,320 --> 02:08:26,800
then we have something here right look
3487
02:08:26,800 --> 02:08:29,920
it's different now right but
3488
02:08:29,920 --> 02:08:32,800
it is awesome right awesome
3489
02:08:32,800 --> 02:08:34,239
and if i run it again it can be
3490
02:08:34,239 --> 02:08:36,880
something different again here run
3491
02:08:36,880 --> 02:08:38,639
so now we actually take this string here
3492
02:08:38,639 --> 02:08:40,639
and scramble it this will be really
3493
02:08:40,639 --> 02:08:43,760
really handy in our project so just a
3494
02:08:43,760 --> 02:08:45,920
hint there remember these things here
3495
02:08:45,920 --> 02:08:48,840
when you do the project right perfect
3496
02:08:48,840 --> 02:08:51,840
awesome next thing right now we just
3497
02:08:51,840 --> 02:08:53,360
used
3498
02:08:53,360 --> 02:08:55,199
strings inside our list but it can be
3499
02:08:55,199 --> 02:08:56,719
anything right so
3500
02:08:56,719 --> 02:08:59,440
my numbers
3501
02:08:59,440 --> 02:09:01,199
so let's say we have a list of numbers
3502
02:09:01,199 --> 02:09:04,719
here 3 5 2 six eight
3503
02:09:04,719 --> 02:09:05,920
two
3504
02:09:05,920 --> 02:09:08,800
then we have my numbers here
3505
02:09:08,800 --> 02:09:11,599
you see here that's a list of numbers
3506
02:09:11,599 --> 02:09:13,679
so there are a lot of useful functions
3507
02:09:13,679 --> 02:09:16,560
right so let's take max you probably
3508
02:09:16,560 --> 02:09:18,800
figured that one out
3509
02:09:18,800 --> 02:09:20,480
it will return the maximal element in
3510
02:09:20,480 --> 02:09:22,960
this case it's 8 as you see here
3511
02:09:22,960 --> 02:09:25,040
and there's something called minimum
3512
02:09:25,040 --> 02:09:27,599
my numbers
3513
02:09:27,599 --> 02:09:29,920
and it returns 2 obviously
3514
02:09:29,920 --> 02:09:31,520
and
3515
02:09:31,520 --> 02:09:33,450
you can have the sum
3516
02:09:33,450 --> 02:09:36,639
[Music]
3517
02:09:36,639 --> 02:09:38,960
26
3518
02:09:38,960 --> 02:09:43,760
3 plus 5 is 8 plus 2 is 10 plus 6 is 16
3519
02:09:43,760 --> 02:09:45,360
plus
3520
02:09:45,360 --> 02:09:46,719
8
3521
02:09:46,719 --> 02:09:47,840
is
3522
02:09:47,840 --> 02:09:51,040
24 plus 2 is 26 so that's correct wow my
3523
02:09:51,040 --> 02:09:52,639
math skills i told you they can be
3524
02:09:52,639 --> 02:09:53,760
improved
3525
02:09:53,760 --> 02:09:55,920
perfect awesome right
3526
02:09:55,920 --> 02:09:58,400
so also just to remember i just told you
3527
02:09:58,400 --> 02:10:01,119
that uh it can return the length of the
3528
02:10:01,119 --> 02:10:03,119
list here so now we have that there one
3529
02:10:03,119 --> 02:10:05,360
two three four five six elements that's
3530
02:10:05,360 --> 02:10:07,040
correct right so
3531
02:10:07,040 --> 02:10:09,599
the way you can calculate the average
3532
02:10:09,599 --> 02:10:13,199
for instance is take the sum of my
3533
02:10:13,199 --> 02:10:16,800
my numbers and divided by the length of
3534
02:10:16,800 --> 02:10:19,520
my numbers right so these are all
3535
02:10:19,520 --> 02:10:22,800
awesome things to master right
3536
02:10:22,800 --> 02:10:25,360
good so far so good so the average
3537
02:10:25,360 --> 02:10:27,880
number in this sequence here is
3538
02:10:27,880 --> 02:10:30,480
4.333 so that should be correct because
3539
02:10:30,480 --> 02:10:33,360
we have 26 elements and we have no
3540
02:10:33,360 --> 02:10:35,840
the sum is 26 and there are six elements
3541
02:10:35,840 --> 02:10:37,360
right
3542
02:10:37,360 --> 02:10:39,040
so this is actually what i wanted to
3543
02:10:39,040 --> 02:10:41,199
show you about lists it's a long thing
3544
02:10:41,199 --> 02:10:43,360
right and we learned about how to index
3545
02:10:43,360 --> 02:10:45,520
the list here right and we can do it
3546
02:10:45,520 --> 02:10:48,159
positive and negatively we saw how we
3547
02:10:48,159 --> 02:10:49,679
could add
3548
02:10:49,679 --> 02:10:52,239
take an element the pop element and
3549
02:10:52,239 --> 02:10:54,079
and we saw how we could append an
3550
02:10:54,079 --> 02:10:55,119
element
3551
02:10:55,119 --> 02:10:57,440
and we saw how we couldn't concatenate
3552
02:10:57,440 --> 02:10:59,360
elements with a plus sign or not
3553
02:10:59,360 --> 02:11:00,880
elements lists
3554
02:11:00,880 --> 02:11:02,000
and uh
3555
02:11:02,000 --> 02:11:03,760
yeah that's nice and then we saw how we
3556
02:11:03,760 --> 02:11:06,000
could choose a random element it comes
3557
02:11:06,000 --> 02:11:07,920
in handy in the next one here
3558
02:11:07,920 --> 02:11:11,440
and we saw how that worked and uh
3559
02:11:11,440 --> 02:11:14,000
we saw how we can mix it shuffle it
3560
02:11:14,000 --> 02:11:16,480
it'll come in handy later
3561
02:11:16,480 --> 02:11:18,639
and then we saw how we could do this one
3562
02:11:18,639 --> 02:11:20,400
here actually join them together and
3563
02:11:20,400 --> 02:11:22,079
actually what we need in the next one is
3564
02:11:22,079 --> 02:11:23,679
this one here right
3565
02:11:23,679 --> 02:11:26,320
awesome and later we also need i don't
3566
02:11:26,320 --> 02:11:27,760
think in the next one no but later we
3567
02:11:27,760 --> 02:11:30,320
will need some some calculations like at
3568
02:11:30,320 --> 02:11:32,320
some point we would love to calculate
3569
02:11:32,320 --> 02:11:34,079
the average of something and that's how
3570
02:11:34,079 --> 02:11:35,360
you can do it
3571
02:11:35,360 --> 02:11:38,400
perfect awesome yeah so actually this is
3572
02:11:38,400 --> 02:11:40,400
what you need to know about list to
3573
02:11:40,400 --> 02:11:41,360
complete
3574
02:11:41,360 --> 02:11:42,880
the rest of the course there are a lot
3575
02:11:42,880 --> 02:11:44,159
of more things you can learn along the
3576
02:11:44,159 --> 02:11:46,800
way my advice is always to keep it
3577
02:11:46,800 --> 02:11:48,560
to the least amount in the beginning
3578
02:11:48,560 --> 02:11:49,840
because if you learn too many things
3579
02:11:49,840 --> 02:11:51,599
you'll just forget them and remember you
3580
02:11:51,599 --> 02:11:53,360
don't need to remember them there's an
3581
02:11:53,360 --> 02:11:55,599
ebook where you can follow along if you
3582
02:11:55,599 --> 02:11:57,520
didn't get that ebook go get it straight
3583
02:11:57,520 --> 02:11:59,360
away it's awesome
3584
02:11:59,360 --> 02:12:01,040
and
3585
02:12:01,040 --> 02:12:03,520
well we are ready for the next thing
3586
02:12:03,520 --> 02:12:04,719
right
3587
02:12:04,719 --> 02:12:07,840
let's get started
3588
02:12:10,320 --> 02:12:12,800
are you excited you should be because
3589
02:12:12,800 --> 02:12:15,119
the projects are where you learn things
3590
02:12:15,119 --> 02:12:16,719
but enough talking let's go to the
3591
02:12:16,719 --> 02:12:19,440
project and see what it is you should do
3592
02:12:19,440 --> 02:12:21,280
so the project is a game right it's
3593
02:12:21,280 --> 02:12:23,520
called the jumplet game and what is that
3594
02:12:23,520 --> 02:12:24,560
well
3595
02:12:24,560 --> 02:12:26,800
honestly there's a link to a description
3596
02:12:26,800 --> 02:12:29,520
there but the things are you need are
3597
02:12:29,520 --> 02:12:30,960
described here
3598
02:12:30,960 --> 02:12:32,159
and remember
3599
02:12:32,159 --> 02:12:34,320
it becomes more and more difficult along
3600
02:12:34,320 --> 02:12:36,560
the way and the description becomes less
3601
02:12:36,560 --> 02:12:39,920
and less or less detailed in many things
3602
02:12:39,920 --> 02:12:44,000
so let's look at that a word jumble is a
3603
02:12:44,000 --> 02:12:45,760
word puzzle game that presents the
3604
02:12:45,760 --> 02:12:48,079
player with a bunch of mixed up letters
3605
02:12:48,079 --> 02:12:49,840
and requires them
3606
02:12:49,840 --> 02:12:52,079
to unscramble the letters to find the
3607
02:12:52,079 --> 02:12:54,480
hidden word right remember what we did
3608
02:12:54,480 --> 02:12:57,280
in the last lesson we scrambled the word
3609
02:12:57,280 --> 02:12:59,040
interesting
3610
02:12:59,040 --> 02:13:01,520
the computer will take a word and jumble
3611
02:13:01,520 --> 02:13:03,760
it mix up the letters that's what we did
3612
02:13:03,760 --> 02:13:04,880
right
3613
02:13:04,880 --> 02:13:06,800
then the player will guess what the word
3614
02:13:06,800 --> 02:13:07,840
is
3615
02:13:07,840 --> 02:13:10,480
an initial word list could be father
3616
02:13:10,480 --> 02:13:12,480
enterprise science programming
3617
02:13:12,480 --> 02:13:14,960
resistance fiction condition reverse
3618
02:13:14,960 --> 02:13:17,040
computer python
3619
02:13:17,040 --> 02:13:19,440
nice list i like it already
3620
02:13:19,440 --> 02:13:21,840
okay so this should actually get you
3621
02:13:21,840 --> 02:13:24,400
started with that one and again how to
3622
02:13:24,400 --> 02:13:25,280
do that
3623
02:13:25,280 --> 02:13:29,040
well sit down think about it
3624
02:13:29,040 --> 02:13:31,679
i advise often to take a piece of paper
3625
02:13:31,679 --> 02:13:34,239
and try to figure out how you would
3626
02:13:34,239 --> 02:13:37,599
sequence this flow here and see how what
3627
02:13:37,599 --> 02:13:39,599
you come up with in the next one i'm
3628
02:13:39,599 --> 02:13:41,119
gonna show you
3629
02:13:41,119 --> 02:13:43,280
how i would solve it at our current
3630
02:13:43,280 --> 02:13:45,760
stage of python skills okay so you're
3631
02:13:45,760 --> 02:13:46,960
ready
3632
02:13:46,960 --> 02:13:49,119
go dive in on a piece of paper maybe and
3633
02:13:49,119 --> 02:13:51,119
or directly into jupiter notebook and
3634
02:13:51,119 --> 02:13:53,440
try to solve it on yourself okay
3635
02:13:53,440 --> 02:13:58,119
ready i am let's get started
3636
02:14:00,880 --> 02:14:03,280
so how did it go please let me know in
3637
02:14:03,280 --> 02:14:06,239
the comments before we dive into it
3638
02:14:06,239 --> 02:14:08,079
don't worry about it if it seemed to be
3639
02:14:08,079 --> 02:14:10,239
very complex right remember in the last
3640
02:14:10,239 --> 02:14:13,280
project we made we took a picture of the
3641
02:14:13,280 --> 02:14:15,840
rock paper scissor game and turned that
3642
02:14:15,840 --> 02:14:17,840
into code that was difficult right here
3643
02:14:17,840 --> 02:14:19,679
we kind of have a wake description of
3644
02:14:19,679 --> 02:14:21,520
something and we need to turn that into
3645
02:14:21,520 --> 02:14:24,079
code a game as well right
3646
02:14:24,079 --> 02:14:26,000
how do you do that well let's try to
3647
02:14:26,000 --> 02:14:27,760
jump into it together let's see how it
3648
02:14:27,760 --> 02:14:31,760
is and let's get started okay
3649
02:14:31,760 --> 02:14:34,639
so let's look at the
3650
02:14:34,639 --> 02:14:36,560
i assume you know what the game is we
3651
02:14:36,560 --> 02:14:38,000
already went through that but let's look
3652
02:14:38,000 --> 02:14:40,320
at these bullets again so the computer
3653
02:14:40,320 --> 02:14:42,800
will take uh take a random word and
3654
02:14:42,800 --> 02:14:44,560
jumble it right so mix up the letters
3655
02:14:44,560 --> 02:14:45,920
and then the player will guess what the
3656
02:14:45,920 --> 02:14:48,719
word is and then so this is basically
3657
02:14:48,719 --> 02:14:50,800
the game and then you say initial list
3658
02:14:50,800 --> 02:14:53,040
could be this one here so you might be
3659
02:14:53,040 --> 02:14:55,440
thinking wow do i really have to type in
3660
02:14:55,440 --> 02:14:57,520
this long list here well actually not
3661
02:14:57,520 --> 02:14:59,119
this is actually listing itself you just
3662
02:14:59,119 --> 02:15:01,920
copy it and then you say the words are
3663
02:15:01,920 --> 02:15:05,040
this list here so now you have it here
3664
02:15:05,040 --> 02:15:07,199
so again back to the first step here
3665
02:15:07,199 --> 02:15:09,119
right the computer will take a word
3666
02:15:09,119 --> 02:15:11,679
right so a random word
3667
02:15:11,679 --> 02:15:14,000
how do you do that
3668
02:15:14,000 --> 02:15:15,920
that's right thank you we should import
3669
02:15:15,920 --> 02:15:17,840
random import
3670
02:15:17,840 --> 02:15:20,079
random so why do i
3671
02:15:20,079 --> 02:15:22,480
import random on a line by itself well
3672
02:15:22,480 --> 02:15:25,199
if you write random here and you want to
3673
02:15:25,199 --> 02:15:27,840
find the methods available by pressing
3674
02:15:27,840 --> 02:15:29,679
tab it doesn't know them because you
3675
02:15:29,679 --> 02:15:31,280
haven't imported yet so that's why i
3676
02:15:31,280 --> 02:15:33,199
have it so if i import here
3677
02:15:33,199 --> 02:15:36,000
and then i go down on my line here and
3678
02:15:36,000 --> 02:15:38,719
then i write random then you can see you
3679
02:15:38,719 --> 02:15:41,199
can actually get the methods by pushing
3680
02:15:41,199 --> 02:15:44,239
tab here and remember words would return
3681
02:15:44,239 --> 02:15:45,760
a random
3682
02:15:45,760 --> 02:15:48,320
as you see a random word so this is the
3683
02:15:48,320 --> 02:15:50,639
word we are going to use here right
3684
02:15:50,639 --> 02:15:53,040
random words
3685
02:15:53,040 --> 02:15:54,079
so
3686
02:15:54,079 --> 02:15:57,119
now we need to jumble it right mix it up
3687
02:15:57,119 --> 02:15:59,280
how would how did we do that remember in
3688
02:15:59,280 --> 02:16:00,800
the last lecture again there was
3689
02:16:00,800 --> 02:16:02,960
something called what was it let's break
3690
02:16:02,960 --> 02:16:05,520
it down right so we need a method and
3691
02:16:05,520 --> 02:16:07,280
that method was called
3692
02:16:07,280 --> 02:16:08,719
sample right
3693
02:16:08,719 --> 02:16:11,599
so let's try to use that one sample and
3694
02:16:11,599 --> 02:16:13,320
see what it says here right the
3695
02:16:13,320 --> 02:16:16,000
documentation says
3696
02:16:16,000 --> 02:16:18,400
chooses k unique random elements from
3697
02:16:18,400 --> 02:16:20,320
the population sequence or set right so
3698
02:16:20,320 --> 02:16:22,639
this is the population will be the word
3699
02:16:22,639 --> 02:16:24,880
here and then we need
3700
02:16:24,880 --> 02:16:26,560
the length of that because we need all
3701
02:16:26,560 --> 02:16:28,400
of them right so word
3702
02:16:28,400 --> 02:16:30,079
length word
3703
02:16:30,079 --> 02:16:31,280
word
3704
02:16:31,280 --> 02:16:33,280
and there you see it and then it
3705
02:16:33,280 --> 02:16:35,359
randomized it but we also need to join
3706
02:16:35,359 --> 02:16:37,040
it together in one string and how was
3707
02:16:37,040 --> 02:16:37,760
that
3708
02:16:37,760 --> 02:16:40,318
well you remember correct there was
3709
02:16:40,318 --> 02:16:42,638
something called join right
3710
02:16:42,638 --> 02:16:44,240
and now it has it
3711
02:16:44,240 --> 02:16:45,280
you see
3712
02:16:45,280 --> 02:16:46,879
now we have it
3713
02:16:46,879 --> 02:16:49,200
so this is our jumble
3714
02:16:49,200 --> 02:16:51,120
and we assign that to a variable right
3715
02:16:51,120 --> 02:16:52,879
so now we actually did all the mix up
3716
02:16:52,879 --> 02:16:54,718
and i would have the jumper word right
3717
02:16:54,718 --> 02:16:58,398
okay so now let's prompt the user right
3718
02:16:58,398 --> 02:17:00,638
let's see how we can do that
3719
02:17:00,638 --> 02:17:02,558
we can do it with the print statement
3720
02:17:02,558 --> 02:17:04,398
and the formatted print statement let's
3721
02:17:04,398 --> 02:17:06,718
just do that
3722
02:17:06,718 --> 02:17:08,718
and the
3723
02:17:08,718 --> 02:17:10,160
jumbo
3724
02:17:10,160 --> 02:17:13,960
word is
3725
02:17:14,478 --> 02:17:15,770
jumble
3726
02:17:15,770 --> 02:17:17,120
[Music]
3727
02:17:17,120 --> 02:17:19,040
and then we have
3728
02:17:19,040 --> 02:17:20,558
guess
3729
02:17:20,558 --> 02:17:21,679
guess
3730
02:17:21,679 --> 02:17:23,439
input
3731
02:17:23,439 --> 02:17:25,280
right your
3732
02:17:25,280 --> 02:17:27,150
guess
3733
02:17:27,150 --> 02:17:28,558
[Music]
3734
02:17:28,558 --> 02:17:30,160
and what do we need to know we need to
3735
02:17:30,160 --> 02:17:33,519
know if the guess is correct
3736
02:17:33,760 --> 02:17:35,280
so if
3737
02:17:35,280 --> 02:17:37,920
guess equal equals word
3738
02:17:37,920 --> 02:17:39,100
then we print
3739
02:17:39,100 --> 02:17:40,398
[Music]
3740
02:17:40,398 --> 02:17:42,718
correct
3741
02:17:42,718 --> 02:17:44,160
else
3742
02:17:44,160 --> 02:17:45,280
print
3743
02:17:45,280 --> 02:17:47,040
and then we need probably to write what
3744
02:17:47,040 --> 02:17:49,679
the correct word is formatted
3745
02:17:49,679 --> 02:17:51,599
here
3746
02:17:51,599 --> 02:17:52,318
in
3747
02:17:52,318 --> 02:17:52,980
correct
3748
02:17:52,980 --> 02:17:54,840
[Music]
3749
02:17:54,840 --> 02:17:58,318
the word is
3750
02:17:58,318 --> 02:18:00,398
word right because we have it in word
3751
02:18:00,398 --> 02:18:02,080
here right remember we keep the word
3752
02:18:02,080 --> 02:18:04,160
here perfect
3753
02:18:04,160 --> 02:18:06,799
awesome okay let's try to run that now
3754
02:18:06,799 --> 02:18:11,839
boom right you guys the jumble word is
3755
02:18:13,040 --> 02:18:14,799
what
3756
02:18:14,799 --> 02:18:17,599
i don't even know what that is
3757
02:18:17,599 --> 02:18:18,959
don't know
3758
02:18:18,959 --> 02:18:22,959
wrong the word is condition okay
3759
02:18:22,959 --> 02:18:24,558
cute cute
3760
02:18:24,558 --> 02:18:27,839
more cute up more
3761
02:18:28,638 --> 02:18:32,799
what am i just all messed up here
3762
02:18:32,799 --> 02:18:36,478
cute up more what is that don't know
3763
02:18:36,478 --> 02:18:38,478
computer of course okay i have to get
3764
02:18:38,478 --> 02:18:40,398
into this game here
3765
02:18:40,398 --> 02:18:41,920
okay so
3766
02:18:41,920 --> 02:18:44,718
this is computer again
3767
02:18:44,718 --> 02:18:48,000
perfect right and let's try it once more
3768
02:18:48,000 --> 02:18:51,679
oh this is difficult i have no idea what
3769
02:18:51,679 --> 02:18:53,840
is this shriv
3770
02:18:53,840 --> 02:18:55,359
river
3771
02:18:55,359 --> 02:18:56,478
severe
3772
02:18:56,478 --> 02:18:58,478
severe
3773
02:18:58,478 --> 02:19:02,080
no severe reverse of course
3774
02:19:02,080 --> 02:19:03,840
okay you can see here i'm not very good
3775
02:19:03,840 --> 02:19:05,760
at that game obviously
3776
02:19:05,760 --> 02:19:07,760
these words are way too difficult for me
3777
02:19:07,760 --> 02:19:09,599
i hope you have more luck with that than
3778
02:19:09,599 --> 02:19:12,318
i do i'll not humiliate myself anymore
3779
02:19:12,318 --> 02:19:14,398
but it's kind of funny though i was kind
3780
02:19:14,398 --> 02:19:16,080
of surprised how difficult it actually
3781
02:19:16,080 --> 02:19:17,599
was
3782
02:19:17,599 --> 02:19:18,638
i mean
3783
02:19:18,638 --> 02:19:20,558
i think you're better than me i hope you
3784
02:19:20,558 --> 02:19:21,359
are
3785
02:19:21,359 --> 02:19:23,760
uh if not then you can see the standard
3786
02:19:23,760 --> 02:19:26,240
is not high here i mean wow i'm
3787
02:19:26,240 --> 02:19:28,718
embarrassed wow i should have done
3788
02:19:28,718 --> 02:19:30,160
better than that
3789
02:19:30,160 --> 02:19:31,519
never mind
3790
02:19:31,519 --> 02:19:32,398
let's
3791
02:19:32,398 --> 02:19:34,799
continue to the next one
3792
02:19:34,799 --> 02:19:36,638
the next one is going to be amazing
3793
02:19:36,638 --> 02:19:38,478
because then we're going to jump into
3794
02:19:38,478 --> 02:19:40,240
loops and that's another way to make
3795
02:19:40,240 --> 02:19:42,398
flows in the programs because you want
3796
02:19:42,398 --> 02:19:44,160
to do the same thing again and again and
3797
02:19:44,160 --> 02:19:46,080
it's going to be amazing you're going to
3798
02:19:46,080 --> 02:19:48,160
love it see you in a moment and please
3799
02:19:48,160 --> 02:19:50,319
just a note forget about how bad i was
3800
02:19:50,319 --> 02:19:52,720
at this jumble game here please don't
3801
02:19:52,720 --> 02:19:55,040
tell anyone it's embarrassing see you in
3802
02:19:55,040 --> 02:19:57,439
a moment
3803
02:20:00,080 --> 02:20:02,800
wow we need to learn a new flow right
3804
02:20:02,800 --> 02:20:05,920
now remember the flow with if statements
3805
02:20:05,920 --> 02:20:08,479
but sometimes at least now we have these
3806
02:20:08,479 --> 02:20:10,640
lists maybe we want to iterate and
3807
02:20:10,640 --> 02:20:12,800
that's always the same thing again and
3808
02:20:12,800 --> 02:20:14,960
again and actually many programs use
3809
02:20:14,960 --> 02:20:17,040
that all the time you probably don't
3810
02:20:17,040 --> 02:20:19,040
realize it but actually when a computer
3811
02:20:19,040 --> 02:20:20,800
runs in the background it must have some
3812
02:20:20,800 --> 02:20:22,319
kind of loop where you're just waiting
3813
02:20:22,319 --> 02:20:24,319
for the next task to do right so that's
3814
02:20:24,319 --> 02:20:26,000
kind of a loop right you're waiting
3815
02:20:26,000 --> 02:20:27,520
waiting waiting should i do something
3816
02:20:27,520 --> 02:20:29,680
shouldn't i do something and so on the
3817
02:20:29,680 --> 02:20:31,680
same with lists right you want to
3818
02:20:31,680 --> 02:20:34,399
iterate over a list for instance and do
3819
02:20:34,399 --> 02:20:36,880
something for each element well this is
3820
02:20:36,880 --> 02:20:39,040
where loops come into the pictures and
3821
02:20:39,040 --> 02:20:41,200
in python you have two main types of
3822
02:20:41,200 --> 02:20:43,359
loops you have for loops and while loops
3823
02:20:43,359 --> 02:20:45,120
so let's jump to jupyter notebook and
3824
02:20:45,120 --> 02:20:47,600
get started
3825
02:20:47,600 --> 02:20:50,000
so again the lesson is about loop here
3826
02:20:50,000 --> 02:20:51,840
and the goal is to learn how to iterate
3827
02:20:51,840 --> 02:20:53,120
over lists
3828
02:20:53,120 --> 02:20:56,080
iterate over chars or characters in a
3829
02:20:56,080 --> 02:20:58,640
string create a for loop over a range
3830
02:20:58,640 --> 02:21:01,280
and create a while loop so these are the
3831
02:21:01,280 --> 02:21:03,280
things we want to do right so again it's
3832
02:21:03,280 --> 02:21:05,359
about learning some syntax and get
3833
02:21:05,359 --> 02:21:07,680
started so for the
3834
02:21:07,680 --> 02:21:09,280
purpose of this let's just make a list
3835
02:21:09,280 --> 02:21:11,120
here as you could see we need a list
3836
02:21:11,120 --> 02:21:12,960
here we need to learn how to iterate
3837
02:21:12,960 --> 02:21:14,560
over a list right
3838
02:21:14,560 --> 02:21:17,280
so let's just call it first
3839
02:21:17,280 --> 02:21:19,120
second and
3840
02:21:19,120 --> 02:21:20,800
third
3841
02:21:20,800 --> 02:21:23,120
that's my list that's my list and you
3842
02:21:23,120 --> 02:21:24,960
know how a list is right
3843
02:21:24,960 --> 02:21:28,240
so it's just like this one here so
3844
02:21:28,240 --> 02:21:31,280
now we need to iterate over a list here
3845
02:21:31,280 --> 02:21:33,520
right so how do you do that well
3846
02:21:33,520 --> 02:21:38,160
for let's just call it item in my
3847
02:21:38,160 --> 02:21:40,399
my list
3848
02:21:40,399 --> 02:21:41,439
colon
3849
02:21:41,439 --> 02:21:43,920
this is basically the loop construction
3850
02:21:43,920 --> 02:21:45,840
here again you see the colon here like
3851
02:21:45,840 --> 02:21:47,840
we also had with the if statement
3852
02:21:47,840 --> 02:21:50,080
because now it will be indented
3853
02:21:50,080 --> 02:21:51,200
afterwards
3854
02:21:51,200 --> 02:21:52,160
so
3855
02:21:52,160 --> 02:21:53,760
what's intended afterwards will be
3856
02:21:53,760 --> 02:21:56,080
executed for each item in my list so
3857
02:21:56,080 --> 02:21:59,359
let's try to do that print item
3858
02:21:59,359 --> 02:22:01,040
just a note here it doesn't have to be
3859
02:22:01,040 --> 02:22:02,880
item let's change it in a moment but
3860
02:22:02,880 --> 02:22:05,520
it's just you know a name for it so what
3861
02:22:05,520 --> 02:22:08,160
it will do now is print each item as you
3862
02:22:08,160 --> 02:22:10,399
see here that's what it does first
3863
02:22:10,399 --> 02:22:12,720
second third right so it takes and
3864
02:22:12,720 --> 02:22:16,000
assigns the value of the list item by
3865
02:22:16,000 --> 02:22:17,680
item to item
3866
02:22:17,680 --> 02:22:19,680
and as i promised you you can just call
3867
02:22:19,680 --> 02:22:21,760
it whatever you want here and it will be
3868
02:22:21,760 --> 02:22:23,439
the same here so there's nothing in the
3869
02:22:23,439 --> 02:22:24,880
naming here right
3870
02:22:24,880 --> 02:22:27,200
perfect awesome right
3871
02:22:27,200 --> 02:22:28,880
so that was the first thing we needed to
3872
02:22:28,880 --> 02:22:30,319
do
3873
02:22:30,319 --> 02:22:32,560
so now we know how to i iterate over a
3874
02:22:32,560 --> 02:22:34,640
list so what about a string right so
3875
02:22:34,640 --> 02:22:36,319
let's say we have a string and it has a
3876
02:22:36,319 --> 02:22:39,359
name in it unknown name but we want to
3877
02:22:39,359 --> 02:22:41,040
inspect all the characters how can you
3878
02:22:41,040 --> 02:22:44,720
do that for c for instance for char
3879
02:22:44,720 --> 02:22:45,439
in
3880
02:22:45,439 --> 02:22:47,040
s
3881
02:22:47,040 --> 02:22:49,120
let's try to print c out and see what
3882
02:22:49,120 --> 02:22:52,399
happens well it does actually assign a
3883
02:22:52,399 --> 02:22:54,240
character
3884
02:22:54,240 --> 02:22:56,640
to c one by one right so it takes
3885
02:22:56,640 --> 02:22:59,280
assigns r to c and prints it
3886
02:22:59,280 --> 02:23:02,399
assigns u to c and prints it assigns n
3887
02:23:02,399 --> 02:23:04,880
to c and prints it and assigns e to c
3888
02:23:04,880 --> 02:23:07,840
and prints it right amazing
3889
02:23:07,840 --> 02:23:09,680
again if this is confusing don't worry
3890
02:23:09,680 --> 02:23:11,600
about it try it again right try to play
3891
02:23:11,600 --> 02:23:13,520
around with it remember everything that
3892
02:23:13,520 --> 02:23:16,479
is indented afterwards is executed in
3893
02:23:16,479 --> 02:23:18,720
the loop right so here we could say
3894
02:23:18,720 --> 02:23:21,280
print let's say we print
3895
02:23:21,280 --> 02:23:22,319
inside
3896
02:23:22,319 --> 02:23:23,520
loop
3897
02:23:23,520 --> 02:23:25,439
and then when you're
3898
02:23:25,439 --> 02:23:27,120
stopped the indentation
3899
02:23:27,120 --> 02:23:29,680
it's only executed after the loop so
3900
02:23:29,680 --> 02:23:30,840
this is
3901
02:23:30,840 --> 02:23:32,920
outside the loop
3902
02:23:32,920 --> 02:23:34,560
[Music]
3903
02:23:34,560 --> 02:23:36,399
so you see here what it does is it
3904
02:23:36,399 --> 02:23:39,120
assigns r to the variable here it prints
3905
02:23:39,120 --> 02:23:41,200
r and it says inside loop inside the
3906
02:23:41,200 --> 02:23:44,640
loop and then it assigns c or u to our
3907
02:23:44,640 --> 02:23:48,160
variable c and it prints c or u here and
3908
02:23:48,160 --> 02:23:49,840
inside the loop and you see inside the
3909
02:23:49,840 --> 02:23:51,439
loop inside the loop interloop and then
3910
02:23:51,439 --> 02:23:54,080
afterwards when it's iterated all over r
3911
02:23:54,080 --> 02:23:56,560
u and e r u and e
3912
02:23:56,560 --> 02:23:58,479
it is outside the loop so it is
3913
02:23:58,479 --> 02:24:00,880
executing the indented code
3914
02:24:00,880 --> 02:24:02,560
for the loop and
3915
02:24:02,560 --> 02:24:04,479
that's how it does right another thing
3916
02:24:04,479 --> 02:24:07,520
you often do is you use a range
3917
02:24:07,520 --> 02:24:08,880
so what is the range we'll see in a
3918
02:24:08,880 --> 02:24:09,760
moment
3919
02:24:09,760 --> 02:24:13,120
so let's try to do it for i in range so
3920
02:24:13,120 --> 02:24:14,880
let's see what range actually says in
3921
02:24:14,880 --> 02:24:16,319
the dock string
3922
02:24:16,319 --> 02:24:18,720
well it says uh
3923
02:24:18,720 --> 02:24:20,080
range
3924
02:24:20,080 --> 02:24:21,520
self
3925
02:24:21,520 --> 02:24:23,280
uh it doesn't actually says that much
3926
02:24:23,280 --> 02:24:26,080
but it has a stop and start a start and
3927
02:24:26,080 --> 02:24:27,680
stop right potentially it doesn't need
3928
02:24:27,680 --> 02:24:29,280
to start it doesn't need to it only
3929
02:24:29,280 --> 02:24:31,280
needs to stop often you only use it with
3930
02:24:31,280 --> 02:24:32,640
a stop but sometimes you need to start
3931
02:24:32,640 --> 02:24:34,399
on a stop value we'll just try to do
3932
02:24:34,399 --> 02:24:35,920
both here
3933
02:24:35,920 --> 02:24:36,640
so
3934
02:24:36,640 --> 02:24:39,120
in range let's just say 4 not to make it
3935
02:24:39,120 --> 02:24:41,920
too much print i so what it does it
3936
02:24:41,920 --> 02:24:43,760
assigns
3937
02:24:43,760 --> 02:24:46,080
accounts all the way up to four for
3938
02:24:46,080 --> 02:24:48,080
exclusive and
3939
02:24:48,080 --> 02:24:50,800
zero one two three right
3940
02:24:50,800 --> 02:24:52,800
and as i said you can have a start value
3941
02:24:52,800 --> 02:24:54,479
let's say we start at two and then we
3942
02:24:54,479 --> 02:24:56,640
iterate up to 4 right so instead here we
3943
02:24:56,640 --> 02:24:59,760
have 2 and 3 because we start from 2.
3944
02:24:59,760 --> 02:25:01,600
uh when do we use these for loops all
3945
02:25:01,600 --> 02:25:04,000
the time and just to
3946
02:25:04,000 --> 02:25:06,080
let's say we have remember the my list
3947
02:25:06,080 --> 02:25:09,439
here it's still here right so 4i in
3948
02:25:09,439 --> 02:25:12,080
range sometimes you would say you take
3949
02:25:12,080 --> 02:25:14,319
the length length of my list here why
3950
02:25:14,319 --> 02:25:16,399
would you do that well in this case here
3951
02:25:16,399 --> 02:25:18,560
it's because you want to access the
3952
02:25:18,560 --> 02:25:20,560
items in the classical way here not
3953
02:25:20,560 --> 02:25:22,160
classically this way here right for
3954
02:25:22,160 --> 02:25:23,760
instance if you also want the index here
3955
02:25:23,760 --> 02:25:26,319
so i comma i here right
3956
02:25:26,319 --> 02:25:27,840
so in this way you actually get the
3957
02:25:27,840 --> 02:25:30,319
index of the items there is zero one two
3958
02:25:30,319 --> 02:25:33,520
right zero one two of the list first
3959
02:25:33,520 --> 02:25:36,000
second third right zero one two zero one
3960
02:25:36,000 --> 02:25:38,080
two this is the way you access them
3961
02:25:38,080 --> 02:25:41,920
right so sometimes this makes sense uh
3962
02:25:41,920 --> 02:25:43,439
there are other ways to play around with
3963
02:25:43,439 --> 02:25:45,200
these things don't worry about it this
3964
02:25:45,200 --> 02:25:46,640
is enough for you
3965
02:25:46,640 --> 02:25:49,680
finally i want to show you a
3966
02:25:49,680 --> 02:25:52,240
while loop so let's
3967
02:25:52,240 --> 02:25:54,319
say we have a value here
3968
02:25:54,319 --> 02:25:56,479
while y is a bit different from four if
3969
02:25:56,479 --> 02:25:58,160
you notice four it does something
3970
02:25:58,160 --> 02:26:01,280
specific number of times so in the first
3971
02:26:01,280 --> 02:26:03,040
case here it does it
3972
02:26:03,040 --> 02:26:05,120
the number of times as long as a list
3973
02:26:05,120 --> 02:26:06,399
has items right
3974
02:26:06,399 --> 02:26:08,399
so it's fixed
3975
02:26:08,399 --> 02:26:10,319
and this one here with a string it does
3976
02:26:10,319 --> 02:26:12,960
it as many as characters are here right
3977
02:26:12,960 --> 02:26:14,000
fixed
3978
02:26:14,000 --> 02:26:15,920
and the same with range it takes it from
3979
02:26:15,920 --> 02:26:17,840
one number to another number right it's
3980
02:26:17,840 --> 02:26:18,800
fixed
3981
02:26:18,800 --> 02:26:21,200
what if we want to simulate something
3982
02:26:21,200 --> 02:26:22,640
different and the same with the last
3983
02:26:22,640 --> 02:26:24,399
example for instance in the program
3984
02:26:24,399 --> 02:26:26,319
sometimes it keeps running until the
3985
02:26:26,319 --> 02:26:30,319
user quits right so how do you do that
3986
02:26:30,319 --> 02:26:32,720
well in this case here we could do value
3987
02:26:32,720 --> 02:26:35,040
value is
3988
02:26:35,040 --> 02:26:37,520
is uh greater than zero for instance
3989
02:26:37,520 --> 02:26:39,280
right so we have some kind of value and
3990
02:26:39,280 --> 02:26:41,920
inside here we will actually update it
3991
02:26:41,920 --> 02:26:43,200
value
3992
02:26:43,200 --> 02:26:46,240
uh we take an input from the user
3993
02:26:46,240 --> 02:26:47,600
value
3994
02:26:47,600 --> 02:26:49,280
and what do we need to remember we need
3995
02:26:49,280 --> 02:26:51,040
to convert it to an end let's just do it
3996
02:26:51,040 --> 02:26:53,040
immediately together here right
3997
02:26:53,040 --> 02:26:53,920
so
3998
02:26:53,920 --> 02:26:55,680
what i'm saying here is now it will
3999
02:26:55,680 --> 02:26:58,000
prompt me for a value and if i put nine
4000
02:26:58,000 --> 02:26:59,359
here it will continue if you put four
4001
02:26:59,359 --> 02:27:01,040
here it will continue if i put zero here
4002
02:27:01,040 --> 02:27:04,000
it will end right so you see this while
4003
02:27:04,000 --> 02:27:05,840
loop here is different from a for loop
4004
02:27:05,840 --> 02:27:07,680
because this can continue forever
4005
02:27:07,680 --> 02:27:08,800
basically
4006
02:27:08,800 --> 02:27:10,479
and
4007
02:27:10,479 --> 02:27:12,960
and will never stop if we continue
4008
02:27:12,960 --> 02:27:15,200
entering numbers that are above zero
4009
02:27:15,200 --> 02:27:16,960
greater than zero right
4010
02:27:16,960 --> 02:27:19,359
so in this sense the while loop is very
4011
02:27:19,359 --> 02:27:21,359
different from the for loop right
4012
02:27:21,359 --> 02:27:23,840
awesome
4013
02:27:26,319 --> 02:27:29,280
before we finalize this lesson here i
4014
02:27:29,280 --> 02:27:31,120
want to show you a few new things
4015
02:27:31,120 --> 02:27:32,960
actually because we will need them in
4016
02:27:32,960 --> 02:27:34,399
the next one and they're not fitted
4017
02:27:34,399 --> 02:27:36,640
right into loops so i just put them here
4018
02:27:36,640 --> 02:27:39,280
in the next one here right so let's get
4019
02:27:39,280 --> 02:27:41,439
started what is it that we need well we
4020
02:27:41,439 --> 02:27:44,000
learned a lot of things right but are we
4021
02:27:44,000 --> 02:27:45,280
done
4022
02:27:45,280 --> 02:27:47,439
no we need a few more things and this is
4023
02:27:47,439 --> 02:27:49,760
just small things right so
4024
02:27:49,760 --> 02:27:51,359
one thing we need to do is our if
4025
02:27:51,359 --> 02:27:53,840
statements we want to see if a character
4026
02:27:53,840 --> 02:27:55,680
has been guessed or not we'll use that
4027
02:27:55,680 --> 02:27:57,760
in the next lecture right so let's do
4028
02:27:57,760 --> 02:27:59,600
that right so if we have like a string
4029
02:27:59,600 --> 02:28:02,640
here let's say we have abc here
4030
02:28:02,640 --> 02:28:04,880
and let's call it just
4031
02:28:04,880 --> 02:28:06,560
here then we can actually use an if
4032
02:28:06,560 --> 02:28:09,840
statement like this one here if
4033
02:28:10,240 --> 02:28:12,000
let's just put a character here and we
4034
02:28:12,000 --> 02:28:15,359
put it to a here and say if c in
4035
02:28:15,359 --> 02:28:16,720
s
4036
02:28:16,720 --> 02:28:18,399
print
4037
02:28:18,399 --> 02:28:21,439
c is in s right
4038
02:28:21,439 --> 02:28:23,120
let's just keep it like that so in this
4039
02:28:23,120 --> 02:28:25,359
case c is in s because we have a is in
4040
02:28:25,359 --> 02:28:27,280
there right the same for b
4041
02:28:27,280 --> 02:28:28,640
and the same for
4042
02:28:28,640 --> 02:28:30,800
c but if you took another character like
4043
02:28:30,800 --> 02:28:32,800
d then it will not be in it right so
4044
02:28:32,800 --> 02:28:35,040
this is quite a handy way to do some
4045
02:28:35,040 --> 02:28:37,040
programming because you see this is
4046
02:28:37,040 --> 02:28:38,560
often you want to just check if this
4047
02:28:38,560 --> 02:28:40,319
character is part of the string here
4048
02:28:40,319 --> 02:28:42,319
it's pretty easy to do it like this so
4049
02:28:42,319 --> 02:28:43,840
this is a really nice thing and you'll
4050
02:28:43,840 --> 02:28:46,080
need it in the project in order to
4051
02:28:46,080 --> 02:28:47,439
finalize that
4052
02:28:47,439 --> 02:28:49,280
another thing is often
4053
02:28:49,280 --> 02:28:50,880
sometimes you need to check that
4054
02:28:50,880 --> 02:28:53,040
something is not the case and we did
4055
02:28:53,040 --> 02:28:55,280
that with variable not equals right but
4056
02:28:55,280 --> 02:28:58,240
you can also do it like this so if
4057
02:28:58,240 --> 02:28:59,359
c
4058
02:28:59,359 --> 02:29:01,040
not in s
4059
02:29:01,040 --> 02:29:03,439
print
4060
02:29:03,760 --> 02:29:04,800
c
4061
02:29:04,800 --> 02:29:06,479
is not in
4062
02:29:06,479 --> 02:29:08,560
s right so if you execute that that is
4063
02:29:08,560 --> 02:29:10,720
the case because we have that be it as
4064
02:29:10,720 --> 02:29:12,880
assigned it to here right so this is not
4065
02:29:12,880 --> 02:29:16,000
negates the expression right so c not in
4066
02:29:16,000 --> 02:29:17,760
s right that's what it means right so
4067
02:29:17,760 --> 02:29:20,160
not so seen it's just about reading it
4068
02:29:20,160 --> 02:29:22,319
right so this is quite straightforward
4069
02:29:22,319 --> 02:29:24,479
and finally you can also have two
4070
02:29:24,479 --> 02:29:26,720
statements in one right
4071
02:29:26,720 --> 02:29:28,720
what do i mean well
4072
02:29:28,720 --> 02:29:30,240
if
4073
02:29:30,240 --> 02:29:33,040
let's put some variable here let a to be
4074
02:29:33,040 --> 02:29:33,840
10
4075
02:29:33,840 --> 02:29:35,200
b to be
4076
02:29:35,200 --> 02:29:39,840
12 c to be 14 in this case here so if a
4077
02:29:39,840 --> 02:29:43,040
is greater than or less than b
4078
02:29:43,040 --> 02:29:44,880
and here it comes
4079
02:29:44,880 --> 02:29:49,760
b is less than c then we print awesome i
4080
02:29:49,760 --> 02:29:51,520
don't want to
4081
02:29:51,520 --> 02:29:53,200
right because this is the case right
4082
02:29:53,200 --> 02:29:56,560
because we both have that a is a lot
4083
02:29:56,560 --> 02:29:58,720
less than b and we also have that b is
4084
02:29:58,720 --> 02:30:01,280
less than c right so in this case here
4085
02:30:01,280 --> 02:30:03,439
this is true right but if i change this
4086
02:30:03,439 --> 02:30:05,840
one here well it's not the case anymore
4087
02:30:05,840 --> 02:30:08,560
because now a is greater than b right
4088
02:30:08,560 --> 02:30:10,960
and in the same way you could have or
4089
02:30:10,960 --> 02:30:13,359
instead here instead of and or then it
4090
02:30:13,359 --> 02:30:15,359
just means one of them is correct and
4091
02:30:15,359 --> 02:30:17,680
one of them is correct because b is a
4092
02:30:17,680 --> 02:30:20,000
less than c here right but if you
4093
02:30:20,000 --> 02:30:22,560
changed this one here
4094
02:30:22,560 --> 02:30:24,640
or c here to 10 here this is not the
4095
02:30:24,640 --> 02:30:26,800
case anymore because none of them
4096
02:30:26,800 --> 02:30:30,240
neither aim is less than b or b is less
4097
02:30:30,240 --> 02:30:32,880
than c right so you can combine them
4098
02:30:32,880 --> 02:30:36,240
with and and ors like that so
4099
02:30:36,240 --> 02:30:38,479
this is amazing you have not and you
4100
02:30:38,479 --> 02:30:40,640
have in with a string and this is
4101
02:30:40,640 --> 02:30:42,479
amazing right this is just a few things
4102
02:30:42,479 --> 02:30:44,720
that you need to master for the next one
4103
02:30:44,720 --> 02:30:47,840
so see in a moment
4104
02:30:49,920 --> 02:30:51,920
if this looks advanced don't worry about
4105
02:30:51,920 --> 02:30:54,800
it we are here together to figure it out
4106
02:30:54,800 --> 02:30:56,720
but first let's try to look what the
4107
02:30:56,720 --> 02:30:58,800
hangman game is and there's actually i
4108
02:30:58,800 --> 02:31:00,720
think there's quite a lot of help in
4109
02:31:00,720 --> 02:31:02,880
this one here so i hope you'll figure it
4110
02:31:02,880 --> 02:31:04,720
out it will be a great success story for
4111
02:31:04,720 --> 02:31:05,680
you right
4112
02:31:05,680 --> 02:31:07,680
and uh don't worry if you don't figure
4113
02:31:07,680 --> 02:31:09,840
it out there's nothing wrong with that
4114
02:31:09,840 --> 02:31:12,560
we all have our own journey and me i've
4115
02:31:12,560 --> 02:31:14,479
been sitting often with problems that
4116
02:31:14,479 --> 02:31:16,080
took me days to solve
4117
02:31:16,080 --> 02:31:17,439
and again
4118
02:31:17,439 --> 02:31:19,680
the more time you spend trying yourself
4119
02:31:19,680 --> 02:31:21,680
uh the more you appreciate the more you
4120
02:31:21,680 --> 02:31:23,120
understand you will get from the
4121
02:31:23,120 --> 02:31:25,920
solution when you see it so let's try to
4122
02:31:25,920 --> 02:31:27,840
understand the game right i also have a
4123
02:31:27,840 --> 02:31:30,000
link here for the hangman game but we'll
4124
02:31:30,000 --> 02:31:32,720
use the description below here right
4125
02:31:32,720 --> 02:31:36,560
so the hangman game basically uh
4126
02:31:36,560 --> 02:31:38,319
it is about you should guess a word
4127
02:31:38,319 --> 02:31:39,600
right so
4128
02:31:39,600 --> 02:31:41,359
first of all you will just get blanks
4129
02:31:41,359 --> 02:31:42,479
and
4130
02:31:42,479 --> 02:31:44,560
then you will answer
4131
02:31:44,560 --> 02:31:46,640
you will guess a character
4132
02:31:46,640 --> 02:31:49,200
and it will display characters which are
4133
02:31:49,200 --> 02:31:51,200
correct and
4134
02:31:51,200 --> 02:31:52,960
in the end my you might guess a full
4135
02:31:52,960 --> 02:31:54,399
word if not
4136
02:31:54,399 --> 02:31:58,800
then you'll be you'll lose you have 10
4137
02:31:58,800 --> 02:32:00,800
guesses wrong guesses right so this is a
4138
02:32:00,800 --> 02:32:02,160
game right the game is as follows
4139
02:32:02,160 --> 02:32:04,560
computer has a list of words okay
4140
02:32:04,560 --> 02:32:06,479
computer chooses a random word from the
4141
02:32:06,479 --> 02:32:08,640
list hmm we know how to do that the
4142
02:32:08,640 --> 02:32:11,760
player gets 10 wrong guesses or 10 turns
4143
02:32:11,760 --> 02:32:15,200
the following the game follows this loop
4144
02:32:15,200 --> 02:32:16,960
computer prints the word character by
4145
02:32:16,960 --> 02:32:19,520
character placing with underscore those
4146
02:32:19,520 --> 02:32:21,600
not guessed yet
4147
02:32:21,600 --> 02:32:23,520
initial initial
4148
02:32:23,520 --> 02:32:26,800
no characters has been guessed right it
4149
02:32:26,800 --> 02:32:30,000
starts with all blanks or underscores
4150
02:32:30,000 --> 02:32:32,720
a player guesses a character if
4151
02:32:32,720 --> 02:32:34,720
character is not in word a turn is
4152
02:32:34,720 --> 02:32:36,080
withdrawn
4153
02:32:36,080 --> 02:32:38,880
if no turns left computer wins if player
4154
02:32:38,880 --> 02:32:40,880
has guessed all characters player wins
4155
02:32:40,880 --> 02:32:43,200
right an initial word list could be
4156
02:32:43,200 --> 02:32:45,040
father enterprise science
4157
02:32:45,040 --> 02:32:47,760
programming resistance fiction condition
4158
02:32:47,760 --> 02:32:51,600
reverse computer python okay
4159
02:32:51,600 --> 02:32:53,040
so
4160
02:32:53,040 --> 02:32:54,399
are you ready
4161
02:32:54,399 --> 02:32:57,520
i hope so it's gonna be amazing and uh
4162
02:32:57,520 --> 02:32:59,120
see you
4163
02:32:59,120 --> 02:33:01,120
in some time you should take some time
4164
02:33:01,120 --> 02:33:04,240
and try this out and uh then if you get
4165
02:33:04,240 --> 02:33:06,640
stuck don't worry i'll help you
4166
02:33:06,640 --> 02:33:09,520
see you in the next one
4167
02:33:12,080 --> 02:33:13,840
isn't this exciting are you ready for
4168
02:33:13,840 --> 02:33:16,479
this one i hope so i hope you did well
4169
02:33:16,479 --> 02:33:18,640
and let me know in the comments below
4170
02:33:18,640 --> 02:33:21,200
what's difficult for you and
4171
02:33:21,200 --> 02:33:23,200
i really love to hear about that because
4172
02:33:23,200 --> 02:33:25,359
it also teach me what is difficult and
4173
02:33:25,359 --> 02:33:27,359
what's not so let's dive into jupiter
4174
02:33:27,359 --> 02:33:29,359
notebook and try to solve this one right
4175
02:33:29,359 --> 02:33:32,479
so we are at the hangman game here right
4176
02:33:32,479 --> 02:33:34,720
so the game was as follows right
4177
02:33:34,720 --> 02:33:37,359
remember you had wrong guesses and write
4178
02:33:37,359 --> 02:33:39,680
guesses and so on there but let's try to
4179
02:33:39,680 --> 02:33:42,479
get the structure first right so
4180
02:33:42,479 --> 02:33:43,680
we know we need
4181
02:33:43,680 --> 02:33:45,920
something done right we need to choose a
4182
02:33:45,920 --> 02:33:48,640
word so let's start by that well first
4183
02:33:48,640 --> 02:33:51,120
we need to import random right remember
4184
02:33:51,120 --> 02:33:53,520
good and then we can take this list here
4185
02:33:53,520 --> 02:33:56,640
for our list of words right so words
4186
02:33:56,640 --> 02:33:58,399
this one there and then we can take a
4187
02:33:58,399 --> 02:34:00,399
random word and we know how to do that
4188
02:34:00,399 --> 02:34:02,960
right so it's random
4189
02:34:02,960 --> 02:34:05,200
choice
4190
02:34:05,200 --> 02:34:07,840
and words right so it's always a good
4191
02:34:07,840 --> 02:34:09,520
way just to check along the way that
4192
02:34:09,520 --> 02:34:11,680
things are going as we plan right so
4193
02:34:11,680 --> 02:34:13,200
here we have science
4194
02:34:13,200 --> 02:34:16,000
enterprise fiction and so on python and
4195
02:34:16,000 --> 02:34:18,720
so on python again and fiction
4196
02:34:18,720 --> 02:34:21,439
so it seems to work so we can choose a
4197
02:34:21,439 --> 02:34:24,399
random word now right and
4198
02:34:24,399 --> 02:34:26,800
now we need a loop right
4199
02:34:26,800 --> 02:34:28,160
i mean
4200
02:34:28,160 --> 02:34:30,800
we need a loop in order to iterate
4201
02:34:30,800 --> 02:34:33,680
multiple times how do we do that
4202
02:34:33,680 --> 02:34:35,520
does it sound like a for loop do we know
4203
02:34:35,520 --> 02:34:38,399
how many times no it depends on we know
4204
02:34:38,399 --> 02:34:40,880
we have 10 turns but if we guess right
4205
02:34:40,880 --> 02:34:43,120
it's not taking a turn away from us and
4206
02:34:43,120 --> 02:34:45,120
if it gets wrong a turn is taking away
4207
02:34:45,120 --> 02:34:47,040
from us so we don't know how many times
4208
02:34:47,040 --> 02:34:49,840
so it will be a while loop right so
4209
02:34:49,840 --> 02:34:52,479
while what well we have these turns here
4210
02:34:52,479 --> 02:34:55,280
so let's try actually to add them to b10
4211
02:34:55,280 --> 02:34:56,560
here
4212
02:34:56,560 --> 02:35:00,160
so while turns is greater than zero we
4213
02:35:00,160 --> 02:35:02,399
continue right so
4214
02:35:02,399 --> 02:35:05,040
this is exactly what we want so what is
4215
02:35:05,040 --> 02:35:07,120
the first thing we want to do right well
4216
02:35:07,120 --> 02:35:08,880
it says computer prints the word
4217
02:35:08,880 --> 02:35:10,640
character by character replacing
4218
02:35:10,640 --> 02:35:14,399
underscore for those not guessed yet
4219
02:35:14,399 --> 02:35:16,800
so we need somehow to keep track of the
4220
02:35:16,800 --> 02:35:19,680
characters we have been guessing right
4221
02:35:19,680 --> 02:35:23,120
so let's add a
4222
02:35:23,280 --> 02:35:25,280
guesses here and let's have it as a
4223
02:35:25,280 --> 02:35:27,520
string so these are the guesses we had
4224
02:35:27,520 --> 02:35:29,680
so far right and now we need to print
4225
02:35:29,680 --> 02:35:32,160
the word character by character
4226
02:35:32,160 --> 02:35:33,920
so how do you do that well it's a for
4227
02:35:33,920 --> 02:35:37,280
loop right 4c in word
4228
02:35:37,280 --> 02:35:40,800
what do we do well if c if we have
4229
02:35:40,800 --> 02:35:42,880
guessed it we should print it right so
4230
02:35:42,880 --> 02:35:45,760
how do we do that remember if c in
4231
02:35:45,760 --> 02:35:47,840
uh guesses because that will be the
4232
02:35:47,840 --> 02:35:49,840
string where we add all our guesses to
4233
02:35:49,840 --> 02:35:51,120
right
4234
02:35:51,120 --> 02:35:52,960
then we print
4235
02:35:52,960 --> 02:35:57,630
c and else we print underscore right
4236
02:35:57,630 --> 02:35:59,040
[Music]
4237
02:35:59,040 --> 02:36:00,160
perfect
4238
02:36:00,160 --> 02:36:03,439
well this will print each character or
4239
02:36:03,439 --> 02:36:05,600
underscore on a line by itself so what
4240
02:36:05,600 --> 02:36:07,520
we can do is use this n trick here if
4241
02:36:07,520 --> 02:36:09,520
you remember it and
4242
02:36:09,520 --> 02:36:11,520
so it doesn't add a new line so in this
4243
02:36:11,520 --> 02:36:15,359
case here we'll just add new
4244
02:36:15,760 --> 02:36:17,600
a space between them instead right and
4245
02:36:17,600 --> 02:36:19,359
then we have a print statement down here
4246
02:36:19,359 --> 02:36:21,840
and let's try this out so let's just
4247
02:36:21,840 --> 02:36:23,520
have an input here so right now it's
4248
02:36:23,520 --> 02:36:25,200
just the input so it doesn't go in an
4249
02:36:25,200 --> 02:36:27,040
infinite loop really really fast so
4250
02:36:27,040 --> 02:36:28,479
let's try to do it
4251
02:36:28,479 --> 02:36:30,720
just want to see that yeah okay it does
4252
02:36:30,720 --> 02:36:32,399
print underscore for all of them because
4253
02:36:32,399 --> 02:36:34,840
we haven't guessed anything yet right
4254
02:36:34,840 --> 02:36:38,960
um perfect so that's the first stage
4255
02:36:38,960 --> 02:36:40,479
now we actually print it out and we
4256
02:36:40,479 --> 02:36:42,080
assume it will print the characters we
4257
02:36:42,080 --> 02:36:44,399
know so how do we do that right well
4258
02:36:44,399 --> 02:36:46,479
let's first stop it you stop it by
4259
02:36:46,479 --> 02:36:48,399
pressing this square bracket up here
4260
02:36:48,399 --> 02:36:50,399
right and then it stops it
4261
02:36:50,399 --> 02:36:51,439
perfect
4262
02:36:51,439 --> 02:36:53,680
so we need to add guesses to our list
4263
02:36:53,680 --> 02:36:55,040
right so
4264
02:36:55,040 --> 02:36:58,319
guess here is input
4265
02:36:58,720 --> 02:36:59,680
guess
4266
02:36:59,680 --> 02:37:01,680
a char
4267
02:37:01,680 --> 02:37:04,560
hr here
4268
02:37:04,560 --> 02:37:08,560
for character and then we take our
4269
02:37:08,560 --> 02:37:11,280
guesses and add it to our guesses so you
4270
02:37:11,280 --> 02:37:14,399
can do that by just adding that right
4271
02:37:14,399 --> 02:37:15,200
so
4272
02:37:15,200 --> 02:37:18,319
let's see if actually that works now you
4273
02:37:18,319 --> 02:37:19,920
can guess a
4274
02:37:19,920 --> 02:37:21,600
char
4275
02:37:21,600 --> 02:37:23,040
okay
4276
02:37:23,040 --> 02:37:24,960
it seems to work i don't know what this
4277
02:37:24,960 --> 02:37:26,240
word is
4278
02:37:26,240 --> 02:37:28,319
uh
4279
02:37:28,319 --> 02:37:31,520
reverse of course re
4280
02:37:31,520 --> 02:37:34,319
verse right so actually it continues
4281
02:37:34,319 --> 02:37:36,080
after we've guessed everything because
4282
02:37:36,080 --> 02:37:37,840
right now we don't terminate right we
4283
02:37:37,840 --> 02:37:40,160
terminate f 10 times
4284
02:37:40,160 --> 02:37:41,760
uh and actually we don't because we
4285
02:37:41,760 --> 02:37:42,880
don't
4286
02:37:42,880 --> 02:37:44,479
we don't decrease this one here so we
4287
02:37:44,479 --> 02:37:47,680
need to terminate it so far okay
4288
02:37:47,680 --> 02:37:50,560
perfect perfect perfect perfect so what
4289
02:37:50,560 --> 02:37:52,240
is the next step right
4290
02:37:52,240 --> 02:37:53,280
so
4291
02:37:53,280 --> 02:37:57,520
if we guess correct or incorrect then we
4292
02:37:57,520 --> 02:38:00,479
should be penaltized
4293
02:38:00,479 --> 02:38:02,479
so if
4294
02:38:02,479 --> 02:38:03,920
guess
4295
02:38:03,920 --> 02:38:05,430
not in word
4296
02:38:05,430 --> 02:38:06,720
[Music]
4297
02:38:06,720 --> 02:38:08,800
right so if the guess the guest
4298
02:38:08,800 --> 02:38:11,120
character is not in the word well we
4299
02:38:11,120 --> 02:38:12,800
take turn
4300
02:38:12,800 --> 02:38:15,920
and say turns -1 right so this is
4301
02:38:15,920 --> 02:38:16,960
actually
4302
02:38:16,960 --> 02:38:19,439
making it possible to
4303
02:38:19,439 --> 02:38:22,080
terminate the program okay so so far so
4304
02:38:22,080 --> 02:38:23,840
good
4305
02:38:23,840 --> 02:38:26,640
so far so good
4306
02:38:26,640 --> 02:38:28,319
no
4307
02:38:28,319 --> 02:38:29,200
c
4308
02:38:29,200 --> 02:38:30,240
o
4309
02:38:30,240 --> 02:38:31,280
m
4310
02:38:31,280 --> 02:38:32,720
not computer
4311
02:38:32,720 --> 02:38:34,399
houses
4312
02:38:34,399 --> 02:38:37,520
uh co
4313
02:38:37,520 --> 02:38:41,760
condition all right con
4314
02:38:43,040 --> 02:38:44,960
so we still don't terminate after we're
4315
02:38:44,960 --> 02:38:49,040
done but if i continued like this
4316
02:38:50,080 --> 02:38:50,620
let's see
4317
02:38:50,620 --> 02:38:53,359
[Music]
4318
02:38:53,359 --> 02:38:55,680
uh let's see g right now we don't know
4319
02:38:55,680 --> 02:38:57,359
how many turns we have so i got a bit
4320
02:38:57,359 --> 02:38:59,439
confused there so let's let's also print
4321
02:38:59,439 --> 02:39:00,880
that out here so
4322
02:39:00,880 --> 02:39:02,800
print
4323
02:39:02,800 --> 02:39:05,439
you have
4324
02:39:05,439 --> 02:39:06,800
turns
4325
02:39:06,800 --> 02:39:08,000
left
4326
02:39:08,000 --> 02:39:10,160
or actually we should write turns left
4327
02:39:10,160 --> 02:39:11,760
and then we have format string here so
4328
02:39:11,760 --> 02:39:13,840
let's do it here you have 10 turns left
4329
02:39:13,840 --> 02:39:17,120
okay so when you just put nothing
4330
02:39:17,120 --> 02:39:19,280
all right so now we should see if we
4331
02:39:19,280 --> 02:39:20,640
terminate down there right so we
4332
02:39:20,640 --> 02:39:22,640
terminate at the end here right after we
4333
02:39:22,640 --> 02:39:25,359
have no turns left okay perfect now that
4334
02:39:25,359 --> 02:39:27,920
works but still we cannot win right so
4335
02:39:27,920 --> 02:39:29,520
how do we win
4336
02:39:29,520 --> 02:39:31,120
well
4337
02:39:31,120 --> 02:39:33,280
basically we can make a variable
4338
02:39:33,280 --> 02:39:37,200
so let's try to do that and we say
4339
02:39:37,200 --> 02:39:40,560
guest all to be false here
4340
02:39:40,560 --> 02:39:43,600
oh what why do i want to do that right
4341
02:39:43,600 --> 02:39:45,920
actually not here actually it would be
4342
02:39:45,920 --> 02:39:47,710
nicer to have it down here
4343
02:39:47,710 --> 02:39:49,600
[Music]
4344
02:39:49,600 --> 02:39:52,399
guessed all false we put it in front of
4345
02:39:52,399 --> 02:39:54,240
the
4346
02:39:54,240 --> 02:39:56,960
for loop here because if we reach inside
4347
02:39:56,960 --> 02:39:59,040
here we know we had a wrong guess so
4348
02:39:59,040 --> 02:40:01,520
guessed all
4349
02:40:01,520 --> 02:40:03,520
or it's opposite right false it should
4350
02:40:03,520 --> 02:40:05,680
be true here right so we assume first
4351
02:40:05,680 --> 02:40:07,520
that we guessed everything
4352
02:40:07,520 --> 02:40:08,319
and
4353
02:40:08,319 --> 02:40:10,319
if we come into this one here we know
4354
02:40:10,319 --> 02:40:12,640
that we didn't guess everything right so
4355
02:40:12,640 --> 02:40:15,760
we don't have i guess here
4356
02:40:15,760 --> 02:40:19,680
so how can we get out of that well if
4357
02:40:19,680 --> 02:40:21,359
if not
4358
02:40:21,359 --> 02:40:22,800
guessed
4359
02:40:22,800 --> 02:40:24,479
all we need to do the following down
4360
02:40:24,479 --> 02:40:25,920
here right otherwise we need to
4361
02:40:25,920 --> 02:40:28,160
terminate right and how can we terminate
4362
02:40:28,160 --> 02:40:30,000
well there are two ways to do that let's
4363
02:40:30,000 --> 02:40:32,479
just keep it simple right now and we'll
4364
02:40:32,479 --> 02:40:36,160
say else turns b0 right because then we
4365
02:40:36,160 --> 02:40:39,520
don't care about anything else then we
4366
02:40:39,520 --> 02:40:40,319
dig
4367
02:40:40,319 --> 02:40:42,080
we put it to zero right so this should
4368
02:40:42,080 --> 02:40:46,080
actually do it right so guess char
4369
02:40:46,880 --> 02:40:48,399
i'm not good at this game
4370
02:40:48,399 --> 02:40:49,760
see here
4371
02:40:49,760 --> 02:40:53,520
what can it be i'll just cheat again uh
4372
02:40:53,520 --> 02:40:55,680
fiction of course
4373
02:40:55,680 --> 02:40:56,560
fig
4374
02:40:56,560 --> 02:40:58,319
because we need to check that it works
4375
02:40:58,319 --> 02:41:01,680
now boom and it ends right you win right
4376
02:41:01,680 --> 02:41:03,600
perfect and actually good right here you
4377
02:41:03,600 --> 02:41:06,080
win in this case here right but those
4378
02:41:06,080 --> 02:41:07,680
are details you can play around with but
4379
02:41:07,680 --> 02:41:08,960
you see how
4380
02:41:08,960 --> 02:41:11,279
actually nice this is right so i just
4381
02:41:11,279 --> 02:41:13,040
again here we have the list of all the
4382
02:41:13,040 --> 02:41:15,200
words and then we have choose a random
4383
02:41:15,200 --> 02:41:17,040
one we keep track of all the guesses we
4384
02:41:17,040 --> 02:41:19,120
have we have the turns here and while
4385
02:41:19,120 --> 02:41:21,120
the turns is greater than zero we
4386
02:41:21,120 --> 02:41:22,560
continue right and then it prints out
4387
02:41:22,560 --> 02:41:24,080
how many turns we have
4388
02:41:24,080 --> 02:41:24,880
we
4389
02:41:24,880 --> 02:41:27,040
assume first that we have guessed
4390
02:41:27,040 --> 02:41:28,720
everything and then we go through it and
4391
02:41:28,720 --> 02:41:30,800
if we didn't we put it to false right
4392
02:41:30,800 --> 02:41:32,960
and afterwards we check if we guessed
4393
02:41:32,960 --> 02:41:35,359
all if we guessed all we just say turns
4394
02:41:35,359 --> 02:41:37,680
zero it'll be nice to have say you win
4395
02:41:37,680 --> 02:41:39,680
it down here and then otherwise we'll
4396
02:41:39,680 --> 02:41:41,840
take a character and our next guess and
4397
02:41:41,840 --> 02:41:43,680
add that to our guesses right
4398
02:41:43,680 --> 02:41:46,720
makes sense and it's amazing
4399
02:41:46,720 --> 02:41:48,880
perfect if you find this exciting the
4400
02:41:48,880 --> 02:41:50,160
next thing is going to be even more
4401
02:41:50,160 --> 02:41:51,600
exciting because then we're going to
4402
02:41:51,600 --> 02:41:53,920
learn about functions yeah that's right
4403
02:41:53,920 --> 02:41:56,080
functions it's a great way to structure
4404
02:41:56,080 --> 02:41:57,359
your code and it'll make it more
4405
02:41:57,359 --> 02:41:58,560
readable and you can actually make
4406
02:41:58,560 --> 02:42:00,319
abstractions so you work on a higher
4407
02:42:00,319 --> 02:42:02,319
abstraction level it's gonna be amazing
4408
02:42:02,319 --> 02:42:05,040
see you in a moment
4409
02:42:07,680 --> 02:42:10,160
are you excited i hope so because in
4410
02:42:10,160 --> 02:42:11,840
this one we're gonna learn about
4411
02:42:11,840 --> 02:42:13,200
functions
4412
02:42:13,200 --> 02:42:15,040
functions what are functions well
4413
02:42:15,040 --> 02:42:17,439
basically it's just to make code
4414
02:42:17,439 --> 02:42:20,240
reusable and there are many reasons why
4415
02:42:20,240 --> 02:42:23,439
you want to master functions but one of
4416
02:42:23,439 --> 02:42:26,800
the most basic thing is well you don't
4417
02:42:26,800 --> 02:42:29,600
want to write the same code twice right
4418
02:42:29,600 --> 02:42:31,600
no you don't
4419
02:42:31,600 --> 02:42:33,680
in the ebook that you can download
4420
02:42:33,680 --> 02:42:36,399
there's a link in the description
4421
02:42:36,399 --> 02:42:38,000
there you can actually get a more
4422
02:42:38,000 --> 02:42:40,560
detailed description about why why use
4423
02:42:40,560 --> 02:42:42,479
functions an introduction to that in
4424
02:42:42,479 --> 02:42:43,920
this one we're going to dive into
4425
02:42:43,920 --> 02:42:45,439
learning about functions and what they
4426
02:42:45,439 --> 02:42:47,760
are and how to use them so let's jump to
4427
02:42:47,760 --> 02:42:50,640
jupyter notebook are you ready here we
4428
02:42:50,640 --> 02:42:53,520
are so again the goal of this section
4429
02:42:53,520 --> 02:42:55,279
here or this lecture here is to learn
4430
02:42:55,279 --> 02:42:57,359
about functions use functions to
4431
02:42:57,359 --> 02:42:58,880
structure code
4432
02:42:58,880 --> 02:43:00,960
function makes the code more readable
4433
02:43:00,960 --> 02:43:04,000
remember about the sin of python well
4434
02:43:04,000 --> 02:43:06,160
it's all about readability right and
4435
02:43:06,160 --> 02:43:07,920
functions actually can make your code
4436
02:43:07,920 --> 02:43:10,560
more readable more structured more easy
4437
02:43:10,560 --> 02:43:12,319
to comprehend
4438
02:43:12,319 --> 02:43:13,920
it might not be obvious in the beginning
4439
02:43:13,920 --> 02:43:17,279
but it will do magic for you so
4440
02:43:17,279 --> 02:43:19,600
understand functions if you are into
4441
02:43:19,600 --> 02:43:20,720
math you probably know what a
4442
02:43:20,720 --> 02:43:22,160
mathematical function
4443
02:43:22,160 --> 02:43:24,399
is well they're basically the same thing
4444
02:43:24,399 --> 02:43:27,200
just bit more broad okay so let's try
4445
02:43:27,200 --> 02:43:28,640
just to make our first function i'll
4446
02:43:28,640 --> 02:43:32,000
just describe what it does right my func
4447
02:43:32,000 --> 02:43:32,880
and it does
4448
02:43:32,880 --> 02:43:34,640
[Music]
4449
02:43:34,640 --> 02:43:38,479
all it does is print hello world
4450
02:43:38,479 --> 02:43:40,000
hello
4451
02:43:40,000 --> 02:43:42,240
world here okay
4452
02:43:42,240 --> 02:43:43,120
so
4453
02:43:43,120 --> 02:43:45,520
if i execute this one nothing happens no
4454
02:43:45,520 --> 02:43:47,279
output comes here because this is a
4455
02:43:47,279 --> 02:43:49,520
definition of a function so you define a
4456
02:43:49,520 --> 02:43:52,720
function with the word dev def and then
4457
02:43:52,720 --> 02:43:54,720
you have a space and then the name of
4458
02:43:54,720 --> 02:43:56,319
the function you have there in this case
4459
02:43:56,319 --> 02:43:58,080
i called it my func you can call it
4460
02:43:58,080 --> 02:43:59,920
whatever and then you have these
4461
02:43:59,920 --> 02:44:01,840
brackets here and inside these brackets
4462
02:44:01,840 --> 02:44:03,359
you can have arguments as you will see
4463
02:44:03,359 --> 02:44:05,279
in a moment right but don't worry about
4464
02:44:05,279 --> 02:44:07,120
that and then again we have this colon
4465
02:44:07,120 --> 02:44:08,800
here and then it indicates that
4466
02:44:08,800 --> 02:44:10,720
everything behind there that's intended
4467
02:44:10,720 --> 02:44:13,200
is part of this function so you have
4468
02:44:13,200 --> 02:44:15,120
multiple lines just like if statements
4469
02:44:15,120 --> 02:44:17,279
and while loops and for loops and so on
4470
02:44:17,279 --> 02:44:20,160
right here so how do you utilize this
4471
02:44:20,160 --> 02:44:21,760
function how do you use it right well
4472
02:44:21,760 --> 02:44:23,920
you call it like
4473
02:44:23,920 --> 02:44:25,760
we called a lot of other things right
4474
02:44:25,760 --> 02:44:27,520
here so if you call it you get the hello
4475
02:44:27,520 --> 02:44:28,720
world
4476
02:44:28,720 --> 02:44:29,520
right
4477
02:44:29,520 --> 02:44:31,760
so this means that this piece of code
4478
02:44:31,760 --> 02:44:33,439
here that you have in this one here can
4479
02:44:33,439 --> 02:44:35,439
be accessed from
4480
02:44:35,439 --> 02:44:37,920
wherever in your program
4481
02:44:37,920 --> 02:44:40,319
this is kind of nice in many cases in
4482
02:44:40,319 --> 02:44:41,680
this case here it doesn't really make
4483
02:44:41,680 --> 02:44:43,279
that big a difference but imagine have a
4484
02:44:43,279 --> 02:44:45,040
big block of code and then you want to
4485
02:44:45,040 --> 02:44:46,880
have that multiple places in your code
4486
02:44:46,880 --> 02:44:49,120
then you can have it without retyping
4487
02:44:49,120 --> 02:44:51,120
the same code again as i mentioned you
4488
02:44:51,120 --> 02:44:52,800
can also take arguments so let's try to
4489
02:44:52,800 --> 02:44:55,439
do that right so let's make a function
4490
02:44:55,439 --> 02:44:57,760
called print name
4491
02:44:57,760 --> 02:44:59,920
still very useful functions here right
4492
02:44:59,920 --> 02:45:01,840
so it will take the name as an argument
4493
02:45:01,840 --> 02:45:03,680
here as you'll see in a moment how it
4494
02:45:03,680 --> 02:45:06,160
works print and let's make a formatted
4495
02:45:06,160 --> 02:45:07,520
string here
4496
02:45:07,520 --> 02:45:08,640
hello
4497
02:45:08,640 --> 02:45:10,080
and let's just say
4498
02:45:10,080 --> 02:45:12,640
name here
4499
02:45:12,640 --> 02:45:14,640
and we need to end it there
4500
02:45:14,640 --> 02:45:15,920
here we go
4501
02:45:15,920 --> 02:45:17,840
down again when we execute it you can
4502
02:45:17,840 --> 02:45:19,439
see it's executed by the number three
4503
02:45:19,439 --> 02:45:22,000
here uh nothing happens right it's just
4504
02:45:22,000 --> 02:45:24,720
a piece of reusable code so now we have
4505
02:45:24,720 --> 02:45:26,080
print
4506
02:45:26,080 --> 02:45:28,319
name here and let's just put my name
4507
02:45:28,319 --> 02:45:29,120
here
4508
02:45:29,120 --> 02:45:30,960
and you can see hello
4509
02:45:30,960 --> 02:45:32,479
so that's what it does and if i put
4510
02:45:32,479 --> 02:45:34,240
another name in there let's just try
4511
02:45:34,240 --> 02:45:35,279
that
4512
02:45:35,279 --> 02:45:38,640
let's be funny right so what's your name
4513
02:45:38,640 --> 02:45:39,600
jens
4514
02:45:39,600 --> 02:45:41,279
okay your name is jens you don't look
4515
02:45:41,279 --> 02:45:43,920
like a chance i must say never mind
4516
02:45:43,920 --> 02:45:46,080
but your name is jens and you don't look
4517
02:45:46,080 --> 02:45:47,920
like one that's how it is okay it says
4518
02:45:47,920 --> 02:45:51,279
hello chance okay good enough fun for me
4519
02:45:51,279 --> 02:45:52,880
and uh obviously you can also have
4520
02:45:52,880 --> 02:45:54,479
multiple lines so let's just make it a
4521
02:45:54,479 --> 02:45:57,840
bit more fun now
4522
02:45:58,160 --> 02:46:01,920
print h and just say name and h here
4523
02:46:01,920 --> 02:46:04,160
and this will print
4524
02:46:04,160 --> 02:46:05,200
hello
4525
02:46:05,200 --> 02:46:07,200
oh i forgot
4526
02:46:07,200 --> 02:46:09,680
name
4527
02:46:09,680 --> 02:46:11,600
and just to have emphasize we can
4528
02:46:11,600 --> 02:46:14,479
multiple lines here
4529
02:46:14,479 --> 02:46:16,080
uh
4530
02:46:16,080 --> 02:46:18,399
you are
4531
02:46:18,399 --> 02:46:19,439
age
4532
02:46:19,439 --> 02:46:22,960
years old right and then we take here
4533
02:46:22,960 --> 02:46:24,880
print age
4534
02:46:24,880 --> 02:46:28,000
i'll just take mine first
4535
02:46:28,560 --> 02:46:30,000
and comma
4536
02:46:30,000 --> 02:46:32,720
30 here right so as you see here
4537
02:46:32,720 --> 02:46:34,880
you have two variables here or two
4538
02:46:34,880 --> 02:46:37,040
parameters here right and use parser
4539
02:46:37,040 --> 02:46:39,680
arguments honor and third here right so
4540
02:46:39,680 --> 02:46:42,080
honey becomes assigned to name and third
4541
02:46:42,080 --> 02:46:44,000
it becomes assigned to age here right so
4542
02:46:44,000 --> 02:46:45,840
that's how the function structure is
4543
02:46:45,840 --> 02:46:48,319
right and there's often a bit confusing
4544
02:46:48,319 --> 02:46:50,479
about what our parameters or what our
4545
02:46:50,479 --> 02:46:53,120
arguments basically said the parameters
4546
02:46:53,120 --> 02:46:55,120
are the ones where you define the
4547
02:46:55,120 --> 02:46:57,040
function right and the arguments are the
4548
02:46:57,040 --> 02:46:59,200
one you parse to the function in the
4549
02:46:59,200 --> 02:47:01,439
case where you call it right don't worry
4550
02:47:01,439 --> 02:47:03,680
about that it's not gonna do much
4551
02:47:03,680 --> 02:47:04,720
difference if you know all the
4552
02:47:04,720 --> 02:47:06,560
terminology and use it correctly it
4553
02:47:06,560 --> 02:47:08,319
doesn't matter many computer programmers
4554
02:47:08,319 --> 02:47:09,840
can be inclusive
4555
02:47:09,840 --> 02:47:11,920
mess it up all the time because we talk
4556
02:47:11,920 --> 02:47:15,040
but the key thing is you understand that
4557
02:47:15,040 --> 02:47:16,720
what happens right
4558
02:47:16,720 --> 02:47:17,920
and
4559
02:47:17,920 --> 02:47:19,120
another thing you can do is actually
4560
02:47:19,120 --> 02:47:21,359
return things from a function right and
4561
02:47:21,359 --> 02:47:22,800
that can be actually pretty handy so
4562
02:47:22,800 --> 02:47:25,760
let's see this one here
4563
02:47:25,760 --> 02:47:27,840
calculate
4564
02:47:27,840 --> 02:47:30,000
h right so let's do this one so let's
4565
02:47:30,000 --> 02:47:31,600
take birth year
4566
02:47:31,600 --> 02:47:32,479
right
4567
02:47:32,479 --> 02:47:34,840
and it returns
4568
02:47:34,840 --> 02:47:38,160
2021 minus birth year right
4569
02:47:38,160 --> 02:47:40,240
let's see one why do we care about this
4570
02:47:40,240 --> 02:47:42,880
one so let's see here so let's calculate
4571
02:47:42,880 --> 02:47:44,880
age and i say
4572
02:47:44,880 --> 02:47:47,200
i'm still born in 1991 i hope so at
4573
02:47:47,200 --> 02:47:48,880
least because then i'm 30 years old i
4574
02:47:48,880 --> 02:47:49,840
like that
4575
02:47:49,840 --> 02:47:50,960
and then
4576
02:47:50,960 --> 02:47:53,279
why is this useful you might say well
4577
02:47:53,279 --> 02:47:55,439
imagine that actually this calculation
4578
02:47:55,439 --> 02:47:58,560
here is done multiple times
4579
02:47:58,560 --> 02:48:00,800
in your program right and suddenly
4580
02:48:00,800 --> 02:48:02,800
something crazy happens
4581
02:48:02,800 --> 02:48:04,160
you know what
4582
02:48:04,160 --> 02:48:06,800
new years right and
4583
02:48:06,800 --> 02:48:10,000
then it actually turns into 2022
4584
02:48:10,000 --> 02:48:11,200
instead right
4585
02:48:11,200 --> 02:48:12,560
and uh
4586
02:48:12,560 --> 02:48:14,720
then this is crazy right then you need
4587
02:48:14,720 --> 02:48:16,800
to update this everywhere in your code
4588
02:48:16,800 --> 02:48:18,479
but if you have a function like this you
4589
02:48:18,479 --> 02:48:20,080
only need to update it one place and
4590
02:48:20,080 --> 02:48:21,680
that place is right here right so if we
4591
02:48:21,680 --> 02:48:24,080
update this one then everywhere you use
4592
02:48:24,080 --> 02:48:27,439
this calculate age it updates to a next
4593
02:48:27,439 --> 02:48:30,000
to the next to the correct value right
4594
02:48:30,000 --> 02:48:32,160
so this is also another useful thing
4595
02:48:32,160 --> 02:48:35,200
about functions right so
4596
02:48:35,200 --> 02:48:38,479
these are some of the things that was
4597
02:48:38,479 --> 02:48:39,520
so far
4598
02:48:39,520 --> 02:48:41,439
we covered simple functions and
4599
02:48:41,439 --> 02:48:43,760
arguments multiple arguments and
4600
02:48:43,760 --> 02:48:45,840
returning something and you can have
4601
02:48:45,840 --> 02:48:47,680
multiple return statements inside here
4602
02:48:47,680 --> 02:48:49,279
it depends on you can have it wherever
4603
02:48:49,279 --> 02:48:51,200
you want but when it returns it returns
4604
02:48:51,200 --> 02:48:53,680
and doesn't execute after that line so
4605
02:48:53,680 --> 02:48:56,720
if i had a line with here print
4606
02:48:56,720 --> 02:48:58,880
hello
4607
02:48:58,880 --> 02:49:01,520
it will not execute that line because it
4608
02:49:01,520 --> 02:49:04,240
returns before that we'll need to learn
4609
02:49:04,240 --> 02:49:06,319
a few things in order to do the next
4610
02:49:06,319 --> 02:49:07,840
exercise so
4611
02:49:07,840 --> 02:49:12,920
let's try to do that in this one here
4612
02:49:14,800 --> 02:49:16,640
so the project we're going to make is
4613
02:49:16,640 --> 02:49:19,040
going to be a cesar cipher and we need a
4614
02:49:19,040 --> 02:49:21,680
new few things in order to do that it's
4615
02:49:21,680 --> 02:49:23,520
not complex it's just i didn't see any
4616
02:49:23,520 --> 02:49:25,200
reason to introduce them before you need
4617
02:49:25,200 --> 02:49:26,640
them here right so that's what we're
4618
02:49:26,640 --> 02:49:27,840
going to do in this one here we're going
4619
02:49:27,840 --> 02:49:29,840
to introduce a few functions that you
4620
02:49:29,840 --> 02:49:31,760
need and try to play a bit around with
4621
02:49:31,760 --> 02:49:33,359
it just to see that we mastered them
4622
02:49:33,359 --> 02:49:35,600
before we get started with the project
4623
02:49:35,600 --> 02:49:38,319
the caesar cipher so the caesar cipher
4624
02:49:38,319 --> 02:49:40,560
probably as you know it takes characters
4625
02:49:40,560 --> 02:49:42,080
and does something with them right it
4626
02:49:42,080 --> 02:49:43,920
scrambles them up somehow we'll see in a
4627
02:49:43,920 --> 02:49:46,399
moment how but in order to do that we
4628
02:49:46,399 --> 02:49:48,399
need to calculate with characters so
4629
02:49:48,399 --> 02:49:50,000
let's do that so let's jump to the
4630
02:49:50,000 --> 02:49:52,560
jubilee notebook so one function we need
4631
02:49:52,560 --> 02:49:55,120
is the order of the of a character and
4632
02:49:55,120 --> 02:49:58,319
what does it do it returns a unicode
4633
02:49:58,319 --> 02:50:00,080
of a
4634
02:50:00,080 --> 02:50:02,080
unicode point for a one character string
4635
02:50:02,080 --> 02:50:04,080
so let's try to do that actually let's
4636
02:50:04,080 --> 02:50:06,479
put the capital a in here
4637
02:50:06,479 --> 02:50:09,840
and say well capital a returns 65 and
4638
02:50:09,840 --> 02:50:11,840
let's just for the fun of that take b
4639
02:50:11,840 --> 02:50:14,319
here and see it gets 66. so these are
4640
02:50:14,319 --> 02:50:17,279
unicodes for those characters right so
4641
02:50:17,279 --> 02:50:19,680
we will need this one here and why we
4642
02:50:19,680 --> 02:50:21,600
need that it's because making
4643
02:50:21,600 --> 02:50:24,479
calculations on characters is difficult
4644
02:50:24,479 --> 02:50:28,000
we need a numeric expression of them so
4645
02:50:28,000 --> 02:50:29,840
then we can actually make calculations
4646
02:50:29,840 --> 02:50:30,800
based on them and that's what we're
4647
02:50:30,800 --> 02:50:32,640
going to need so we also need to get
4648
02:50:32,640 --> 02:50:34,720
them back and there we have this one
4649
02:50:34,720 --> 02:50:37,040
here which will return unicode string of
4650
02:50:37,040 --> 02:50:39,600
the number right so if we put 65 here it
4651
02:50:39,600 --> 02:50:42,640
will return a and here it will be 66 it
4652
02:50:42,640 --> 02:50:45,439
will return b and so forth here right so
4653
02:50:45,439 --> 02:50:48,160
this is really really nice
4654
02:50:48,160 --> 02:50:50,960
so just to show it here so four
4655
02:50:50,960 --> 02:50:54,560
see in range here we take 65
4656
02:50:54,560 --> 02:50:56,960
and 65
4657
02:50:56,960 --> 02:50:59,279
plus 26 here i think there are 26
4658
02:50:59,279 --> 02:51:01,920
characters in the alphabet and let's
4659
02:51:01,920 --> 02:51:06,000
just print it here format it there
4660
02:51:06,000 --> 02:51:08,319
so
4661
02:51:09,200 --> 02:51:10,319
c
4662
02:51:10,319 --> 02:51:12,640
is
4663
02:51:15,520 --> 02:51:17,279
let's see here right
4664
02:51:17,279 --> 02:51:18,960
let's do that
4665
02:51:18,960 --> 02:51:20,880
and you see here we get all the alphabet
4666
02:51:20,880 --> 02:51:22,399
all the way down to set here so we have
4667
02:51:22,399 --> 02:51:24,160
that alphabet is from
4668
02:51:24,160 --> 02:51:28,560
65 all the way down here to 90 air force
4669
02:51:28,560 --> 02:51:30,240
set
4670
02:51:30,240 --> 02:51:31,120
okay
4671
02:51:31,120 --> 02:51:33,359
so so far so good okay
4672
02:51:33,359 --> 02:51:35,439
another thing we need to do is remainder
4673
02:51:35,439 --> 02:51:37,760
calculations and this seems a bit
4674
02:51:37,760 --> 02:51:39,520
confusing at first but actually it's
4675
02:51:39,520 --> 02:51:41,439
quite straightforward
4676
02:51:41,439 --> 02:51:42,720
so
4677
02:51:42,720 --> 02:51:44,399
there are many ways to describe it and
4678
02:51:44,399 --> 02:51:46,720
in the e-book i go i actually make a
4679
02:51:46,720 --> 02:51:48,399
quite good description of how it works
4680
02:51:48,399 --> 02:51:50,720
but let's just show it here right so
4681
02:51:50,720 --> 02:51:53,439
imagine actually you have
4682
02:51:53,439 --> 02:51:55,760
it's new year's eve again right and you
4683
02:51:55,760 --> 02:51:57,680
say i will count the hours from new
4684
02:51:57,680 --> 02:52:00,560
year's eve right so after one hour it's
4685
02:52:00,560 --> 02:52:03,120
one am after two hours it's two a.m and
4686
02:52:03,120 --> 02:52:06,560
so forth right but let's say
4687
02:52:06,560 --> 02:52:09,279
hours right so let's say they went
4688
02:52:09,279 --> 02:52:13,279
25 hours so what time is it right well
4689
02:52:13,279 --> 02:52:15,279
if you do the remainder calculations
4690
02:52:15,279 --> 02:52:18,160
here with 24 that means that
4691
02:52:18,160 --> 02:52:20,240
if we remove
4692
02:52:20,240 --> 02:52:22,640
if we have a clock with 24 hours
4693
02:52:22,640 --> 02:52:25,040
it will actually do it in a circle as
4694
02:52:25,040 --> 02:52:26,960
you see because then it'll back at 1
4695
02:52:26,960 --> 02:52:29,200
right then it's one am again right and
4696
02:52:29,200 --> 02:52:31,680
this is actually what it does it
4697
02:52:31,680 --> 02:52:33,359
can actually circulate like that so if
4698
02:52:33,359 --> 02:52:35,279
we take one up
4699
02:52:35,279 --> 02:52:37,359
one is one but
4700
02:52:37,359 --> 02:52:39,520
25 is one again
4701
02:52:39,520 --> 02:52:42,000
and uh if we add 24 to that again it
4702
02:52:42,000 --> 02:52:44,160
will be 49.
4703
02:52:44,160 --> 02:52:46,240
it's still one as you see and it
4704
02:52:46,240 --> 02:52:48,240
continues like that and if you take 50
4705
02:52:48,240 --> 02:52:50,880
it will be two right so in 50 hours it
4706
02:52:50,880 --> 02:52:53,439
will be 2 am right and this is how you
4707
02:52:53,439 --> 02:52:56,080
can actually think of it it's just
4708
02:52:56,080 --> 02:53:00,560
taking a value and
4709
02:53:00,560 --> 02:53:02,560
putting it down like a clock it resets
4710
02:53:02,560 --> 02:53:04,640
every time once in a while this is 24
4711
02:53:04,640 --> 02:53:06,160
hour clock right it could also be 12
4712
02:53:06,160 --> 02:53:08,560
o'clock 12 hour clock right and resets
4713
02:53:08,560 --> 02:53:11,520
it all the time similar
4714
02:53:11,520 --> 02:53:13,439
so this is how you do it right so you
4715
02:53:13,439 --> 02:53:15,359
can actually do additions to it right so
4716
02:53:15,359 --> 02:53:18,160
let's say here 50 it was two but you
4717
02:53:18,160 --> 02:53:20,080
could also add to this one here add
4718
02:53:20,080 --> 02:53:24,080
three air and it will be 53 because it
4719
02:53:24,080 --> 02:53:26,640
addition is done afterwards but here
4720
02:53:26,640 --> 02:53:28,479
would be 5 right
4721
02:53:28,479 --> 02:53:29,439
so
4722
02:53:29,439 --> 02:53:31,760
this is often handy when you do things
4723
02:53:31,760 --> 02:53:34,080
because you do need to do it modulus
4724
02:53:34,080 --> 02:53:36,640
something right or remainder something
4725
02:53:36,640 --> 02:53:37,439
so
4726
02:53:37,439 --> 02:53:39,200
we will need to use this in the next one
4727
02:53:39,200 --> 02:53:41,120
and uh it's gonna be
4728
02:53:41,120 --> 02:53:43,040
if you never worked with that it's a bit
4729
02:53:43,040 --> 02:53:45,120
tricky but let's make an example here so
4730
02:53:45,120 --> 02:53:47,120
let's uh def
4731
02:53:47,120 --> 02:53:51,200
is let's make a function called is even
4732
02:53:51,200 --> 02:53:53,120
and take a number here
4733
02:53:53,120 --> 02:53:54,800
so how do we check if something is even
4734
02:53:54,800 --> 02:53:56,080
right hmm
4735
02:53:56,080 --> 02:53:58,640
well if we had a clock with only zero
4736
02:53:58,640 --> 02:54:01,840
and one so it could be zero or one zero
4737
02:54:01,840 --> 02:54:04,479
one zero one right that'll make sense
4738
02:54:04,479 --> 02:54:05,359
because
4739
02:54:05,359 --> 02:54:08,960
if it is zero o'clock and then it's even
4740
02:54:08,960 --> 02:54:12,240
and if it's one o'clock it's odd right
4741
02:54:12,240 --> 02:54:13,439
so if
4742
02:54:13,439 --> 02:54:15,600
n modulus two
4743
02:54:15,600 --> 02:54:17,520
equals equals zero
4744
02:54:17,520 --> 02:54:18,840
then we print
4745
02:54:18,840 --> 02:54:20,800
even
4746
02:54:20,800 --> 02:54:22,880
else
4747
02:54:22,880 --> 02:54:24,319
print
4748
02:54:24,319 --> 02:54:26,240
odd right
4749
02:54:26,240 --> 02:54:27,040
so
4750
02:54:27,040 --> 02:54:28,720
let's try that
4751
02:54:28,720 --> 02:54:30,240
is
4752
02:54:30,240 --> 02:54:31,680
even
4753
02:54:31,680 --> 02:54:32,560
zero
4754
02:54:32,560 --> 02:54:35,040
yes it's even
4755
02:54:35,040 --> 02:54:37,200
is evens oh
4756
02:54:37,200 --> 02:54:39,760
here yes it is so let's try to do that
4757
02:54:39,760 --> 02:54:42,720
if 4i in range
4758
02:54:42,720 --> 02:54:44,720
10 let's just take 10 and then just
4759
02:54:44,720 --> 02:54:45,600
print
4760
02:54:45,600 --> 02:54:46,840
is
4761
02:54:46,840 --> 02:54:48,399
even
4762
02:54:48,399 --> 02:54:51,359
even here right i and actually for the
4763
02:54:51,359 --> 02:54:54,160
fun of it let's just print
4764
02:54:54,160 --> 02:54:55,040
print
4765
02:54:55,040 --> 02:54:57,760
i and we take end
4766
02:54:57,760 --> 02:55:00,160
here right so here we have it even odd
4767
02:55:00,160 --> 02:55:02,800
even odd even odd even odd even odd as
4768
02:55:02,800 --> 02:55:04,800
we expected right so
4769
02:55:04,800 --> 02:55:07,359
just when you think of this it is like
4770
02:55:07,359 --> 02:55:09,439
you come to the end of the number here
4771
02:55:09,439 --> 02:55:11,520
right the number you take the remainder
4772
02:55:11,520 --> 02:55:13,920
calculation with it is the clock with so
4773
02:55:13,920 --> 02:55:16,080
many hours in all right and it just
4774
02:55:16,080 --> 02:55:18,160
returns to the same thing again right
4775
02:55:18,160 --> 02:55:19,840
it's like a clock right it goes around
4776
02:55:19,840 --> 02:55:21,920
around around even though 50 hours is
4777
02:55:21,920 --> 02:55:23,279
gone it's still
4778
02:55:23,279 --> 02:55:25,600
just 3 a.m right
4779
02:55:25,600 --> 02:55:29,600
or 2 a.m it was 2 a.m yeah perfect okay
4780
02:55:29,600 --> 02:55:32,399
so far so good and that's actually all
4781
02:55:32,399 --> 02:55:34,960
you need to get started with the project
4782
02:55:34,960 --> 02:55:36,960
so are you excited i am let's get
4783
02:55:36,960 --> 02:55:39,359
started
4784
02:55:42,399 --> 02:55:45,359
this is amazing this is a great project
4785
02:55:45,359 --> 02:55:46,880
and it's really really fun and you will
4786
02:55:46,880 --> 02:55:49,040
learn a lot of things along the way
4787
02:55:49,040 --> 02:55:52,479
so let's get started right so
4788
02:55:52,479 --> 02:55:54,560
cesar cipher if you're not familiar with
4789
02:55:54,560 --> 02:55:56,640
it there's also a link here you can
4790
02:55:56,640 --> 02:55:58,000
enjoy if you want to read a bit more
4791
02:55:58,000 --> 02:56:00,000
about it but the goal of this project is
4792
02:56:00,000 --> 02:56:01,600
to make encryption and decryption right
4793
02:56:01,600 --> 02:56:04,000
so let's just introduce it here
4794
02:56:04,000 --> 02:56:05,840
so the caesar cipher is a simple
4795
02:56:05,840 --> 02:56:08,000
substitution cipher that basically means
4796
02:56:08,000 --> 02:56:11,120
it changes characters which is limited
4797
02:56:11,120 --> 02:56:13,200
to only shift the character by fixed
4798
02:56:13,200 --> 02:56:15,359
number i'll show in the diagram down in
4799
02:56:15,359 --> 02:56:17,680
a moment so let's take an example right
4800
02:56:17,680 --> 02:56:21,920
imagine you got the message brx d u h
4801
02:56:21,920 --> 02:56:25,760
d said h v r p
4802
02:56:25,760 --> 02:56:27,040
what we're going to make out of it no
4803
02:56:27,040 --> 02:56:28,880
sense right so what if we get help with
4804
02:56:28,880 --> 02:56:31,040
this diagram here right so let's look at
4805
02:56:31,040 --> 02:56:33,040
this diagram here right
4806
02:56:33,040 --> 02:56:33,920
so
4807
02:56:33,920 --> 02:56:36,240
c here is a bit difficult to see here
4808
02:56:36,240 --> 02:56:39,439
right a goes to d maybe b goes to e and
4809
02:56:39,439 --> 02:56:41,600
so forth so we shifted the alphabet down
4810
02:56:41,600 --> 02:56:44,720
here by three characters right so the
4811
02:56:44,720 --> 02:56:47,200
three a b and c are over in the end here
4812
02:56:47,200 --> 02:56:51,040
while so a maps to d and so forth right
4813
02:56:51,040 --> 02:56:53,600
so if you had b here and you actually
4814
02:56:53,600 --> 02:56:57,279
find b somewhere in the list here b it's
4815
02:56:57,279 --> 02:56:59,920
was mapped y was mapped to b you see
4816
02:56:59,920 --> 02:57:02,720
that y is above b here because this is
4817
02:57:02,720 --> 02:57:04,479
the encryption algorithm and the
4818
02:57:04,479 --> 02:57:06,880
decryption is opposite right so b maps
4819
02:57:06,880 --> 02:57:08,960
to opposite
4820
02:57:08,960 --> 02:57:09,840
y
4821
02:57:09,840 --> 02:57:12,960
so b maps to y and r
4822
02:57:12,960 --> 02:57:15,680
let's find r it maps to o
4823
02:57:15,680 --> 02:57:18,240
x maps to
4824
02:57:18,240 --> 02:57:19,359
u
4825
02:57:19,359 --> 02:57:22,080
and d you probably figured this one out
4826
02:57:22,080 --> 02:57:23,600
now right d
4827
02:57:23,600 --> 02:57:25,680
a and so forth you can figure this one
4828
02:57:25,680 --> 02:57:28,479
out and try it yourself right so this is
4829
02:57:28,479 --> 02:57:30,880
actually what you want to do right so
4830
02:57:30,880 --> 02:57:33,040
implement so the project you should do
4831
02:57:33,040 --> 02:57:36,560
is implement a helper function encrypt
4832
02:57:36,560 --> 02:57:39,120
char which takes a char and a key to
4833
02:57:39,120 --> 02:57:40,960
encrypt a single character chart with
4834
02:57:40,960 --> 02:57:43,520
key it can be helpful to use this
4835
02:57:43,520 --> 02:57:47,760
function ord and chr and the remainder
4836
02:57:47,760 --> 02:57:49,680
calculations right
4837
02:57:49,680 --> 02:57:51,439
and calculation can be a bit tricky so
4838
02:57:51,439 --> 02:57:52,960
don't worry if you don't figure it out
4839
02:57:52,960 --> 02:57:54,640
but this is fun to play around with to
4840
02:57:54,640 --> 02:57:56,560
figure it out and see if you find out
4841
02:57:56,560 --> 02:57:59,040
right and uh yeah and then you implement
4842
02:57:59,040 --> 02:58:00,880
the message encrypt message message key
4843
02:58:00,880 --> 02:58:02,880
that should be used use a helper
4844
02:58:02,880 --> 02:58:04,560
function we just created up there
4845
02:58:04,560 --> 02:58:07,279
implement similar functions for decrypt
4846
02:58:07,279 --> 02:58:09,040
right so again
4847
02:58:09,040 --> 02:58:11,600
i know that i mean i think
4848
02:58:11,600 --> 02:58:13,279
the first helper function up here is
4849
02:58:13,279 --> 02:58:15,359
quite complex and that's also why it's a
4850
02:58:15,359 --> 02:58:16,960
good idea to make it as a helper
4851
02:58:16,960 --> 02:58:19,760
function because then you can see uh try
4852
02:58:19,760 --> 02:58:21,680
to encrypt one character right if you
4853
02:58:21,680 --> 02:58:24,240
use key three you know key three that it
4854
02:58:24,240 --> 02:58:27,279
should map a to d and b to e and so
4855
02:58:27,279 --> 02:58:28,800
forth and then you can try around with
4856
02:58:28,800 --> 02:58:31,359
it because if you don't nail this one
4857
02:58:31,359 --> 02:58:34,319
here the rest will be wrong right
4858
02:58:34,319 --> 02:58:36,160
obviously
4859
02:58:36,160 --> 02:58:38,640
so are you ready to try and you know you
4860
02:58:38,640 --> 02:58:40,319
should use this one here and this one
4861
02:58:40,319 --> 02:58:43,359
here and this one here and still if you
4862
02:58:43,359 --> 02:58:45,120
don't figure it out
4863
02:58:45,120 --> 02:58:46,800
it is difficult i would say it's not
4864
02:58:46,800 --> 02:58:49,200
easy but it is fun to try to play and
4865
02:58:49,200 --> 02:58:52,000
then see how it can be done and remember
4866
02:58:52,000 --> 02:58:53,760
often there's not just only one solution
4867
02:58:53,760 --> 02:58:56,080
there are multiple are you ready i think
4868
02:58:56,080 --> 02:58:58,160
you are let's get started
4869
02:58:58,160 --> 02:59:00,080
and don't be afraid to get some help
4870
02:59:00,080 --> 02:59:03,760
this is a difficult one see you
4871
02:59:06,720 --> 02:59:08,800
did you how far did you come let me know
4872
02:59:08,800 --> 02:59:10,560
in the comments down below there i would
4873
02:59:10,560 --> 02:59:12,000
love to hear
4874
02:59:12,000 --> 02:59:14,319
where you ended up or if you figured out
4875
02:59:14,319 --> 02:59:16,080
all by yourself don't worry if you
4876
02:59:16,080 --> 02:59:18,479
didn't it's pretty difficult right
4877
02:59:18,479 --> 02:59:21,040
so this is the mapping we want to
4878
02:59:21,040 --> 02:59:23,120
achieve with our helper function right
4879
02:59:23,120 --> 02:59:24,080
remember
4880
02:59:24,080 --> 02:59:25,760
you need to create this helper function
4881
02:59:25,760 --> 02:59:29,040
encrypt char that takes a char and a key
4882
02:59:29,040 --> 02:59:31,040
right so to keep it simple let's try to
4883
02:59:31,040 --> 02:59:33,920
implement it for the value three or not
4884
02:59:33,920 --> 02:59:35,760
we will call it with value three and
4885
02:59:35,760 --> 02:59:37,920
validate it with it to see how it works
4886
02:59:37,920 --> 02:59:38,640
right
4887
02:59:38,640 --> 02:59:42,080
so so far so good let's create a
4888
02:59:42,080 --> 02:59:45,359
function here dev encrypt
4889
02:59:45,359 --> 02:59:49,279
char and it takes jar and key here right
4890
02:59:49,279 --> 02:59:51,200
and it should return something so right
4891
02:59:51,200 --> 02:59:54,640
now let's just return the char and see
4892
02:59:54,640 --> 02:59:57,920
that it doesn't do anything right so
4893
02:59:57,920 --> 03:00:01,040
so far so good encrypt
4894
03:00:01,040 --> 03:00:03,520
char and it will take let's say a here
4895
03:00:03,520 --> 03:00:05,520
and a key here three here so this is a
4896
03:00:05,520 --> 03:00:07,359
purpose here so right now it fails
4897
03:00:07,359 --> 03:00:09,040
because it maps a to a because we don't
4898
03:00:09,040 --> 03:00:10,640
do anything right
4899
03:00:10,640 --> 03:00:11,439
so
4900
03:00:11,439 --> 03:00:13,600
it says to use these helper functions
4901
03:00:13,600 --> 03:00:16,399
here right there or
4902
03:00:16,399 --> 03:00:17,720
cr
4903
03:00:17,720 --> 03:00:20,880
chr and then remainder right
4904
03:00:20,880 --> 03:00:23,279
so how can we do that right
4905
03:00:23,279 --> 03:00:25,840
it is to be honest it is or one
4906
03:00:25,840 --> 03:00:27,680
calculations but you can do it in
4907
03:00:27,680 --> 03:00:29,120
multiple steps and that's what we're
4908
03:00:29,120 --> 03:00:33,040
gonna do right so remember if we mapped
4909
03:00:33,040 --> 03:00:35,520
if we mapped uh
4910
03:00:35,520 --> 03:00:36,399
it
4911
03:00:36,399 --> 03:00:38,960
this one here we get the unicode of char
4912
03:00:38,960 --> 03:00:40,720
and then we can actually add the key to
4913
03:00:40,720 --> 03:00:43,760
it and return that and
4914
03:00:43,760 --> 03:00:45,760
then we have a key value let's just see
4915
03:00:45,760 --> 03:00:47,600
that here right so now we get 68
4916
03:00:47,600 --> 03:00:48,640
remember
4917
03:00:48,640 --> 03:00:51,600
that the order of
4918
03:00:51,600 --> 03:00:53,120
a
4919
03:00:53,120 --> 03:00:55,200
or 65 right so we added three to it so
4920
03:00:55,200 --> 03:00:57,840
this looks pretty pretty nice so how do
4921
03:00:57,840 --> 03:00:59,760
we turn that into a character and we do
4922
03:00:59,760 --> 03:01:01,760
it like this here right
4923
03:01:01,760 --> 03:01:02,479
so
4924
03:01:02,479 --> 03:01:03,840
is this it
4925
03:01:03,840 --> 03:01:06,080
it seems pretty good right but there's a
4926
03:01:06,080 --> 03:01:08,000
catch right if we come to the end of the
4927
03:01:08,000 --> 03:01:09,040
alphabet
4928
03:01:09,040 --> 03:01:11,520
so if we map x for instance let's just
4929
03:01:11,520 --> 03:01:13,760
take w first just to assume that it goes
4930
03:01:13,760 --> 03:01:14,460
well here
4931
03:01:14,460 --> 03:01:15,760
[Music]
4932
03:01:15,760 --> 03:01:18,640
it goes fine well but after w we get x
4933
03:01:18,640 --> 03:01:20,640
here and it gets a square brackets and
4934
03:01:20,640 --> 03:01:23,040
that's where the a should come in right
4935
03:01:23,040 --> 03:01:24,640
so this is where the
4936
03:01:24,640 --> 03:01:29,600
this is the strange thing of uh
4937
03:01:29,600 --> 03:01:32,560
a strange thing of the house called the
4938
03:01:32,560 --> 03:01:34,960
modulus or the remainder calculation
4939
03:01:34,960 --> 03:01:37,359
comes into the picture right
4940
03:01:37,359 --> 03:01:38,080
so
4941
03:01:38,080 --> 03:01:40,800
how can we do that now
4942
03:01:40,800 --> 03:01:42,880
this is difficult because actually we
4943
03:01:42,880 --> 03:01:44,960
have a problem here because this value
4944
03:01:44,960 --> 03:01:48,240
here should not index to
4945
03:01:48,240 --> 03:01:51,120
to zero after it comes up to this value
4946
03:01:51,120 --> 03:01:53,840
which is 90 actually so what should it
4947
03:01:53,840 --> 03:01:56,319
map to right hmm
4948
03:01:56,319 --> 03:01:57,279
well
4949
03:01:57,279 --> 03:01:59,840
first of all let's just try to add this
4950
03:01:59,840 --> 03:02:01,200
together here
4951
03:02:01,200 --> 03:02:02,960
and then we have here and then we put
4952
03:02:02,960 --> 03:02:04,080
modulus
4953
03:02:04,080 --> 03:02:06,160
well what is the modulus looks like it's
4954
03:02:06,160 --> 03:02:08,800
26 right because we know they're 26
4955
03:02:08,800 --> 03:02:10,800
characters but the problem is
4956
03:02:10,800 --> 03:02:14,479
then we need to add more again
4957
03:02:14,479 --> 03:02:16,560
how do you do that so let's say we take
4958
03:02:16,560 --> 03:02:18,640
the a character
4959
03:02:18,640 --> 03:02:21,600
and subtract that
4960
03:02:21,600 --> 03:02:23,080
from our value right
4961
03:02:23,080 --> 03:02:24,720
[Music]
4962
03:02:24,720 --> 03:02:26,960
what if we subtract that a character
4963
03:02:26,960 --> 03:02:31,120
this which is 65 right
4964
03:02:31,120 --> 03:02:33,680
so we subtract now
4965
03:02:33,680 --> 03:02:35,120
a from it
4966
03:02:35,120 --> 03:02:37,920
we add the key to it so what do we have
4967
03:02:37,920 --> 03:02:39,680
here right so we
4968
03:02:39,680 --> 03:02:42,000
take the character if it was a we
4969
03:02:42,000 --> 03:02:44,560
subtract a so it's zero and then we add
4970
03:02:44,560 --> 03:02:47,600
the key and then we take it modulus 26
4971
03:02:47,600 --> 03:02:49,680
right because that's 26 characters and
4972
03:02:49,680 --> 03:02:51,120
then if we just
4973
03:02:51,120 --> 03:02:52,000
take
4974
03:02:52,000 --> 03:02:55,840
and add a outside here right
4975
03:02:55,840 --> 03:02:57,600
i actually think we're pretty close now
4976
03:02:57,600 --> 03:03:00,880
let's try this one boom a you saw that
4977
03:03:00,880 --> 03:03:02,720
but is everything correct now
4978
03:03:02,720 --> 03:03:06,399
well there's one way to find it out
4979
03:03:07,520 --> 03:03:10,800
let's try just a few ones here a becomes
4980
03:03:10,800 --> 03:03:14,240
d set becomes c
4981
03:03:14,240 --> 03:03:16,800
uh it looks pretty good right so if this
4982
03:03:16,800 --> 03:03:18,640
was a bit confusing don't worry about it
4983
03:03:18,640 --> 03:03:20,560
but look what we do here it's because we
4984
03:03:20,560 --> 03:03:22,640
need to do this remainder calculations
4985
03:03:22,640 --> 03:03:23,520
here
4986
03:03:23,520 --> 03:03:24,640
and
4987
03:03:24,640 --> 03:03:27,279
in order to do that we actually subtract
4988
03:03:27,279 --> 03:03:28,240
the
4989
03:03:28,240 --> 03:03:30,960
65 from the character value and add the
4990
03:03:30,960 --> 03:03:33,600
key and then do the modulus calculation
4991
03:03:33,600 --> 03:03:36,080
with the 26 here and then we add that to
4992
03:03:36,080 --> 03:03:39,359
the 65 character again right so it looks
4993
03:03:39,359 --> 03:03:41,439
a bit confusing i know don't worry about
4994
03:03:41,439 --> 03:03:42,160
it
4995
03:03:42,160 --> 03:03:44,800
it is the tricky part so
4996
03:03:44,800 --> 03:03:48,000
next thing next up here right what do we
4997
03:03:48,000 --> 03:03:50,000
need to know we need to make this
4998
03:03:50,000 --> 03:03:52,000
function encrypt
4999
03:03:52,000 --> 03:03:55,520
message now and it takes the message and
5000
03:03:55,520 --> 03:03:58,240
key here right
5001
03:03:58,240 --> 03:04:03,040
so what we need to do now is actually we
5002
03:04:03,600 --> 03:04:06,240
we focused on uppercase words so we need
5003
03:04:06,240 --> 03:04:09,920
to convert our message to upper right
5004
03:04:09,920 --> 03:04:11,600
just to make sure that the user didn't
5005
03:04:11,600 --> 03:04:13,520
mess something up i'm a user and i would
5006
03:04:13,520 --> 03:04:15,439
know how to mess it up so i just ensure
5007
03:04:15,439 --> 03:04:18,399
that all the characters are in uppercase
5008
03:04:18,399 --> 03:04:20,880
and then let's just have a cipher here
5009
03:04:20,880 --> 03:04:22,640
and
5010
03:04:22,640 --> 03:04:24,640
that's a cipher text okay and then we
5011
03:04:24,640 --> 03:04:27,359
take four char in message
5012
03:04:27,359 --> 03:04:28,960
uh
5013
03:04:28,960 --> 03:04:30,800
in message right
5014
03:04:30,800 --> 03:04:32,240
and then what do we do we call the
5015
03:04:32,240 --> 03:04:33,760
encrypt but there's a cache right there
5016
03:04:33,760 --> 03:04:36,000
might be spaces and stuff like that so
5017
03:04:36,000 --> 03:04:36,880
if
5018
03:04:36,880 --> 03:04:38,560
so we do if c
5019
03:04:38,560 --> 03:04:40,080
in
5020
03:04:40,080 --> 03:04:43,439
not in we could say not in or maybe we
5021
03:04:43,439 --> 03:04:45,439
just say in
5022
03:04:45,439 --> 03:04:47,680
the characters let's say space dot and
5023
03:04:47,680 --> 03:04:49,120
comma
5024
03:04:49,120 --> 03:04:52,160
if it is this case then we take cipher
5025
03:04:52,160 --> 03:04:53,200
is
5026
03:04:53,200 --> 03:04:57,520
equal to cipher plus a character right
5027
03:04:57,520 --> 03:05:00,080
else we call cipher
5028
03:05:00,080 --> 03:05:02,960
and we take cipher and plus
5029
03:05:02,960 --> 03:05:04,720
encrypt
5030
03:05:04,720 --> 03:05:06,399
char right
5031
03:05:06,399 --> 03:05:08,800
where we call it with c right this
5032
03:05:08,800 --> 03:05:11,600
should basically do it and then we
5033
03:05:11,600 --> 03:05:14,640
should return cipher okay let's try that
5034
03:05:14,640 --> 03:05:17,439
one okay confused not really i'll walk
5035
03:05:17,439 --> 03:05:18,720
you through in a moment
5036
03:05:18,720 --> 03:05:20,720
encrypt message
5037
03:05:20,720 --> 03:05:22,640
and we take
5038
03:05:22,640 --> 03:05:25,760
you are awesome
5039
03:05:25,760 --> 03:05:27,200
and we have an
5040
03:05:27,200 --> 03:05:29,680
oh we need i forgot the key here right
5041
03:05:29,680 --> 03:05:32,720
i'm so excited about it and i actually
5042
03:05:32,720 --> 03:05:34,640
forgot the key down here
5043
03:05:34,640 --> 03:05:37,359
and got so excited right perfect here
5044
03:05:37,359 --> 03:05:38,720
right so now we actually have this
5045
03:05:38,720 --> 03:05:41,279
message here which is actually the same
5046
03:05:41,279 --> 03:05:43,520
one as we have up here right
5047
03:05:43,520 --> 03:05:44,840
that's pretty
5048
03:05:44,840 --> 03:05:48,479
cool that's pretty cool actually
5049
03:05:48,479 --> 03:05:51,040
okay so let's just check this code here
5050
03:05:51,040 --> 03:05:53,120
again so encrypt message right so first
5051
03:05:53,120 --> 03:05:54,560
step here we just put everything in
5052
03:05:54,560 --> 03:05:57,040
uppercase in order to ensure that then
5053
03:05:57,040 --> 03:05:58,800
we have an empty string called cipher
5054
03:05:58,800 --> 03:06:00,800
which we'll use to add character by
5055
03:06:00,800 --> 03:06:02,319
character because then we take the
5056
03:06:02,319 --> 03:06:04,160
message the character from the measured
5057
03:06:04,160 --> 03:06:05,359
one by one
5058
03:06:05,359 --> 03:06:07,680
if the character is a space a special
5059
03:06:07,680 --> 03:06:09,600
character basically then we just add it
5060
03:06:09,600 --> 03:06:12,080
we just ignore it right otherwise we
5061
03:06:12,080 --> 03:06:14,399
encrypt it with the key here and
5062
03:06:14,399 --> 03:06:16,560
if you like me all excited you just
5063
03:06:16,560 --> 03:06:18,479
forget about putting the key in there
5064
03:06:18,479 --> 03:06:20,720
never mind right and actually now you
5065
03:06:20,720 --> 03:06:22,399
can use other keys but let's just leave
5066
03:06:22,399 --> 03:06:23,840
that for you to play around because the
5067
03:06:23,840 --> 03:06:26,240
next step is we need to make decrypt
5068
03:06:26,240 --> 03:06:27,359
right
5069
03:06:27,359 --> 03:06:28,479
hmm
5070
03:06:28,479 --> 03:06:30,160
how did you do that
5071
03:06:30,160 --> 03:06:32,800
if it was me at first i would rewrite
5072
03:06:32,800 --> 03:06:35,680
everything up here
5073
03:06:36,080 --> 03:06:39,319
in a decryption function let's do that
5074
03:06:39,319 --> 03:06:41,040
decrypt
5075
03:06:41,040 --> 03:06:43,279
char
5076
03:06:43,279 --> 03:06:44,720
char
5077
03:06:44,720 --> 03:06:47,279
key well it's probably pretty
5078
03:06:47,279 --> 03:06:49,120
the same here right but we need to do it
5079
03:06:49,120 --> 03:06:51,840
opposite order now right so let's just
5080
03:06:51,840 --> 03:06:54,479
actually start with the same thing as we
5081
03:06:54,479 --> 03:06:57,840
have up here
5082
03:06:57,920 --> 03:06:58,880
and let's
5083
03:06:58,880 --> 03:07:02,000
change something here right
5084
03:07:02,479 --> 03:07:03,840
so
5085
03:07:03,840 --> 03:07:05,279
if
5086
03:07:05,279 --> 03:07:07,040
encryption and decryption are actually
5087
03:07:07,040 --> 03:07:08,800
the opposite of each other right
5088
03:07:08,800 --> 03:07:10,479
decryption is actually the opposite way
5089
03:07:10,479 --> 03:07:13,439
so that's actually the
5090
03:07:13,520 --> 03:07:18,000
26 minus the key right
5091
03:07:18,560 --> 03:07:20,399
instead of plus a key here so that
5092
03:07:20,399 --> 03:07:22,240
should actually do it right so let's try
5093
03:07:22,240 --> 03:07:24,800
that one here so let's decrypt
5094
03:07:24,800 --> 03:07:28,000
a char let's decrypt d here with key 3
5095
03:07:28,000 --> 03:07:29,920
here and we see we get a here so this is
5096
03:07:29,920 --> 03:07:31,600
opposite right so all we need to do is
5097
03:07:31,600 --> 03:07:33,680
this one here that's pretty nice right
5098
03:07:33,680 --> 03:07:35,680
so now we have that one there so let's
5099
03:07:35,680 --> 03:07:38,960
try to make a decrypt def
5100
03:07:38,960 --> 03:07:39,680
the
5101
03:07:39,680 --> 03:07:40,800
crypt
5102
03:07:40,800 --> 03:07:42,479
message
5103
03:07:42,479 --> 03:07:45,200
cipher now and key here
5104
03:07:45,200 --> 03:07:46,240
and
5105
03:07:46,240 --> 03:07:48,240
do we assume the cipher is an upper case
5106
03:07:48,240 --> 03:07:51,439
i think so we do so we just take message
5107
03:07:51,439 --> 03:07:54,399
and we put it to the empty message oops
5108
03:07:54,399 --> 03:07:55,520
ah
5109
03:07:55,520 --> 03:07:57,920
message and put it to the empty message
5110
03:07:57,920 --> 03:07:58,640
here
5111
03:07:58,640 --> 03:08:02,240
and then for c in cypher
5112
03:08:02,240 --> 03:08:04,960
we'd say if c in
5113
03:08:04,960 --> 03:08:07,840
this space
5114
03:08:07,840 --> 03:08:09,600
and dot it was with opposite order here
5115
03:08:09,600 --> 03:08:12,640
it doesn't matter then cipher equals
5116
03:08:12,640 --> 03:08:14,240
cipher plus
5117
03:08:14,240 --> 03:08:15,600
c
5118
03:08:15,600 --> 03:08:17,279
else
5119
03:08:17,279 --> 03:08:21,640
cipher or message
5120
03:08:24,160 --> 03:08:25,200
message
5121
03:08:25,200 --> 03:08:28,800
thank you for helping me here message
5122
03:08:28,800 --> 03:08:30,880
message
5123
03:08:30,880 --> 03:08:34,080
message plus
5124
03:08:34,080 --> 03:08:36,240
decrypt
5125
03:08:36,240 --> 03:08:38,399
char
5126
03:08:38,399 --> 03:08:40,560
c key
5127
03:08:40,560 --> 03:08:43,600
oops and we need still we need to
5128
03:08:43,600 --> 03:08:46,080
return message so let's try that one
5129
03:08:46,080 --> 03:08:46,960
right
5130
03:08:46,960 --> 03:08:48,399
so the
5131
03:08:48,399 --> 03:08:50,319
crypt message
5132
03:08:50,319 --> 03:08:52,960
what message do you want to decrypt
5133
03:08:52,960 --> 03:08:55,600
this one here
5134
03:08:57,439 --> 03:08:59,120
three
5135
03:08:59,120 --> 03:09:01,760
you are awesome right
5136
03:09:01,760 --> 03:09:02,960
if you're really really smart you
5137
03:09:02,960 --> 03:09:04,880
probably realize this can be done a bit
5138
03:09:04,880 --> 03:09:07,840
smarter right so let's try to do that a
5139
03:09:07,840 --> 03:09:09,920
bit smarter right
5140
03:09:09,920 --> 03:09:11,040
so
5141
03:09:11,040 --> 03:09:14,720
let's make a new function here def de
5142
03:09:14,720 --> 03:09:16,240
crypt
5143
03:09:16,240 --> 03:09:17,680
message
5144
03:09:17,680 --> 03:09:18,880
two
5145
03:09:18,880 --> 03:09:21,279
and called cipher and key
5146
03:09:21,279 --> 03:09:22,880
because you'll probably realize that
5147
03:09:22,880 --> 03:09:24,880
this is the same
5148
03:09:24,880 --> 03:09:26,319
sequence here and it's just the key
5149
03:09:26,319 --> 03:09:29,200
minus here so what if we just return
5150
03:09:29,200 --> 03:09:32,239
encrypt message with a
5151
03:09:32,239 --> 03:09:33,439
cipher
5152
03:09:33,439 --> 03:09:34,960
and we take
5153
03:09:34,960 --> 03:09:37,600
26 minus key right
5154
03:09:37,600 --> 03:09:40,160
what happens then let's try that
5155
03:09:40,160 --> 03:09:42,239
so decrypt
5156
03:09:42,239 --> 03:09:45,680
message 2 and we take our favorite
5157
03:09:45,680 --> 03:09:48,080
message here
5158
03:09:48,080 --> 03:09:50,479
and we take three here and you see it
5159
03:09:50,479 --> 03:09:52,560
also works like that
5160
03:09:52,560 --> 03:09:54,239
so basically because the encryption
5161
03:09:54,239 --> 03:09:55,840
decryption is the same algorithm you
5162
03:09:55,840 --> 03:09:58,160
don't need to implement it all again but
5163
03:09:58,160 --> 03:10:00,479
it's just fun to do it right it's just
5164
03:10:00,479 --> 03:10:02,239
fun and often when you see like i say oh
5165
03:10:02,239 --> 03:10:04,479
why didn't i think of that well i had
5166
03:10:04,479 --> 03:10:06,319
multiple experiences like that so don't
5167
03:10:06,319 --> 03:10:08,319
worry if you had the same experience i
5168
03:10:08,319 --> 03:10:10,239
think maybe even i did this myself a
5169
03:10:10,239 --> 03:10:12,399
long long time ago i don't remember
5170
03:10:12,399 --> 03:10:15,359
but it is quite fun right so again this
5171
03:10:15,359 --> 03:10:17,200
one seems quite complex and this is
5172
03:10:17,200 --> 03:10:19,600
probably i mean
5173
03:10:19,600 --> 03:10:21,200
if it doesn't make sense at first try to
5174
03:10:21,200 --> 03:10:22,800
write it down try to make some simple
5175
03:10:22,800 --> 03:10:25,040
examples calculate it yourself with
5176
03:10:25,040 --> 03:10:27,279
specific values it will help you a lot
5177
03:10:27,279 --> 03:10:28,720
you can actually take this one and print
5178
03:10:28,720 --> 03:10:31,200
them out one by one and figure out what
5179
03:10:31,200 --> 03:10:32,720
are the values of each of them and
5180
03:10:32,720 --> 03:10:34,720
calculate it by yourself the tricky part
5181
03:10:34,720 --> 03:10:36,560
is to understand this remainder think of
5182
03:10:36,560 --> 03:10:38,880
it like a clock that has 26 hours and
5183
03:10:38,880 --> 03:10:40,720
then it resets every time right start
5184
03:10:40,720 --> 03:10:43,520
from zero again every time it reaches 26
5185
03:10:43,520 --> 03:10:45,120
it's zero instead
5186
03:10:45,120 --> 03:10:47,920
zero instead zero instead right
5187
03:10:47,920 --> 03:10:48,880
uh
5188
03:10:48,880 --> 03:10:51,760
good and uh that's basically it i mean
5189
03:10:51,760 --> 03:10:54,319
this is amazing isn't it fun i think so
5190
03:10:54,319 --> 03:10:57,520
amazing see you in a moment
5191
03:11:00,000 --> 03:11:02,000
so this one is exciting because we're
5192
03:11:02,000 --> 03:11:04,800
gonna learn a new data structure so this
5193
03:11:04,800 --> 03:11:06,960
is one of the built-in data structures
5194
03:11:06,960 --> 03:11:09,600
from python and it is used all the time
5195
03:11:09,600 --> 03:11:11,520
it's called the dictionary
5196
03:11:11,520 --> 03:11:14,720
whoa so what is a dictionary well in the
5197
03:11:14,720 --> 03:11:17,600
one hand it actually is similar to a
5198
03:11:17,600 --> 03:11:19,359
dictionary you know the one on the
5199
03:11:19,359 --> 03:11:21,520
bookshelf those physical books i don't
5200
03:11:21,520 --> 03:11:23,120
know you remember those
5201
03:11:23,120 --> 03:11:24,960
back in the times when people had these
5202
03:11:24,960 --> 03:11:27,040
big shells with books on right one of
5203
03:11:27,040 --> 03:11:29,760
them might be called a dictionary so how
5204
03:11:29,760 --> 03:11:31,359
would you use a dictionary well you
5205
03:11:31,359 --> 03:11:33,279
would have a word that you wanted to
5206
03:11:33,279 --> 03:11:36,399
look up and find the explanation of the
5207
03:11:36,399 --> 03:11:39,520
word what type of word and so on so
5208
03:11:39,520 --> 03:11:41,760
the key thing is that the word you're
5209
03:11:41,760 --> 03:11:43,760
looking for is the one you find the
5210
03:11:43,760 --> 03:11:46,399
content with right so you have a key and
5211
03:11:46,399 --> 03:11:49,200
a value right the key is a word and the
5212
03:11:49,200 --> 03:11:51,200
value is the description of the word
5213
03:11:51,200 --> 03:11:52,239
right
5214
03:11:52,239 --> 03:11:56,239
a python dictionary is similar
5215
03:11:56,239 --> 03:11:57,680
you have a key
5216
03:11:57,680 --> 03:11:59,439
this is the one you want to look up and
5217
03:11:59,439 --> 03:12:01,840
then you have a value which is a content
5218
03:12:01,840 --> 03:12:03,680
the description like in a dictionary
5219
03:12:03,680 --> 03:12:04,640
right
5220
03:12:04,640 --> 03:12:07,439
so key and value pairs what am i talking
5221
03:12:07,439 --> 03:12:10,399
about let's jump to jupiter notebook and
5222
03:12:10,399 --> 03:12:13,439
figure it out right you ready i am let's
5223
03:12:13,439 --> 03:12:14,880
get started
5224
03:12:14,880 --> 03:12:17,760
so here we are in our jupyter notebook
5225
03:12:17,760 --> 03:12:19,600
and we have the dictionaries here the
5226
03:12:19,600 --> 03:12:21,040
goal of this one is to learn about
5227
03:12:21,040 --> 03:12:24,239
dictionaries and uh yeah what do they do
5228
03:12:24,239 --> 03:12:27,120
they have these key value pairs i also
5229
03:12:27,120 --> 03:12:29,279
write dict here and this is because that
5230
03:12:29,279 --> 03:12:32,479
in python they often refer to the mastic
5231
03:12:32,479 --> 03:12:35,200
okay let's get started so the best way
5232
03:12:35,200 --> 03:12:37,200
to learn about things is often just to
5233
03:12:37,200 --> 03:12:38,960
see them and play a bit around with them
5234
03:12:38,960 --> 03:12:40,640
so let's try to do that right are you
5235
03:12:40,640 --> 03:12:42,800
ready yeah you are
5236
03:12:42,800 --> 03:12:45,279
so my dick
5237
03:12:45,279 --> 03:12:47,279
my dick
5238
03:12:47,279 --> 03:12:49,600
uh so the way you create python
5239
03:12:49,600 --> 03:12:51,840
dictionaries is with curly brackets like
5240
03:12:51,840 --> 03:12:52,960
this right
5241
03:12:52,960 --> 03:12:55,200
so if you do like this you just create
5242
03:12:55,200 --> 03:12:57,279
an empty dictionaries and you could do
5243
03:12:57,279 --> 03:12:59,279
that and then you can add items to them
5244
03:12:59,279 --> 03:13:00,800
just like you had a list where you can
5245
03:13:00,800 --> 03:13:03,359
append elements to them we're not going
5246
03:13:03,359 --> 03:13:04,560
to do that here we're just going to
5247
03:13:04,560 --> 03:13:07,439
create one here and just describe how it
5248
03:13:07,439 --> 03:13:09,520
works so i said
5249
03:13:09,520 --> 03:13:12,239
a dictionary keeps key and value spares
5250
03:13:12,239 --> 03:13:14,239
so let's try to put a key in here and
5251
03:13:14,239 --> 03:13:16,080
the key could be anything now we just
5252
03:13:16,080 --> 03:13:18,479
keep it as a string key one and then use
5253
03:13:18,479 --> 03:13:20,640
colon here to
5254
03:13:20,640 --> 03:13:23,359
put the value behind there and the value
5255
03:13:23,359 --> 03:13:25,279
could also be anything now we have the
5256
03:13:25,279 --> 03:13:27,359
key as a string and the value is a
5257
03:13:27,359 --> 03:13:29,120
string
5258
03:13:29,120 --> 03:13:31,120
and let's just add another one here key
5259
03:13:31,120 --> 03:13:31,920
2
5260
03:13:31,920 --> 03:13:33,359
and
5261
03:13:33,359 --> 03:13:36,560
value 2 right so now we have actually
5262
03:13:36,560 --> 03:13:38,880
created a dictionary here
5263
03:13:38,880 --> 03:13:39,680
and
5264
03:13:39,680 --> 03:13:41,520
again we have the key and the value so
5265
03:13:41,520 --> 03:13:44,239
you might think how do i access things
5266
03:13:44,239 --> 03:13:47,279
right so again like a dictionary
5267
03:13:47,279 --> 03:13:48,880
the physical book i was talking about
5268
03:13:48,880 --> 03:13:51,120
right you would look up at word right
5269
03:13:51,120 --> 03:13:54,319
and this is the key to our
5270
03:13:54,319 --> 03:13:55,840
thing right so if i wanted to look at
5271
03:13:55,840 --> 03:13:58,800
the value of key one then i just write
5272
03:13:58,800 --> 03:14:01,600
it like that and then i get it right and
5273
03:14:01,600 --> 03:14:03,439
you probably already guessed it what
5274
03:14:03,439 --> 03:14:05,920
would happen if i put key two instead
5275
03:14:05,920 --> 03:14:08,840
here well i would get the value of key
5276
03:14:08,840 --> 03:14:11,760
two so this is really really nice so
5277
03:14:11,760 --> 03:14:14,160
this is how a dictionary works and a
5278
03:14:14,160 --> 03:14:15,680
great thing about dictionaries is you
5279
03:14:15,680 --> 03:14:17,279
can just add
5280
03:14:17,279 --> 03:14:20,000
items or key value pairs along the way
5281
03:14:20,000 --> 03:14:22,479
so i created it here so i can put a key
5282
03:14:22,479 --> 03:14:23,600
for
5283
03:14:23,600 --> 03:14:26,880
key 3 and add value 3 for instance right
5284
03:14:26,880 --> 03:14:29,200
and now my dictionary
5285
03:14:29,200 --> 03:14:31,760
looks like this here right
5286
03:14:31,760 --> 03:14:34,000
so please note that we have key 1 value
5287
03:14:34,000 --> 03:14:37,680
1 key 2 value 2 key 3 value 3. and the
5288
03:14:37,680 --> 03:14:40,640
key 3 was assigned here so it was not
5289
03:14:40,640 --> 03:14:42,720
originally assigned in the definition
5290
03:14:42,720 --> 03:14:45,680
here so you can just add key values
5291
03:14:45,680 --> 03:14:47,760
pairs along the way
5292
03:14:47,760 --> 03:14:50,880
you can also update the values
5293
03:14:50,880 --> 03:14:52,880
my dick here for instance if you take
5294
03:14:52,880 --> 03:14:56,319
key 2 here you can update it and you can
5295
03:14:56,319 --> 03:14:59,680
actually use a similar
5296
03:14:59,680 --> 03:15:02,800
the values do not need to be unique
5297
03:15:02,800 --> 03:15:04,880
so let's just say we have put a value 3
5298
03:15:04,880 --> 03:15:06,399
here
5299
03:15:06,399 --> 03:15:08,560
so let's see what happens here then you
5300
03:15:08,560 --> 03:15:10,800
can actually see here that the values
5301
03:15:10,800 --> 03:15:12,800
can be the same
5302
03:15:12,800 --> 03:15:15,439
but the keys obviously need to be unique
5303
03:15:15,439 --> 03:15:19,439
you cannot assign the same
5304
03:15:19,680 --> 03:15:21,439
key multiple times then you wouldn't
5305
03:15:21,439 --> 03:15:23,279
know which key we're looking up right so
5306
03:15:23,279 --> 03:15:25,439
the keys are unique that means there can
5307
03:15:25,439 --> 03:15:28,080
only be one key of each type of each
5308
03:15:28,080 --> 03:15:30,880
value not bad it's a it's a bit awkward
5309
03:15:30,880 --> 03:15:32,800
to use the word value there right
5310
03:15:32,800 --> 03:15:35,120
because the values are behind the keys
5311
03:15:35,120 --> 03:15:36,000
okay
5312
03:15:36,000 --> 03:15:39,040
good makes sense
5313
03:15:39,040 --> 03:15:40,239
so
5314
03:15:40,239 --> 03:15:42,720
often people struggle a little bit with
5315
03:15:42,720 --> 03:15:43,760
well
5316
03:15:43,760 --> 03:15:45,760
when do i use these and why are they so
5317
03:15:45,760 --> 03:15:46,800
useful
5318
03:15:46,800 --> 03:15:49,279
well
5319
03:15:49,279 --> 03:15:52,160
recall a database for instance or an
5320
03:15:52,160 --> 03:15:54,720
excel sheet or something like that
5321
03:15:54,720 --> 03:15:58,080
so often what you have are rows of data
5322
03:15:58,080 --> 03:16:00,880
with similar
5323
03:16:01,279 --> 03:16:03,600
the keys in them actually and this is
5324
03:16:03,600 --> 03:16:06,080
called a record so let's do one for a
5325
03:16:06,080 --> 03:16:08,720
car for instance let's make a record for
5326
03:16:08,720 --> 03:16:11,200
a car so imagine we had a long
5327
03:16:11,200 --> 03:16:14,479
row of cars where you had the brand the
5328
03:16:14,479 --> 03:16:16,720
model and the year right so you had a
5329
03:16:16,720 --> 03:16:18,800
big sheet of that then one row would be
5330
03:16:18,800 --> 03:16:20,720
a record in it that's what you call it
5331
03:16:20,720 --> 03:16:21,520
right
5332
03:16:21,520 --> 03:16:23,200
so let's try to make one like that so
5333
03:16:23,200 --> 03:16:25,520
let's say here we have the brand
5334
03:16:25,520 --> 03:16:27,439
and the brand here what car should we
5335
03:16:27,439 --> 03:16:31,680
take lamborghini i like you lambo
5336
03:16:31,680 --> 03:16:34,479
lamborghini
5337
03:16:34,479 --> 03:16:36,640
was almost not possible
5338
03:16:36,640 --> 03:16:38,399
someone was spelling it wrong so
5339
03:16:38,399 --> 03:16:40,960
lamborghini so what model should we take
5340
03:16:40,960 --> 03:16:42,840
here
5341
03:16:42,840 --> 03:16:45,600
modeler yeah i know we are in these
5342
03:16:45,600 --> 03:16:48,880
times when we need green energy green
5343
03:16:48,880 --> 03:16:51,200
green driving so we need an electric one
5344
03:16:51,200 --> 03:16:53,439
and luckily lamborghini has an electric
5345
03:16:53,439 --> 03:16:56,319
car and it's called xi'an
5346
03:16:56,319 --> 03:16:58,960
right so lamborghini
5347
03:16:58,960 --> 03:17:00,720
i know in the us you often call it a
5348
03:17:00,720 --> 03:17:04,239
lambo lambo lambo yeah i know that i
5349
03:17:04,239 --> 03:17:05,760
think it's because
5350
03:17:05,760 --> 03:17:07,200
you have a hard time to pronounce
5351
03:17:07,200 --> 03:17:08,640
lamborghini
5352
03:17:08,640 --> 03:17:10,880
i probably don't do it perfectly because
5353
03:17:10,880 --> 03:17:14,319
it's like it's italian
5354
03:17:14,319 --> 03:17:16,239
the car model names are actually most of
5355
03:17:16,239 --> 03:17:18,319
the time spanish names
5356
03:17:18,319 --> 03:17:21,200
named after spanish bulls right is that
5357
03:17:21,200 --> 03:17:23,760
the case i think so
5358
03:17:23,760 --> 03:17:25,760
good and then we have the year of this
5359
03:17:25,760 --> 03:17:27,920
one here and that was a trick right
5360
03:17:27,920 --> 03:17:29,920
because now we can put for instance an
5361
03:17:29,920 --> 03:17:32,399
integer because a year is an integer
5362
03:17:32,399 --> 03:17:34,319
right so here you also see how they can
5363
03:17:34,319 --> 03:17:36,239
have different types here so this is a
5364
03:17:36,239 --> 03:17:38,960
string string and an integer right
5365
03:17:38,960 --> 03:17:41,120
so how would this record look like like
5366
03:17:41,120 --> 03:17:42,880
this
5367
03:17:42,880 --> 03:17:44,560
so
5368
03:17:44,560 --> 03:17:46,640
in the next lecture we're going to learn
5369
03:17:46,640 --> 03:17:48,800
about csv files
5370
03:17:48,800 --> 03:17:52,000
and csv files are rows of similar data
5371
03:17:52,000 --> 03:17:53,840
like i talked about like an excel sheet
5372
03:17:53,840 --> 03:17:55,840
right where you have the columns and you
5373
03:17:55,840 --> 03:17:57,840
have the same rows or a database if you
5374
03:17:57,840 --> 03:18:00,560
can relate to that instead right so rows
5375
03:18:00,560 --> 03:18:03,359
of the same type of data right and a
5376
03:18:03,359 --> 03:18:05,520
great way to read that data is to read
5377
03:18:05,520 --> 03:18:07,359
it into a dictionary and we're going to
5378
03:18:07,359 --> 03:18:08,800
do that it's going to be awesome right
5379
03:18:08,800 --> 03:18:10,319
this is also why we need to learn about
5380
03:18:10,319 --> 03:18:12,720
dictionaries and in the game
5381
03:18:12,720 --> 03:18:14,319
not in the game in the project we're
5382
03:18:14,319 --> 03:18:15,359
going to you and you're also going to
5383
03:18:15,359 --> 03:18:18,720
see some awesome use cases of
5384
03:18:18,720 --> 03:18:20,640
dictionaries right
5385
03:18:20,640 --> 03:18:22,640
so here we have it
5386
03:18:22,640 --> 03:18:24,239
a record like this one and we could have
5387
03:18:24,239 --> 03:18:26,239
multiple cars but we took this car just
5388
03:18:26,239 --> 03:18:28,239
to show it as an example
5389
03:18:28,239 --> 03:18:31,040
one thing that you often also use these
5390
03:18:31,040 --> 03:18:33,120
uh
5391
03:18:33,120 --> 03:18:35,200
dictionaries to is actually counting
5392
03:18:35,200 --> 03:18:37,840
occurrences of something right
5393
03:18:37,840 --> 03:18:38,720
and
5394
03:18:38,720 --> 03:18:40,560
me personally i use it all the time for
5395
03:18:40,560 --> 03:18:42,479
that so for instance if we had a list
5396
03:18:42,479 --> 03:18:44,080
now
5397
03:18:44,080 --> 03:18:46,160
let's just have a list of items here
5398
03:18:46,160 --> 03:18:48,239
and these items could be strings right
5399
03:18:48,239 --> 03:18:51,720
so we have a pen here we can have a
5400
03:18:51,720 --> 03:18:53,359
scissor
5401
03:18:53,359 --> 03:18:55,600
i'm gonna have another pen here
5402
03:18:55,600 --> 03:18:57,279
we have a
5403
03:18:57,279 --> 03:18:59,200
pen here again and then let's just we
5404
03:18:59,200 --> 03:19:01,200
have a scissor and let's just say we
5405
03:19:01,200 --> 03:19:02,479
have these
5406
03:19:02,479 --> 03:19:04,800
five items there so
5407
03:19:04,800 --> 03:19:09,279
our goal now is to count the occurrences
5408
03:19:09,279 --> 03:19:11,840
of each type
5409
03:19:11,840 --> 03:19:13,600
uh in there right so we have pen and
5410
03:19:13,600 --> 03:19:15,279
sisters
5411
03:19:15,279 --> 03:19:17,040
and we also assume we actually don't
5412
03:19:17,040 --> 03:19:19,040
know we have pen and scissors we don't
5413
03:19:19,040 --> 03:19:20,800
know how many different types we have we
5414
03:19:20,800 --> 03:19:22,960
just want to count them right so you see
5415
03:19:22,960 --> 03:19:24,080
that
5416
03:19:24,080 --> 03:19:25,840
the code below here that i'm going to
5417
03:19:25,840 --> 03:19:28,399
make doesn't assume that we know we have
5418
03:19:28,399 --> 03:19:30,399
pen and scissor and
5419
03:19:30,399 --> 03:19:32,640
that's kind of the neat nice thing about
5420
03:19:32,640 --> 03:19:34,800
these dictionaries how flexible they are
5421
03:19:34,800 --> 03:19:35,920
right
5422
03:19:35,920 --> 03:19:38,160
so let's just make a dictionary called
5423
03:19:38,160 --> 03:19:40,080
count
5424
03:19:40,080 --> 03:19:42,239
and have it empty so this dictionary is
5425
03:19:42,239 --> 03:19:44,479
just empty right
5426
03:19:44,479 --> 03:19:47,200
and then we take four item in items
5427
03:19:47,200 --> 03:19:48,319
right
5428
03:19:48,319 --> 03:19:52,160
so remember this for loop here will
5429
03:19:52,160 --> 03:19:55,200
will iterate over the items in our list
5430
03:19:55,200 --> 03:19:59,359
and so far we have made no assumption of
5431
03:19:59,359 --> 03:20:02,080
how many different types or items we
5432
03:20:02,080 --> 03:20:03,600
have in our
5433
03:20:03,600 --> 03:20:05,439
items how many different items we have
5434
03:20:05,439 --> 03:20:07,279
in our items we don't know we only have
5435
03:20:07,279 --> 03:20:09,200
pen and scissors right
5436
03:20:09,200 --> 03:20:12,080
so what can we do so we count
5437
03:20:12,080 --> 03:20:14,000
and now we actually put the item as a
5438
03:20:14,000 --> 03:20:16,640
key here because we want to increase and
5439
03:20:16,640 --> 03:20:18,880
count the number of them each one of
5440
03:20:18,880 --> 03:20:20,319
them right
5441
03:20:20,319 --> 03:20:22,560
good so far so good so how can we do
5442
03:20:22,560 --> 03:20:24,720
that so we actually look at count and
5443
03:20:24,720 --> 03:20:27,279
then it has a method here
5444
03:20:27,279 --> 03:20:29,840
i thought so at least and that is called
5445
03:20:29,840 --> 03:20:30,880
get
5446
03:20:30,880 --> 03:20:33,760
so what does get do
5447
03:20:33,760 --> 03:20:35,920
and what does get do
5448
03:20:35,920 --> 03:20:38,000
it doesn't want to help me the automatic
5449
03:20:38,000 --> 03:20:39,920
help here
5450
03:20:39,920 --> 03:20:43,120
well for some reason
5451
03:20:43,120 --> 03:20:45,359
it's not active right now
5452
03:20:45,359 --> 03:20:47,120
i actually don't know why it doesn't get
5453
03:20:47,120 --> 03:20:48,960
the help
5454
03:20:48,960 --> 03:20:51,439
book up here never mind i can't help
5455
03:20:51,439 --> 03:20:53,600
help you then but what you can do is
5456
03:20:53,600 --> 03:20:55,920
look up the item that we're having and
5457
03:20:55,920 --> 03:20:58,399
then we can put a default value so that
5458
03:20:58,399 --> 03:21:00,560
means actually what this get does is it
5459
03:21:00,560 --> 03:21:02,479
looks up item i
5460
03:21:02,479 --> 03:21:06,080
item in a key in this count here and if
5461
03:21:06,080 --> 03:21:09,520
it doesn't exist it will return zero
5462
03:21:09,520 --> 03:21:11,040
this is this is great news because then
5463
03:21:11,040 --> 03:21:12,800
we can just add one to that right and
5464
03:21:12,800 --> 03:21:15,200
then we execute it because what do we
5465
03:21:15,200 --> 03:21:17,359
have now look at now
5466
03:21:17,359 --> 03:21:19,920
we have count three for pens and count
5467
03:21:19,920 --> 03:21:22,000
two for scissors right so we have one
5468
03:21:22,000 --> 03:21:24,640
two three pens and two scissors right
5469
03:21:24,640 --> 03:21:26,479
this is what this one does right it goes
5470
03:21:26,479 --> 03:21:29,200
from item and items right so first pen
5471
03:21:29,200 --> 03:21:31,120
and it puts pen in here and looks up
5472
03:21:31,120 --> 03:21:32,479
does pen exist
5473
03:21:32,479 --> 03:21:34,560
no not the first time so it puts zero
5474
03:21:34,560 --> 03:21:36,479
and then it adds one right
5475
03:21:36,479 --> 03:21:38,479
then put scissor and look scissor up
5476
03:21:38,479 --> 03:21:39,279
here
5477
03:21:39,279 --> 03:21:41,920
scissor do you exist not so far then you
5478
03:21:41,920 --> 03:21:44,000
add one then you come to the pen right
5479
03:21:44,000 --> 03:21:46,479
you look up pen you pan exist there's
5480
03:21:46,479 --> 03:21:49,200
one pen we add one to then now pen two
5481
03:21:49,200 --> 03:21:51,040
right and take this one
5482
03:21:51,040 --> 03:21:53,279
it looks pen up pen is there pen is two
5483
03:21:53,279 --> 03:21:55,279
we add one two pen is three
5484
03:21:55,279 --> 03:21:56,880
then we have scissor
5485
03:21:56,880 --> 03:21:58,160
scissors there
5486
03:21:58,160 --> 03:22:00,640
scissors one we had one scissors two
5487
03:22:00,640 --> 03:22:03,359
right you see how it goes this is really
5488
03:22:03,359 --> 03:22:05,279
really powerful this one here and i love
5489
03:22:05,279 --> 03:22:06,479
that kind of stuff
5490
03:22:06,479 --> 03:22:08,399
and we're going to use something similar
5491
03:22:08,399 --> 03:22:10,160
to it
5492
03:22:10,160 --> 03:22:12,399
in our project a question you might have
5493
03:22:12,399 --> 03:22:15,040
is like but how do you iterate over a
5494
03:22:15,040 --> 03:22:16,960
dictionary right
5495
03:22:16,960 --> 03:22:19,600
when you do that very similar to a list
5496
03:22:19,600 --> 03:22:20,960
you just can't do it the same way
5497
03:22:20,960 --> 03:22:22,800
because you have key value pairs so
5498
03:22:22,800 --> 03:22:25,600
let's do that for key
5499
03:22:25,600 --> 03:22:28,640
key value in
5500
03:22:28,640 --> 03:22:32,640
count here you can take items
5501
03:22:32,640 --> 03:22:34,880
instead so items returns the key value
5502
03:22:34,880 --> 03:22:38,239
pairs in it so let's just show you here
5503
03:22:38,239 --> 03:22:40,880
key value here right so you see it has
5504
03:22:40,880 --> 03:22:43,680
pen and scissor key and value a similar
5505
03:22:43,680 --> 03:22:45,439
we could have done it for this car here
5506
03:22:45,439 --> 03:22:47,359
we could print that out so let's do that
5507
03:22:47,359 --> 03:22:53,600
for key value in car items
5508
03:22:53,600 --> 03:22:55,600
i forgot the colon here
5509
03:22:55,600 --> 03:22:56,960
print
5510
03:22:56,960 --> 03:22:59,760
key value right so we have the
5511
03:22:59,760 --> 03:23:02,000
here we have the brand lamborghini
5512
03:23:02,000 --> 03:23:03,520
models
5513
03:23:03,520 --> 03:23:07,439
and year 2020 right you see how it works
5514
03:23:07,439 --> 03:23:08,640
i think so
5515
03:23:08,640 --> 03:23:10,720
a final thing you often need is actually
5516
03:23:10,720 --> 03:23:14,560
the keys to get the keys out of the
5517
03:23:14,560 --> 03:23:15,279
of
5518
03:23:15,279 --> 03:23:16,960
a dictionary right so here we have the
5519
03:23:16,960 --> 03:23:20,000
brand model here as a keys and yeah the
5520
03:23:20,000 --> 03:23:21,760
other one here in account we had the pen
5521
03:23:21,760 --> 03:23:24,239
and scissors keys so how can you access
5522
03:23:24,239 --> 03:23:25,359
those well
5523
03:23:25,359 --> 03:23:28,319
well if you just say keys on it
5524
03:23:28,319 --> 03:23:29,600
what do you get you actually get a
5525
03:23:29,600 --> 03:23:31,359
keys right
5526
03:23:31,359 --> 03:23:33,520
so this is you see
5527
03:23:33,520 --> 03:23:35,680
obviously this is very close to a list
5528
03:23:35,680 --> 03:23:38,880
already but if you want it as a list
5529
03:23:38,880 --> 03:23:40,239
then you can actually just write list
5530
03:23:40,239 --> 03:23:42,720
outside and have car keys car keys
5531
03:23:42,720 --> 03:23:44,960
that's nice and you get it as a list
5532
03:23:44,960 --> 03:23:46,560
here now this is a list you can actually
5533
03:23:46,560 --> 03:23:48,880
just if you're a bit worried about it
5534
03:23:48,880 --> 03:23:50,319
you can see
5535
03:23:50,319 --> 03:23:52,720
type here and you can take this list
5536
03:23:52,720 --> 03:23:55,520
here inside here and see it is a list
5537
03:23:55,520 --> 03:23:58,319
what list does is you know it it
5538
03:23:58,319 --> 03:24:01,120
converts it to a list if possible
5539
03:24:01,120 --> 03:24:04,720
and uh similarly you could take the
5540
03:24:04,720 --> 03:24:07,359
the count up here and convert that to a
5541
03:24:07,359 --> 03:24:10,160
list right so if you wanted that list
5542
03:24:10,160 --> 03:24:13,200
count here keys right
5543
03:24:13,200 --> 03:24:15,680
so here you have this pen and scissor
5544
03:24:15,680 --> 03:24:17,439
asset list and you would need that in
5545
03:24:17,439 --> 03:24:19,120
the project so
5546
03:24:19,120 --> 03:24:20,560
but often you also need that you won't
5547
03:24:20,560 --> 03:24:22,720
just want the keys right
5548
03:24:22,720 --> 03:24:24,479
in a similar way you could iterate over
5549
03:24:24,479 --> 03:24:25,920
them but we're not going to do that in
5550
03:24:25,920 --> 03:24:28,239
this one so now you're actually ready
5551
03:24:28,239 --> 03:24:31,120
for making the project are you excited i
5552
03:24:31,120 --> 03:24:35,120
am so let's get started
5553
03:24:38,000 --> 03:24:39,439
so now we're going to use our
5554
03:24:39,439 --> 03:24:41,520
dictionaries in our project are you
5555
03:24:41,520 --> 03:24:43,439
ready i hope so
5556
03:24:43,439 --> 03:24:45,840
so the project here is actually two
5557
03:24:45,840 --> 03:24:47,840
smaller projects and one is called
5558
03:24:47,840 --> 03:24:50,479
capitals that's a small game and the
5559
03:24:50,479 --> 03:24:52,479
other one is frequency count so it's
5560
03:24:52,479 --> 03:24:55,359
more a functional way to use the
5561
03:24:55,359 --> 03:24:57,760
dictionaries which i find really nice so
5562
03:24:57,760 --> 03:24:59,439
the goal is to make a game who's called
5563
03:24:59,439 --> 03:25:01,680
a guess a capital game and the other one
5564
03:25:01,680 --> 03:25:02,399
is
5565
03:25:02,399 --> 03:25:04,000
frequency count
5566
03:25:04,000 --> 03:25:04,800
so
5567
03:25:04,800 --> 03:25:07,439
description of the guess a capital game
5568
03:25:07,439 --> 03:25:09,680
well the thing is you should use a
5569
03:25:09,680 --> 03:25:12,160
dictionary obviously this is a key thing
5570
03:25:12,160 --> 03:25:14,479
we are learning in this session here
5571
03:25:14,479 --> 03:25:15,439
right
5572
03:25:15,439 --> 03:25:18,239
to keep country capital pairs as key
5573
03:25:18,239 --> 03:25:19,840
value pairs right
5574
03:25:19,840 --> 03:25:21,760
and i just put an example down here you
5575
03:25:21,760 --> 03:25:23,279
can use whatever you want these are the
5576
03:25:23,279 --> 03:25:25,200
capitals i managed to figure out the
5577
03:25:25,200 --> 03:25:27,680
rest of them i probably wouldn't
5578
03:25:27,680 --> 03:25:28,800
no
5579
03:25:28,800 --> 03:25:30,800
just kidding maybe i would know one more
5580
03:25:30,800 --> 03:25:31,680
right
5581
03:25:31,680 --> 03:25:33,680
and then prompt the users three times
5582
03:25:33,680 --> 03:25:35,600
for a capital in a country it should be
5583
03:25:35,600 --> 03:25:38,080
a random one obviously or that's up to
5584
03:25:38,080 --> 03:25:39,520
you of course
5585
03:25:39,520 --> 03:25:41,680
print the number of the correct capitals
5586
03:25:41,680 --> 03:25:43,680
after the game right feel free to print
5587
03:25:43,680 --> 03:25:46,399
whether answer is correct and what it is
5588
03:25:46,399 --> 03:25:48,840
right that was the first one right
5589
03:25:48,840 --> 03:25:52,080
so do as far as you can and i hope you
5590
03:25:52,080 --> 03:25:53,840
manage this one you should be
5591
03:25:53,840 --> 03:25:56,080
doable it takes some time obviously to
5592
03:25:56,080 --> 03:25:57,279
figure it out
5593
03:25:57,279 --> 03:25:59,359
and then go to the next one description
5594
03:25:59,359 --> 03:26:02,319
of uh frequency count right
5595
03:26:02,319 --> 03:26:04,080
prompt the user for a line of text right
5596
03:26:04,080 --> 03:26:06,000
you just need some text there right use
5597
03:26:06,000 --> 03:26:07,840
a dictionary to make a frequency count
5598
03:26:07,840 --> 03:26:11,920
off the letters print the frequencies
5599
03:26:12,160 --> 03:26:14,479
yeah
5600
03:26:14,720 --> 03:26:16,560
i would print the frequency with a loop
5601
03:26:16,560 --> 03:26:18,960
you don't have to but that's just makes
5602
03:26:18,960 --> 03:26:22,000
it looks a bit nicer i think so
5603
03:26:22,000 --> 03:26:24,319
are you ready i think so
5604
03:26:24,319 --> 03:26:26,880
i'm ready and i i'll be waiting for you
5605
03:26:26,880 --> 03:26:29,760
in the next lecture and uh hoping that
5606
03:26:29,760 --> 03:26:31,680
you spend some time trying to solve this
5607
03:26:31,680 --> 03:26:34,000
it's for your own benefit right the more
5608
03:26:34,000 --> 03:26:36,720
time you use trying to solve projects
5609
03:26:36,720 --> 03:26:38,319
the more you learn so see you in a
5610
03:26:38,319 --> 03:26:39,840
moment
5611
03:26:39,840 --> 03:26:41,680
not a short moment
5612
03:26:41,680 --> 03:26:46,359
a few moments see you bye
5613
03:26:48,640 --> 03:26:50,960
so are you ready to see some solution
5614
03:26:50,960 --> 03:26:53,760
here and uh did you try it out i hope so
5615
03:26:53,760 --> 03:26:56,319
because it's good for you to practice
5616
03:26:56,319 --> 03:26:58,080
and even if you tried and you came to
5617
03:26:58,080 --> 03:26:59,600
the solution and you see i do it
5618
03:26:59,600 --> 03:27:01,200
differently it doesn't mean that your
5619
03:27:01,200 --> 03:27:03,920
solution is wrong often people get a bit
5620
03:27:03,920 --> 03:27:05,439
confused especially in the beginning
5621
03:27:05,439 --> 03:27:07,439
it's like wow there's so many different
5622
03:27:07,439 --> 03:27:09,520
ways you can solve problems in does it
5623
03:27:09,520 --> 03:27:12,239
mean that your solution is wrong no it
5624
03:27:12,239 --> 03:27:13,840
doesn't maybe yours is actually better
5625
03:27:13,840 --> 03:27:16,720
than mine i don't know and uh
5626
03:27:16,720 --> 03:27:18,160
you always just have to keep in mind
5627
03:27:18,160 --> 03:27:20,160
that yeah as you learn along the way and
5628
03:27:20,160 --> 03:27:22,080
the more tools you get the better
5629
03:27:22,080 --> 03:27:23,920
solutions you can make right but it
5630
03:27:23,920 --> 03:27:26,640
takes practice and experience what is a
5631
03:27:26,640 --> 03:27:28,560
good solution and what is a bad solution
5632
03:27:28,560 --> 03:27:31,120
you have to look at the context right so
5633
03:27:31,120 --> 03:27:33,279
let's get started so
5634
03:27:33,279 --> 03:27:35,439
strictly speaking it doesn't say that
5635
03:27:35,439 --> 03:27:38,080
you need to take a random capital of
5636
03:27:38,080 --> 03:27:40,239
here but you just need to take
5637
03:27:40,239 --> 03:27:42,000
three of them right but i'd like to take
5638
03:27:42,000 --> 03:27:44,319
them random when you do it randomly of
5639
03:27:44,319 --> 03:27:46,160
course and when your list is so short of
5640
03:27:46,160 --> 03:27:47,840
this one you're not guaranteed you'll
5641
03:27:47,840 --> 03:27:50,880
get three different capitals and that's
5642
03:27:50,880 --> 03:27:53,359
just and compromise i'm willing to take
5643
03:27:53,359 --> 03:27:57,520
in my solution so i import random
5644
03:27:57,520 --> 03:27:59,520
because
5645
03:27:59,520 --> 03:28:01,920
i would like to take a random city
5646
03:28:01,920 --> 03:28:05,120
random country to quote question what is
5647
03:28:05,120 --> 03:28:06,479
the capital right
5648
03:28:06,479 --> 03:28:09,439
so let's try to do that so first of all
5649
03:28:09,439 --> 03:28:13,200
let's call it capitals here and take the
5650
03:28:13,200 --> 03:28:15,200
dictionary down there and then we have
5651
03:28:15,200 --> 03:28:17,200
the dictionary right let's just add
5652
03:28:17,200 --> 03:28:18,640
another cell there
5653
03:28:18,640 --> 03:28:21,680
and just to see their capitals and then
5654
03:28:21,680 --> 03:28:24,399
we have capitals here and you can see
5655
03:28:24,399 --> 03:28:26,160
how it is here right
5656
03:28:26,160 --> 03:28:27,359
perfect
5657
03:28:27,359 --> 03:28:29,600
perfect perfect perfect
5658
03:28:29,600 --> 03:28:31,040
good
5659
03:28:31,040 --> 03:28:33,840
so that was the first step right
5660
03:28:33,840 --> 03:28:36,000
and this next step is we want to take
5661
03:28:36,000 --> 03:28:38,399
keep track of the score of the person
5662
03:28:38,399 --> 03:28:40,000
right we already
5663
03:28:40,000 --> 03:28:42,399
know that that we are going to do three
5664
03:28:42,399 --> 03:28:46,160
questions from three times and
5665
03:28:46,160 --> 03:28:47,840
so we want to keep track of how many
5666
03:28:47,840 --> 03:28:50,000
answers were correct or non-correct
5667
03:28:50,000 --> 03:28:52,080
right and then we make a for loop and we
5668
03:28:52,080 --> 03:28:55,439
can make like four i in range three
5669
03:28:55,439 --> 03:28:58,960
that's three times loop
5670
03:28:58,960 --> 03:29:00,640
i can reveal that we're not going to use
5671
03:29:00,640 --> 03:29:03,840
this variable i here and often when
5672
03:29:03,840 --> 03:29:06,160
people are not using a variable but they
5673
03:29:06,160 --> 03:29:08,000
need to define a variable they use
5674
03:29:08,000 --> 03:29:10,000
underscore like that
5675
03:29:10,000 --> 03:29:12,479
it can look a bit confusing at first so
5676
03:29:12,479 --> 03:29:15,200
just leave it out there just keep it
5677
03:29:15,200 --> 03:29:18,080
simple okay so now you want to prompt
5678
03:29:18,080 --> 03:29:22,800
the user for a random
5679
03:29:22,800 --> 03:29:26,080
capital right or a random country right
5680
03:29:26,080 --> 03:29:28,640
so let's just say country here and then
5681
03:29:28,640 --> 03:29:30,800
we need a random one how did he do that
5682
03:29:30,800 --> 03:29:31,760
right
5683
03:29:31,760 --> 03:29:34,319
well we needed the keys right the keys
5684
03:29:34,319 --> 03:29:36,000
are the countries right
5685
03:29:36,000 --> 03:29:38,479
so how did they get the keys right well
5686
03:29:38,479 --> 03:29:39,680
capitals
5687
03:29:39,680 --> 03:29:42,640
keys right that would turn a
5688
03:29:42,640 --> 03:29:44,560
list right
5689
03:29:44,560 --> 03:29:46,640
we want this as a list
5690
03:29:46,640 --> 03:29:49,359
okay so far so good now this is a list
5691
03:29:49,359 --> 03:29:51,840
right remember list of the keys so this
5692
03:29:51,840 --> 03:29:53,920
list will contain of france finland
5693
03:29:53,920 --> 03:29:55,760
sweden and denmark right
5694
03:29:55,760 --> 03:29:57,520
and then we need a random one and that
5695
03:29:57,520 --> 03:30:01,040
was a random choice right
5696
03:30:01,040 --> 03:30:02,560
so now
5697
03:30:02,560 --> 03:30:04,720
let's just try to run this
5698
03:30:04,720 --> 03:30:06,319
country
5699
03:30:06,319 --> 03:30:07,680
now this one will
5700
03:30:07,680 --> 03:30:10,399
print three random capitals right so we
5701
03:30:10,399 --> 03:30:12,720
run it again it's three different
5702
03:30:12,720 --> 03:30:14,080
not three different but a different
5703
03:30:14,080 --> 03:30:15,760
order at least sweden finland denmark
5704
03:30:15,760 --> 03:30:17,200
right
5705
03:30:17,200 --> 03:30:19,040
okay so far so good
5706
03:30:19,040 --> 03:30:21,680
now we want to prompt the user what is
5707
03:30:21,680 --> 03:30:24,720
the capital of this country right so
5708
03:30:24,720 --> 03:30:26,960
the user will get
5709
03:30:26,960 --> 03:30:28,640
prompted
5710
03:30:28,640 --> 03:30:31,760
so we make a formatted string
5711
03:30:31,760 --> 03:30:33,359
what is the
5712
03:30:33,359 --> 03:30:36,640
capital of
5713
03:30:37,920 --> 03:30:40,000
country oh
5714
03:30:40,000 --> 03:30:41,680
country
5715
03:30:41,680 --> 03:30:42,960
question mark
5716
03:30:42,960 --> 03:30:44,960
space right
5717
03:30:44,960 --> 03:30:47,600
good so now we are prompted and now what
5718
03:30:47,600 --> 03:30:49,600
we want to do is check
5719
03:30:49,600 --> 03:30:53,040
if the answer is the same as the capital
5720
03:30:53,040 --> 03:30:55,359
in our game here right so how do we do
5721
03:30:55,359 --> 03:30:56,479
that right
5722
03:30:56,479 --> 03:30:58,720
so one way to do it is also remember
5723
03:30:58,720 --> 03:31:00,399
maybe there are differences in lower
5724
03:31:00,399 --> 03:31:02,720
upper case so often what i like to do is
5725
03:31:02,720 --> 03:31:05,359
just to say answer lower so we put it in
5726
03:31:05,359 --> 03:31:07,680
lowercase right you could also
5727
03:31:07,680 --> 03:31:09,520
do it differently but this is fine for
5728
03:31:09,520 --> 03:31:12,080
our purpose and now we have the country
5729
03:31:12,080 --> 03:31:14,160
we're looking for and that's a key in
5730
03:31:14,160 --> 03:31:15,040
this
5731
03:31:15,040 --> 03:31:17,960
dictionary right so capitals
5732
03:31:17,960 --> 03:31:21,359
capitals let me put the country in there
5733
03:31:21,359 --> 03:31:23,200
and then we obviously need to put that
5734
03:31:23,200 --> 03:31:25,520
to lower again right so if this is the
5735
03:31:25,520 --> 03:31:29,120
case we are correct right so print
5736
03:31:29,120 --> 03:31:30,960
correct
5737
03:31:30,960 --> 03:31:33,760
correct right
5738
03:31:33,840 --> 03:31:35,439
you can also say
5739
03:31:35,439 --> 03:31:38,279
correct the capital
5740
03:31:38,279 --> 03:31:41,120
capital of
5741
03:31:41,120 --> 03:31:42,960
country
5742
03:31:42,960 --> 03:31:45,120
is
5743
03:31:45,120 --> 03:31:47,840
we can just say answer
5744
03:31:47,840 --> 03:31:49,840
or we put
5745
03:31:49,840 --> 03:31:51,520
country
5746
03:31:51,520 --> 03:31:52,960
uh
5747
03:31:52,960 --> 03:31:54,560
that was not correct
5748
03:31:54,560 --> 03:31:56,000
capitals
5749
03:31:56,000 --> 03:31:58,560
country here right
5750
03:31:58,560 --> 03:32:00,880
exclamation mark no exclamation mark
5751
03:32:00,880 --> 03:32:03,520
here good and then we need one more
5752
03:32:03,520 --> 03:32:05,920
thing here right the score
5753
03:32:05,920 --> 03:32:09,040
equals score plus one right
5754
03:32:09,040 --> 03:32:10,640
and then we have the else statement and
5755
03:32:10,640 --> 03:32:12,560
then it's when it's incorrect right
5756
03:32:12,560 --> 03:32:13,920
print
5757
03:32:13,920 --> 03:32:16,160
in correct
5758
03:32:16,160 --> 03:32:18,640
the we can actually just copy the same
5759
03:32:18,640 --> 03:32:21,200
thing here and write the
5760
03:32:21,200 --> 03:32:23,439
this one here
5761
03:32:23,439 --> 03:32:24,479
right
5762
03:32:24,479 --> 03:32:26,560
then we have it again here right
5763
03:32:26,560 --> 03:32:28,000
and we needed to remember these should
5764
03:32:28,000 --> 03:32:29,840
be formatted strings
5765
03:32:29,840 --> 03:32:33,359
obviously thank you for reminding me
5766
03:32:33,359 --> 03:32:34,319
good
5767
03:32:34,319 --> 03:32:37,600
so this is the three times we're asking
5768
03:32:37,600 --> 03:32:38,800
we have the
5769
03:32:38,800 --> 03:32:41,359
for loop here and we ask take a random
5770
03:32:41,359 --> 03:32:44,319
country we ask for the country
5771
03:32:44,319 --> 03:32:46,399
we check if the answer is the correct
5772
03:32:46,399 --> 03:32:48,399
one if it's correct we write it's
5773
03:32:48,399 --> 03:32:50,479
correct and we add one to the score if
5774
03:32:50,479 --> 03:32:52,239
it's incorrect we write it's incorrect
5775
03:32:52,239 --> 03:32:56,080
and write the r write the right answer
5776
03:32:56,080 --> 03:32:59,760
and in the end let's just say print
5777
03:32:59,760 --> 03:33:00,880
your
5778
03:33:00,880 --> 03:33:03,040
score
5779
03:33:03,040 --> 03:33:05,200
we can just add it here format the
5780
03:33:05,200 --> 03:33:07,359
string score
5781
03:33:07,359 --> 03:33:09,279
and then we need to remember formatted
5782
03:33:09,279 --> 03:33:11,840
here right so are you ready do you want
5783
03:33:11,840 --> 03:33:15,200
to try i want to try oops
5784
03:33:15,200 --> 03:33:16,880
i did something wrong
5785
03:33:16,880 --> 03:33:19,040
capitals is not defined
5786
03:33:19,040 --> 03:33:22,479
did i write a wrong cap p
5787
03:33:22,479 --> 03:33:24,080
tolls here right so it didn't matter i
5788
03:33:24,080 --> 03:33:26,479
was typing enter twice that's why also
5789
03:33:26,479 --> 03:33:28,560
so fast right ko
5790
03:33:28,560 --> 03:33:31,200
ko ben hagen
5791
03:33:31,200 --> 03:33:34,960
yes i got this one stockholm
5792
03:33:34,960 --> 03:33:37,120
yes i got this wrong
5793
03:33:37,120 --> 03:33:38,239
paris
5794
03:33:38,239 --> 03:33:39,520
boom
5795
03:33:39,520 --> 03:33:41,600
so i got to score three can you do
5796
03:33:41,600 --> 03:33:43,680
better than me i think so because these
5797
03:33:43,680 --> 03:33:45,439
are also easy these are the three four
5798
03:33:45,439 --> 03:33:47,600
capitals i'm know by heart the rest of
5799
03:33:47,600 --> 03:33:49,439
the world i have no idea
5800
03:33:49,439 --> 03:33:52,000
perfect maybe a few more capitals i
5801
03:33:52,000 --> 03:33:54,160
don't know but as you see this seems to
5802
03:33:54,160 --> 03:33:56,000
work let's also just ensure if you
5803
03:33:56,000 --> 03:33:58,640
answer wrong that it works sweden
5804
03:33:58,640 --> 03:34:00,479
say copenhagen
5805
03:34:00,479 --> 03:34:02,000
that's incorrect
5806
03:34:02,000 --> 03:34:03,520
oh sweden
5807
03:34:03,520 --> 03:34:06,080
it's stockholm so then that's one is
5808
03:34:06,080 --> 03:34:07,600
correct and
5809
03:34:07,600 --> 03:34:10,560
denmark let's just call it helsinki and
5810
03:34:10,560 --> 03:34:11,920
it's incorrect right so you could score
5811
03:34:11,920 --> 03:34:14,479
one right you had one right answer there
5812
03:34:14,479 --> 03:34:15,279
right
5813
03:34:15,279 --> 03:34:16,560
because uh
5814
03:34:16,560 --> 03:34:18,960
the capital of sweden here was stockholm
5815
03:34:18,960 --> 03:34:20,800
i wrote copenhagen the capital of sweden
5816
03:34:20,800 --> 03:34:22,720
was stockholm i wrote stockholm one
5817
03:34:22,720 --> 03:34:24,800
correct capital denmark is copenhagen
5818
03:34:24,800 --> 03:34:26,080
and i wrote
5819
03:34:26,080 --> 03:34:27,760
helsinki right
5820
03:34:27,760 --> 03:34:30,479
perfect so it seems to work so far so
5821
03:34:30,479 --> 03:34:32,399
good are you ready for the next one so
5822
03:34:32,399 --> 03:34:34,800
now for the frequency count let's try to
5823
03:34:34,800 --> 03:34:36,960
look at this one here right so let's
5824
03:34:36,960 --> 03:34:38,880
recall it frequency count prompt the
5825
03:34:38,880 --> 03:34:41,040
user for a line of text use a dictionary
5826
03:34:41,040 --> 03:34:42,800
to make frequency count of the letters
5827
03:34:42,800 --> 03:34:45,600
right so how many times does each letter
5828
03:34:45,600 --> 03:34:48,239
occur right so printer frequencies let's
5829
03:34:48,239 --> 03:34:50,479
get started right so
5830
03:34:50,479 --> 03:34:52,080
we need to input the line of text so
5831
03:34:52,080 --> 03:34:54,319
let's just call it text
5832
03:34:54,319 --> 03:34:57,520
and we use input here and uh just write
5833
03:34:57,520 --> 03:35:00,319
a line of text
5834
03:35:00,319 --> 03:35:01,520
right
5835
03:35:01,520 --> 03:35:03,359
and uh remember how it was right you
5836
03:35:03,359 --> 03:35:05,279
created the dictionary let's just call
5837
03:35:05,279 --> 03:35:08,720
it frequency here right or frick
5838
03:35:08,720 --> 03:35:09,760
and
5839
03:35:09,760 --> 03:35:12,640
then we need to iterate over it right
5840
03:35:12,640 --> 03:35:15,040
and remember the iteration here we need
5841
03:35:15,040 --> 03:35:18,080
to iterate over text which is a string
5842
03:35:18,080 --> 03:35:20,479
but you can do that easily with a for
5843
03:35:20,479 --> 03:35:23,840
loop right so that's 4c in text and what
5844
03:35:23,840 --> 03:35:26,399
c does is it's assigned to character by
5845
03:35:26,399 --> 03:35:28,160
character or letter by letter and this
5846
03:35:28,160 --> 03:35:29,920
is actually what we want right
5847
03:35:29,920 --> 03:35:33,040
so what we can do now is actually
5848
03:35:33,040 --> 03:35:35,680
add this c here to it and then we take
5849
03:35:35,680 --> 03:35:37,680
the freak and get right remember this
5850
03:35:37,680 --> 03:35:40,160
get method there it will look up c and
5851
03:35:40,160 --> 03:35:42,560
return 0 if it's not there already and
5852
03:35:42,560 --> 03:35:44,239
then we add 1 to that
5853
03:35:44,239 --> 03:35:46,479
so that's actually it
5854
03:35:46,479 --> 03:35:49,680
but we also want to print it out so
5855
03:35:49,680 --> 03:35:51,600
one way to do that is actually to print
5856
03:35:51,600 --> 03:35:53,760
over the frequencies just print the
5857
03:35:53,760 --> 03:35:57,279
frequencies out like this print frag
5858
03:35:57,279 --> 03:35:58,560
let's just do that with start and then
5859
03:35:58,560 --> 03:36:01,279
we make it a bit prettier afterwards so
5860
03:36:01,279 --> 03:36:04,640
this is my text
5861
03:36:04,640 --> 03:36:07,840
and you see here this is okay well this
5862
03:36:07,840 --> 03:36:10,160
is a bad solution but i will like to
5863
03:36:10,160 --> 03:36:12,239
print it line by line right
5864
03:36:12,239 --> 03:36:14,640
and maybe also another thing that i'm
5865
03:36:14,640 --> 03:36:17,200
looking at is i have t and capital t
5866
03:36:17,200 --> 03:36:18,720
right maybe i just want to make them
5867
03:36:18,720 --> 03:36:19,760
lower
5868
03:36:19,760 --> 03:36:21,279
actually i could do that immediately
5869
03:36:21,279 --> 03:36:25,279
right to set c is equal to lower right
5870
03:36:25,279 --> 03:36:27,120
and why do i want to do it here instead
5871
03:36:27,120 --> 03:36:29,279
of just adding here because if i add it
5872
03:36:29,279 --> 03:36:31,760
here i also have to add it here right so
5873
03:36:31,760 --> 03:36:34,319
i just change c to be in lower case
5874
03:36:34,319 --> 03:36:38,560
right so if i do it now this is my text
5875
03:36:38,560 --> 03:36:41,520
then i get the three t's here instead of
5876
03:36:41,520 --> 03:36:43,279
having capital and
5877
03:36:43,279 --> 03:36:45,439
lowercase frequencies
5878
03:36:45,439 --> 03:36:48,560
but now to the last part so how did i
5879
03:36:48,560 --> 03:36:52,000
make a for loop over a dictionary right
5880
03:36:52,000 --> 03:36:53,040
remember
5881
03:36:53,040 --> 03:36:56,239
for key value
5882
03:36:56,239 --> 03:36:57,279
in
5883
03:36:57,279 --> 03:36:58,160
freck
5884
03:36:58,160 --> 03:36:59,680
and then we just needed to take the
5885
03:36:59,680 --> 03:37:02,479
items right remember
5886
03:37:02,479 --> 03:37:04,000
then we can print and let's just print
5887
03:37:04,000 --> 03:37:05,680
it formatted here
5888
03:37:05,680 --> 03:37:07,279
and we take
5889
03:37:07,279 --> 03:37:08,160
key
5890
03:37:08,160 --> 03:37:10,399
colon
5891
03:37:10,399 --> 03:37:12,080
value right
5892
03:37:12,080 --> 03:37:15,920
perfect so this is my text and then you
5893
03:37:15,920 --> 03:37:17,760
see it you have it here i think it's a
5894
03:37:17,760 --> 03:37:19,600
bit nicer like this right
5895
03:37:19,600 --> 03:37:20,960
right
5896
03:37:20,960 --> 03:37:21,840
and
5897
03:37:21,840 --> 03:37:23,840
yeah you might see that this is not
5898
03:37:23,840 --> 03:37:25,439
ordered and
5899
03:37:25,439 --> 03:37:27,439
this one is because of its space but you
5900
03:37:27,439 --> 03:37:29,200
can actually order them afterwards if
5901
03:37:29,200 --> 03:37:31,040
you want but we're not going to go into
5902
03:37:31,040 --> 03:37:33,120
that in this one here this is exactly
5903
03:37:33,120 --> 03:37:35,200
fine for our purpose right so you see
5904
03:37:35,200 --> 03:37:37,520
now you actually can count things and
5905
03:37:37,520 --> 03:37:39,120
again i want to emphasize that the
5906
03:37:39,120 --> 03:37:40,880
dictionary here
5907
03:37:40,880 --> 03:37:43,040
before we start i didn't know what are
5908
03:37:43,040 --> 03:37:45,600
the letters in the string we wrote this
5909
03:37:45,600 --> 03:37:47,359
is my text right it doesn't know
5910
03:37:47,359 --> 03:37:48,960
anything about it you just add them
5911
03:37:48,960 --> 03:37:50,800
dynamically along the way and that's
5912
03:37:50,800 --> 03:37:54,000
really nice this frequency get is really
5913
03:37:54,000 --> 03:37:55,120
nice as well
5914
03:37:55,120 --> 03:37:58,000
so you enjoyed it i hope so because this
5915
03:37:58,000 --> 03:37:59,600
is really really amazing and powerful
5916
03:37:59,600 --> 03:38:00,479
stuff
5917
03:38:00,479 --> 03:38:01,680
so
5918
03:38:01,680 --> 03:38:04,239
see you in the next one i think yes the
5919
03:38:04,239 --> 03:38:06,239
next one we're going to learn about csv
5920
03:38:06,239 --> 03:38:09,840
files which are ideal to write read into
5921
03:38:09,840 --> 03:38:11,200
dictionaries like this one it's going to
5922
03:38:11,200 --> 03:38:14,560
be amazing see you in a moment
5923
03:38:17,279 --> 03:38:19,279
in this one it's going to be amazing
5924
03:38:19,279 --> 03:38:22,000
because we are going to learn about csv
5925
03:38:22,000 --> 03:38:24,640
files you might say c is what
5926
03:38:24,640 --> 03:38:28,399
comma separated values files right and
5927
03:38:28,399 --> 03:38:31,439
what are they well it's basically a
5928
03:38:31,439 --> 03:38:34,239
great way to store data in a structured
5929
03:38:34,239 --> 03:38:36,800
way so let's just dive into jupiter
5930
03:38:36,800 --> 03:38:38,399
notebook and actually try to find one
5931
03:38:38,399 --> 03:38:40,880
and read one and learn your magic about
5932
03:38:40,880 --> 03:38:43,520
them right so let's get started
5933
03:38:43,520 --> 03:38:46,000
so we're here inside jupiter notebook
5934
03:38:46,000 --> 03:38:48,399
here right and the goal is actually just
5935
03:38:48,399 --> 03:38:51,439
to learn to read and process csv files
5936
03:38:51,439 --> 03:38:52,800
because we're going to use that in our
5937
03:38:52,800 --> 03:38:54,560
project and again the best way to learn
5938
03:38:54,560 --> 03:38:57,600
is to make projects so let's get started
5939
03:38:57,600 --> 03:38:58,399
so
5940
03:38:58,399 --> 03:39:00,160
i just want to jump over to here your
5941
03:39:00,160 --> 03:39:01,760
file structure here because here you can
5942
03:39:01,760 --> 03:39:03,760
see there are some files and the first
5943
03:39:03,760 --> 03:39:05,439
one we're going to dive into is this a
5944
03:39:05,439 --> 03:39:07,760
name csv right you see all of them here
5945
03:39:07,760 --> 03:39:09,760
are called csv files we're going to use
5946
03:39:09,760 --> 03:39:11,359
them along the
5947
03:39:11,359 --> 03:39:13,439
projects along the way here in this
5948
03:39:13,439 --> 03:39:14,880
course there but the first one is this
5949
03:39:14,880 --> 03:39:18,399
one here it's quite a simple one right
5950
03:39:18,399 --> 03:39:20,640
so what do we have on the first line is
5951
03:39:20,640 --> 03:39:22,399
a bit different from the rest of them
5952
03:39:22,399 --> 03:39:25,600
right so the first line contains the
5953
03:39:25,600 --> 03:39:29,040
names of the columns so they're comma
5954
03:39:29,040 --> 03:39:30,880
separated that means that for every
5955
03:39:30,880 --> 03:39:34,080
comma it encounters it's a new column of
5956
03:39:34,080 --> 03:39:37,439
data right so here we have first name
5957
03:39:37,439 --> 03:39:39,520
last name and age so this is a simple
5958
03:39:39,520 --> 03:39:41,760
one that just keeps track of people's
5959
03:39:41,760 --> 03:39:44,720
first name last name and age right so
5960
03:39:44,720 --> 03:39:47,359
the lines below are those with the
5961
03:39:47,359 --> 03:39:49,840
actual data on them that correspond to
5962
03:39:49,840 --> 03:39:51,359
them right so if you take the first line
5963
03:39:51,359 --> 03:39:54,319
airline two we have connor so connor is
5964
03:39:54,319 --> 03:39:57,359
the first name right ward is the last
5965
03:39:57,359 --> 03:39:59,920
name and the age is 15 right
5966
03:39:59,920 --> 03:40:01,040
and this
5967
03:40:01,040 --> 03:40:03,199
third line here we have another
5968
03:40:03,199 --> 03:40:05,520
record in it like remember we called
5969
03:40:05,520 --> 03:40:07,680
record when we talked about dictionaries
5970
03:40:07,680 --> 03:40:10,160
uh then the first name is rose the last
5971
03:40:10,160 --> 03:40:13,680
name is peterson and the age is 18. then
5972
03:40:13,680 --> 03:40:15,279
we have paul
5973
03:40:15,279 --> 03:40:17,120
cox
5974
03:40:17,120 --> 03:40:20,560
12 hana higgs 10 right
5975
03:40:20,560 --> 03:40:23,359
so this is a very short and very simple
5976
03:40:23,359 --> 03:40:25,760
csv file but it's just to get you
5977
03:40:25,760 --> 03:40:28,640
started and familiar with them right
5978
03:40:28,640 --> 03:40:31,120
so how do you do that right how do you
5979
03:40:31,120 --> 03:40:34,160
read these csv files how do you process
5980
03:40:34,160 --> 03:40:35,199
them right
5981
03:40:35,199 --> 03:40:38,160
well you import a library that does
5982
03:40:38,160 --> 03:40:39,840
basically most of the things for you
5983
03:40:39,840 --> 03:40:41,840
that's why we love python because it has
5984
03:40:41,840 --> 03:40:44,160
all these powerful libraries that does
5985
03:40:44,160 --> 03:40:45,600
everything for us
5986
03:40:45,600 --> 03:40:47,120
in
5987
03:40:47,120 --> 03:40:49,840
port csv it's called csv isn't that
5988
03:40:49,840 --> 03:40:52,239
beautiful it reads csv files and the
5989
03:40:52,239 --> 03:40:54,560
library is called csv so let's load that
5990
03:40:54,560 --> 03:40:56,080
immediately
5991
03:40:56,080 --> 03:40:57,040
so
5992
03:40:57,040 --> 03:40:59,279
now we have to work with files and
5993
03:40:59,279 --> 03:41:01,439
there's something called file pointers
5994
03:41:01,439 --> 03:41:04,000
and so on like that but
5995
03:41:04,000 --> 03:41:06,560
honestly you don't really have to figure
5996
03:41:06,560 --> 03:41:08,960
that much out just you need some simple
5997
03:41:08,960 --> 03:41:11,359
syntax there are different ways to do it
5998
03:41:11,359 --> 03:41:12,720
uh
5999
03:41:12,720 --> 03:41:14,720
i do it in two different ways i'm just
6000
03:41:14,720 --> 03:41:16,880
going to show you i think this is the
6001
03:41:16,880 --> 03:41:19,520
most preferred way because then it keeps
6002
03:41:19,520 --> 03:41:22,080
a less mess behind you
6003
03:41:22,080 --> 03:41:24,560
so it's called with first and then we
6004
03:41:24,560 --> 03:41:27,920
open and this open here what it does is
6005
03:41:27,920 --> 03:41:30,640
it opens the
6006
03:41:30,640 --> 03:41:32,560
file pointer right so this opens a file
6007
03:41:32,560 --> 03:41:35,040
and returns a stream here right
6008
03:41:35,040 --> 03:41:36,960
so this is what i talked about
6009
03:41:36,960 --> 03:41:38,160
the file
6010
03:41:38,160 --> 03:41:40,080
pointer right so here we have to write
6011
03:41:40,080 --> 03:41:43,520
the file name so remember it's on the
6012
03:41:43,520 --> 03:41:45,680
files and it was called
6013
03:41:45,680 --> 03:41:50,160
name it was called name records
6014
03:41:50,399 --> 03:41:53,680
csv csv right this is a file and another
6015
03:41:53,680 --> 03:41:55,680
thing we often need to tell these file
6016
03:41:55,680 --> 03:41:57,760
pointers it's whether we want to read or
6017
03:41:57,760 --> 03:41:59,520
write to them in this case we only want
6018
03:41:59,520 --> 03:42:01,279
to read
6019
03:42:01,279 --> 03:42:02,319
and
6020
03:42:02,319 --> 03:42:03,279
now
6021
03:42:03,279 --> 03:42:05,680
here's the syntax because we need to
6022
03:42:05,680 --> 03:42:06,960
simp
6023
03:42:06,960 --> 03:42:09,840
we need somehow to get this file pointer
6024
03:42:09,840 --> 03:42:11,840
this is like a pointer pointing at the
6025
03:42:11,840 --> 03:42:13,760
file that file system and let's just
6026
03:42:13,760 --> 03:42:16,560
call it f here right so
6027
03:42:16,560 --> 03:42:19,279
in the code which is indented after this
6028
03:42:19,279 --> 03:42:21,840
with there it is everywhere we have
6029
03:42:21,840 --> 03:42:24,160
access to this file pointer because
6030
03:42:24,160 --> 03:42:26,479
after it's not indented anymore it's we
6031
03:42:26,479 --> 03:42:28,479
don't have access it will close a file
6032
03:42:28,479 --> 03:42:30,960
again and while with this mess of
6033
03:42:30,960 --> 03:42:33,359
opening and closing files it becomes to
6034
03:42:33,359 --> 03:42:34,800
keep track you don't want to have
6035
03:42:34,800 --> 03:42:37,920
multiple people adding as the same file
6036
03:42:37,920 --> 03:42:40,319
because it gets a mess so you need to
6037
03:42:40,319 --> 03:42:42,160
take
6038
03:42:42,160 --> 03:42:44,319
access to a file and make sure you're
6039
03:42:44,319 --> 03:42:46,560
the only one writing to it or reading to
6040
03:42:46,560 --> 03:42:48,160
it currently right that's why you have
6041
03:42:48,160 --> 03:42:50,640
this open and close with a file pointer
6042
03:42:50,640 --> 03:42:52,880
to make sure it's only one people person
6043
03:42:52,880 --> 03:42:54,640
doing it at the time
6044
03:42:54,640 --> 03:42:56,000
if you are in a file system with
6045
03:42:56,000 --> 03:42:58,080
multiple users
6046
03:42:58,080 --> 03:43:01,760
good now we want to have the csv reader
6047
03:43:01,760 --> 03:43:03,760
what is that csv
6048
03:43:03,760 --> 03:43:04,479
well
6049
03:43:04,479 --> 03:43:07,600
csv here has a lot of
6050
03:43:07,600 --> 03:43:09,439
a lot of things here right you see here
6051
03:43:09,439 --> 03:43:11,120
a lot of things here what we are going
6052
03:43:11,120 --> 03:43:14,080
to do is called the dict reader right
6053
03:43:14,080 --> 03:43:17,439
it's probably as you can guess it
6054
03:43:17,439 --> 03:43:19,439
let's see what it says here
6055
03:43:19,439 --> 03:43:21,600
it doesn't say much here actually but it
6056
03:43:21,600 --> 03:43:24,319
is a dictionary reader obviously and we
6057
03:43:24,319 --> 03:43:25,920
just learned about dictionaries and i
6058
03:43:25,920 --> 03:43:27,760
just told you that records are awesome
6059
03:43:27,760 --> 03:43:30,800
for dictionaries so let's try to read
6060
03:43:30,800 --> 03:43:32,960
the data here
6061
03:43:32,960 --> 03:43:34,960
and all it takes is this file pointer
6062
03:43:34,960 --> 03:43:35,840
here
6063
03:43:35,840 --> 03:43:36,880
perfect
6064
03:43:36,880 --> 03:43:39,199
and what you now need is actually the
6065
03:43:39,199 --> 03:43:40,720
name records
6066
03:43:40,720 --> 03:43:43,840
because this is returning a csv writer
6067
03:43:43,840 --> 03:43:46,319
reader and now we need to convert that
6068
03:43:46,319 --> 03:43:49,120
to a list of
6069
03:43:49,120 --> 03:43:50,640
list of dictionaries you'll see in a
6070
03:43:50,640 --> 03:43:51,760
moment
6071
03:43:51,760 --> 03:43:52,560
name
6072
03:43:52,560 --> 03:43:54,560
records
6073
03:43:54,560 --> 03:43:56,800
and all it does is actually we just
6074
03:43:56,800 --> 03:43:59,840
convert this csv reader
6075
03:43:59,840 --> 03:44:01,600
to a list
6076
03:44:01,600 --> 03:44:03,040
so let's do that
6077
03:44:03,040 --> 03:44:05,680
now we have name records down here and
6078
03:44:05,680 --> 03:44:08,479
you see here this is a list
6079
03:44:08,479 --> 03:44:10,720
where normally you notice but this is a
6080
03:44:10,720 --> 03:44:12,560
list right the square brackets here and
6081
03:44:12,560 --> 03:44:14,000
the square brackets here means it's a
6082
03:44:14,000 --> 03:44:17,040
list and each item of the list is a
6083
03:44:17,040 --> 03:44:19,680
dictionary each dictionary has the
6084
03:44:19,680 --> 03:44:21,840
column name for each of them right first
6085
03:44:21,840 --> 03:44:26,479
name connor last name ward age 15.
6086
03:44:26,479 --> 03:44:28,720
just like in this one here what i said
6087
03:44:28,720 --> 03:44:31,760
first name connor last name word age 15
6088
03:44:31,760 --> 03:44:33,920
right you see
6089
03:44:33,920 --> 03:44:36,160
and so it goes on for each of the lines
6090
03:44:36,160 --> 03:44:36,960
right
6091
03:44:36,960 --> 03:44:40,479
so we already know in this we can access
6092
03:44:40,479 --> 03:44:42,800
the first one like this here and so on
6093
03:44:42,800 --> 03:44:44,800
so forth right
6094
03:44:44,800 --> 03:44:45,680
but
6095
03:44:45,680 --> 03:44:47,760
for our case here
6096
03:44:47,760 --> 03:44:48,720
yeah and
6097
03:44:48,720 --> 03:44:50,880
just one more step here
6098
03:44:50,880 --> 03:44:53,199
name records you could obviously also
6099
03:44:53,199 --> 03:44:55,600
access the dictionary directly here
6100
03:44:55,600 --> 03:44:57,760
because the first one here it says we
6101
03:44:57,760 --> 03:44:59,840
have the first item of the list and now
6102
03:44:59,840 --> 03:45:01,600
we want to access something in the
6103
03:45:01,600 --> 03:45:03,359
dictionary you can do that directly as
6104
03:45:03,359 --> 03:45:05,680
well like this this is again really
6105
03:45:05,680 --> 03:45:07,439
really nice syntax right then you get
6106
03:45:07,439 --> 03:45:09,680
corner obviously right so this is how
6107
03:45:09,680 --> 03:45:11,920
you can use it and obviously you could
6108
03:45:11,920 --> 03:45:13,040
take
6109
03:45:13,040 --> 03:45:14,239
another
6110
03:45:14,239 --> 03:45:15,600
list
6111
03:45:15,600 --> 03:45:17,760
item like the third one here and you'll
6112
03:45:17,760 --> 03:45:20,239
get hana the last one right because the
6113
03:45:20,239 --> 03:45:22,000
third one is the last one right
6114
03:45:22,000 --> 03:45:23,600
zero one two three
6115
03:45:23,600 --> 03:45:24,640
right
6116
03:45:24,640 --> 03:45:28,080
perfect right isn't that amazing i think
6117
03:45:28,080 --> 03:45:29,359
so
6118
03:45:29,359 --> 03:45:30,960
good so
6119
03:45:30,960 --> 03:45:34,160
how do you do that right so how do you
6120
03:45:34,160 --> 03:45:36,000
print out
6121
03:45:36,000 --> 03:45:39,120
all these things here
6122
03:45:39,120 --> 03:45:41,359
well let's try to make a for loop here
6123
03:45:41,359 --> 03:45:43,199
now we know the syntax of this one here
6124
03:45:43,199 --> 03:45:44,880
and we in this case we just play that we
6125
03:45:44,880 --> 03:45:47,040
know all the key value
6126
03:45:47,040 --> 03:45:49,600
keys in it and we're all only interested
6127
03:45:49,600 --> 03:45:51,439
in showing the key
6128
03:45:51,439 --> 03:45:53,840
uh using the keys to print something out
6129
03:45:53,840 --> 03:45:57,040
so let's do that so for
6130
03:45:57,040 --> 03:45:59,600
record in name
6131
03:45:59,600 --> 03:46:01,199
records
6132
03:46:01,199 --> 03:46:02,880
records
6133
03:46:02,880 --> 03:46:04,560
what do we do this is a list again
6134
03:46:04,560 --> 03:46:06,640
remember now record what is record
6135
03:46:06,640 --> 03:46:09,279
record is a dictionary right because an
6136
03:46:09,279 --> 03:46:12,560
item in the list is a dictionary right
6137
03:46:12,560 --> 03:46:14,880
so what can we do we can print format it
6138
03:46:14,880 --> 03:46:17,040
here let's just do that
6139
03:46:17,040 --> 03:46:17,760
and
6140
03:46:17,760 --> 03:46:20,800
let's just say we take record and then
6141
03:46:20,800 --> 03:46:22,800
we take first
6142
03:46:22,800 --> 03:46:24,319
first
6143
03:46:24,319 --> 03:46:24,680
name
6144
03:46:24,680 --> 03:46:25,920
[Music]
6145
03:46:25,920 --> 03:46:28,319
and then we take
6146
03:46:28,319 --> 03:46:31,840
also record
6147
03:46:32,160 --> 03:46:34,080
oops square ones
6148
03:46:34,080 --> 03:46:35,520
last
6149
03:46:35,520 --> 03:46:37,120
name
6150
03:46:37,120 --> 03:46:39,199
and let's just say we just put it here
6151
03:46:39,199 --> 03:46:41,279
the h here
6152
03:46:41,279 --> 03:46:43,920
record
6153
03:46:44,880 --> 03:46:47,120
age right this is all we want to do
6154
03:46:47,120 --> 03:46:49,680
right so see here what it does right so
6155
03:46:49,680 --> 03:46:52,080
it prints first name connor
6156
03:46:52,080 --> 03:46:53,840
last name ward
6157
03:46:53,840 --> 03:46:56,560
colon age 15 right so we have connor
6158
03:46:56,560 --> 03:47:00,800
ward 15 rose peterson 18 paul cox 12
6159
03:47:00,800 --> 03:47:03,680
hannah hicks 10 right so this is exactly
6160
03:47:03,680 --> 03:47:06,239
the data we had here and you see how
6161
03:47:06,239 --> 03:47:08,640
nice and easy it is to access it through
6162
03:47:08,640 --> 03:47:10,640
dictionaries right
6163
03:47:10,640 --> 03:47:11,760
amazing
6164
03:47:11,760 --> 03:47:13,279
this is actually all you need to get
6165
03:47:13,279 --> 03:47:16,239
started using csv files and csv files is
6166
03:47:16,239 --> 03:47:19,520
an amazing way to work with data
6167
03:47:19,520 --> 03:47:21,520
so are you ready for the project it's
6168
03:47:21,520 --> 03:47:23,040
going to be
6169
03:47:23,040 --> 03:47:25,439
actually quite awesome i think so yeah
6170
03:47:25,439 --> 03:47:27,760
we're going to read some nice files csv
6171
03:47:27,760 --> 03:47:28,640
files
6172
03:47:28,640 --> 03:47:30,720
and work with the data in a bit more
6173
03:47:30,720 --> 03:47:32,319
advanced way in this simple way here and
6174
03:47:32,319 --> 03:47:33,520
it's going to be amazing see you in a
6175
03:47:33,520 --> 03:47:35,840
moment
6176
03:47:38,960 --> 03:47:41,600
are you ready i hope you are because i'm
6177
03:47:41,600 --> 03:47:43,520
really excited about this one
6178
03:47:43,520 --> 03:47:46,560
so in this one we're gonna read csv
6179
03:47:46,560 --> 03:47:49,279
files and process data right and we're
6180
03:47:49,279 --> 03:47:52,160
gonna process a massive one in this one
6181
03:47:52,160 --> 03:47:53,920
or at least for our
6182
03:47:53,920 --> 03:47:56,560
our stage of our learning journey it's a
6183
03:47:56,560 --> 03:47:58,960
massive csv file okay
6184
03:47:58,960 --> 03:48:01,920
good so let's jump into jupyter notebook
6185
03:48:01,920 --> 03:48:03,920
notebook here and see what it says so
6186
03:48:03,920 --> 03:48:06,960
the csv file we want to process is
6187
03:48:06,960 --> 03:48:10,560
having car data right we love cars
6188
03:48:10,560 --> 03:48:12,160
so the goal is to learn how to read and
6189
03:48:12,160 --> 03:48:15,920
process csv files so the
6190
03:48:15,920 --> 03:48:18,800
goal of the project is also to process
6191
03:48:18,800 --> 03:48:21,359
files cars csv we'll just look at in a
6192
03:48:21,359 --> 03:48:24,080
moment and calculate the average
6193
03:48:24,080 --> 03:48:27,600
horsepower for each car brand okay
6194
03:48:27,600 --> 03:48:31,359
let's just jump into our
6195
03:48:31,359 --> 03:48:33,680
file structure here and you see here we
6196
03:48:33,680 --> 03:48:35,840
have the files here we have this files
6197
03:48:35,840 --> 03:48:37,439
here all the
6198
03:48:37,439 --> 03:48:40,080
library files here and we click it and
6199
03:48:40,080 --> 03:48:42,319
we have cars here and then we open it
6200
03:48:42,319 --> 03:48:43,600
inside here
6201
03:48:43,600 --> 03:48:46,000
and in this case it just
6202
03:48:46,000 --> 03:48:48,560
takes a few seconds because it's quite a
6203
03:48:48,560 --> 03:48:50,319
large one and sometimes but the notebook
6204
03:48:50,319 --> 03:48:52,479
is a bit slow here it is right
6205
03:48:52,479 --> 03:48:54,479
so here we have the first line with all
6206
03:48:54,479 --> 03:48:56,800
the columns here right and then we have
6207
03:48:56,800 --> 03:48:59,359
cars for each aligned below here and as
6208
03:48:59,359 --> 03:49:01,680
you see here it's quite a big one here
6209
03:49:01,680 --> 03:49:02,960
actually
6210
03:49:02,960 --> 03:49:05,600
we actually have more than 5 000 cars
6211
03:49:05,600 --> 03:49:08,040
here right you see there are lines
6212
03:49:08,040 --> 03:49:11,359
5077 is the last line number i mean this
6213
03:49:11,359 --> 03:49:13,840
one is empty down there okay
6214
03:49:13,840 --> 03:49:16,239
so for each line we have a car
6215
03:49:16,239 --> 03:49:18,880
so what do we have about the car
6216
03:49:18,880 --> 03:49:20,399
well it says on the first line here we
6217
03:49:20,399 --> 03:49:22,720
have height and we also just notice that
6218
03:49:22,720 --> 03:49:24,960
each line is broken down
6219
03:49:24,960 --> 03:49:28,239
in approximately three lines in my case
6220
03:49:28,239 --> 03:49:29,600
if you open it it might be a different
6221
03:49:29,600 --> 03:49:31,600
breaking up because the size of the
6222
03:49:31,600 --> 03:49:34,640
screen are pretty large font here
6223
03:49:34,640 --> 03:49:36,960
so it's height length width engine
6224
03:49:36,960 --> 03:49:39,760
driveline engine type engine hybrid
6225
03:49:39,760 --> 03:49:41,680
number of forward gears
6226
03:49:41,680 --> 03:49:44,399
engine transmission fuel city
6227
03:49:44,399 --> 03:49:47,120
fuel type fuel highway classification id
6228
03:49:47,120 --> 03:49:49,040
make i just want to say that this make
6229
03:49:49,040 --> 03:49:49,920
here
6230
03:49:49,920 --> 03:49:52,560
is a car brand so i guess it's short for
6231
03:49:52,560 --> 03:49:54,319
maker or whatever
6232
03:49:54,319 --> 03:49:57,279
model year year horsepower this is one
6233
03:49:57,279 --> 03:49:59,279
last second one right we only have
6234
03:49:59,279 --> 03:50:01,279
torque afterwards so horsepower is one
6235
03:50:01,279 --> 03:50:03,279
we're looking for so if we take the
6236
03:50:03,279 --> 03:50:04,880
example of the first one here we have
6237
03:50:04,880 --> 03:50:07,040
141 141.4 blah blah blah all the way
6238
03:50:07,040 --> 03:50:08,880
down here and we see actually this is an
6239
03:50:08,880 --> 03:50:11,680
audi as it says here this is a make you
6240
03:50:11,680 --> 03:50:13,840
don't really see easily this is a make
6241
03:50:13,840 --> 03:50:14,720
but
6242
03:50:14,720 --> 03:50:16,960
i promise you it is
6243
03:50:16,960 --> 03:50:18,880
and the horsepower is the second last is
6244
03:50:18,880 --> 03:50:21,760
this one here right so this is the horse
6245
03:50:21,760 --> 03:50:24,560
power we are looking for so for audi and
6246
03:50:24,560 --> 03:50:27,040
you can see there are multiple audi's
6247
03:50:27,040 --> 03:50:28,319
down here
6248
03:50:28,319 --> 03:50:30,800
we want to collect all of these here
6249
03:50:30,800 --> 03:50:33,279
these second last values here and
6250
03:50:33,279 --> 03:50:35,840
calculate the average of that in the
6251
03:50:35,840 --> 03:50:37,600
prop project right
6252
03:50:37,600 --> 03:50:40,000
so let's go back to the project
6253
03:50:40,000 --> 03:50:42,160
so it's also broken down in in this case
6254
03:50:42,160 --> 03:50:44,560
four steps here to make it a bit easier
6255
03:50:44,560 --> 03:50:46,640
to figure out what to do right but the
6256
03:50:46,640 --> 03:50:48,800
goal should be clear we need to get for
6257
03:50:48,800 --> 03:50:51,279
each car brand so they're more than audi
6258
03:50:51,279 --> 03:50:53,920
in these 5 000 cars we collected
6259
03:50:53,920 --> 03:50:57,040
you want to collect the horsepower and
6260
03:50:57,040 --> 03:50:59,279
collect them and calculate the average
6261
03:50:59,279 --> 03:51:01,120
of them so how can you do that so one
6262
03:51:01,120 --> 03:51:03,199
way to do that is like this here so
6263
03:51:03,199 --> 03:51:05,680
first import c3 because we want csv to
6264
03:51:05,680 --> 03:51:07,840
do all the hard work for us right
6265
03:51:07,840 --> 03:51:09,600
and then we read the csv file into a
6266
03:51:09,600 --> 03:51:11,680
list of dictionaries and why we do that
6267
03:51:11,680 --> 03:51:14,800
well it makes it easy to access right
6268
03:51:14,800 --> 03:51:17,040
and then now we need to collect all the
6269
03:51:17,040 --> 03:51:20,800
horse powers for each car right so one
6270
03:51:20,800 --> 03:51:23,040
way to do that is remember we did this
6271
03:51:23,040 --> 03:51:24,800
frequency count right
6272
03:51:24,800 --> 03:51:25,600
so
6273
03:51:25,600 --> 03:51:28,239
at the frequency count we had a integer
6274
03:51:28,239 --> 03:51:30,319
but what if we had a list instead of
6275
03:51:30,319 --> 03:51:32,479
that integer well you can do that in a
6276
03:51:32,479 --> 03:51:35,040
python dictionary as well so instead the
6277
03:51:35,040 --> 03:51:37,199
value is a dictionary so we can actually
6278
03:51:37,199 --> 03:51:39,279
do the same trick here right
6279
03:51:39,279 --> 03:51:40,800
so use the dictionary to have a list of
6280
03:51:40,800 --> 03:51:43,040
horsepower for each brand and then we do
6281
03:51:43,040 --> 03:51:46,000
this for loop again right and uh
6282
03:51:46,000 --> 03:51:47,760
just a hint here
6283
03:51:47,760 --> 03:51:48,800
the car
6284
03:51:48,800 --> 03:51:51,600
the car brand is called make as i said
6285
03:51:51,600 --> 03:51:53,680
in the data set
6286
03:51:53,680 --> 03:51:54,479
okay
6287
03:51:54,479 --> 03:51:56,479
so that's how you access it so imagine
6288
03:51:56,479 --> 03:51:58,800
you have a for loop or a car
6289
03:51:58,800 --> 03:52:01,840
in the cars list you have
6290
03:52:01,840 --> 03:52:04,080
then you could use the get method again
6291
03:52:04,080 --> 03:52:06,080
right and this get method you should
6292
03:52:06,080 --> 03:52:08,960
take it for car make for karmic because
6293
03:52:08,960 --> 03:52:10,880
we are it's raining over the car makers
6294
03:52:10,880 --> 03:52:13,279
right we are trying to look for for
6295
03:52:13,279 --> 03:52:15,359
instance first case for audi we want to
6296
03:52:15,359 --> 03:52:17,439
look it up if nothing is there we
6297
03:52:17,439 --> 03:52:20,000
we return an empty list if there is and
6298
03:52:20,000 --> 03:52:22,560
then we add you know plus two list is
6299
03:52:22,560 --> 03:52:24,800
concatenate them then you concatenate
6300
03:52:24,800 --> 03:52:26,960
the horsepower to it right so that's the
6301
03:52:26,960 --> 03:52:28,239
second step
6302
03:52:28,239 --> 03:52:29,760
also remember
6303
03:52:29,760 --> 03:52:33,439
the horsepower here as you saw it is in
6304
03:52:33,439 --> 03:52:34,319
a
6305
03:52:34,319 --> 03:52:35,600
string
6306
03:52:35,600 --> 03:52:37,199
even though it would not be quoted in
6307
03:52:37,199 --> 03:52:38,880
here it would still read it as a string
6308
03:52:38,880 --> 03:52:39,760
because
6309
03:52:39,760 --> 03:52:42,880
that's how csv reader does it so no
6310
03:52:42,880 --> 03:52:44,479
matter what you should always remember
6311
03:52:44,479 --> 03:52:47,040
this is a string so you need to convert
6312
03:52:47,040 --> 03:52:49,279
it and in our case we you just need to
6313
03:52:49,279 --> 03:52:51,359
convert it somewhere and i'll
6314
03:52:51,359 --> 03:52:53,600
i'll do an sf4 you can do it
6315
03:52:53,600 --> 03:52:55,680
here if you wanted to
6316
03:52:55,680 --> 03:52:57,600
so use a new dictionary to keep the
6317
03:52:57,600 --> 03:53:00,080
calculated average horsepower we
6318
03:53:00,080 --> 03:53:02,000
calculated for the for loop over the
6319
03:53:02,000 --> 03:53:03,600
dictionary from step three right so
6320
03:53:03,600 --> 03:53:05,279
basically we do kind of the same thing
6321
03:53:05,279 --> 03:53:07,279
we just have a new dictionary and for
6322
03:53:07,279 --> 03:53:09,120
each one of them we actually calculate
6323
03:53:09,120 --> 03:53:12,399
the sum of that list and then we
6324
03:53:12,399 --> 03:53:15,199
divide it by the length of the list then
6325
03:53:15,199 --> 03:53:17,199
we have the average right
6326
03:53:17,199 --> 03:53:19,680
the sum of the list divided by how many
6327
03:53:19,680 --> 03:53:21,520
items are in the list the length of the
6328
03:53:21,520 --> 03:53:24,640
list is the average of the list right
6329
03:53:24,640 --> 03:53:26,319
yeah good
6330
03:53:26,319 --> 03:53:27,920
so
6331
03:53:27,920 --> 03:53:30,239
this can be done by a nested loop inside
6332
03:53:30,239 --> 03:53:31,680
this is what we this is how we're going
6333
03:53:31,680 --> 03:53:32,960
to do it in this one if you do it a bit
6334
03:53:32,960 --> 03:53:34,160
different it's fine you could do a bit
6335
03:53:34,160 --> 03:53:36,080
smarter than this but this is also
6336
03:53:36,080 --> 03:53:38,160
easier to understand maybe
6337
03:53:38,160 --> 03:53:40,319
good are you ready i am so let's get
6338
03:53:40,319 --> 03:53:42,800
started
6339
03:53:45,199 --> 03:53:47,600
are you ready for this i hope you try to
6340
03:53:47,600 --> 03:53:50,479
yourself and again don't get confused if
6341
03:53:50,479 --> 03:53:52,080
you didn't manage to do it all because
6342
03:53:52,080 --> 03:53:54,399
it's it is a bit tricky i think this
6343
03:53:54,399 --> 03:53:56,319
exercise here or this project here is a
6344
03:53:56,319 --> 03:53:57,680
bit difficult
6345
03:53:57,680 --> 03:54:00,080
and uh but still you know
6346
03:54:00,080 --> 03:54:01,760
trying to solve things where you're
6347
03:54:01,760 --> 03:54:04,080
maybe not 100 comfortable this is where
6348
03:54:04,080 --> 03:54:06,000
you learn right and this is what we're
6349
03:54:06,000 --> 03:54:07,840
doing in this project here right
6350
03:54:07,840 --> 03:54:09,600
learning along the way right
6351
03:54:09,600 --> 03:54:13,040
so so far so good so let's just do it
6352
03:54:13,040 --> 03:54:14,880
step by step right
6353
03:54:14,880 --> 03:54:16,319
so
6354
03:54:16,319 --> 03:54:17,840
import csv that should be
6355
03:54:17,840 --> 03:54:21,520
straightforward right import csv
6356
03:54:21,520 --> 03:54:24,000
boom there you have it
6357
03:54:24,000 --> 03:54:26,239
you read the csv file into a list of
6358
03:54:26,239 --> 03:54:28,080
dictionaries and again if you don't
6359
03:54:28,080 --> 03:54:31,120
remember the syntax by heart it was
6360
03:54:31,120 --> 03:54:33,199
covered in the last one you just needed
6361
03:54:33,199 --> 03:54:36,239
to change uh change the file you're
6362
03:54:36,239 --> 03:54:37,439
reading right
6363
03:54:37,439 --> 03:54:39,040
so
6364
03:54:39,040 --> 03:54:40,560
if you don't remember the syntax nobody
6365
03:54:40,560 --> 03:54:42,399
does that actually most of the time you
6366
03:54:42,399 --> 03:54:45,120
just look things up again and
6367
03:54:45,120 --> 03:54:47,199
unless you use it on a daily basis it
6368
03:54:47,199 --> 03:54:49,840
takes time to get it into your
6369
03:54:49,840 --> 03:54:54,000
into your household into your
6370
03:54:54,319 --> 03:54:56,160
into your flow so you just know it by
6371
03:54:56,160 --> 03:54:57,439
hard right
6372
03:54:57,439 --> 03:55:00,080
so this one was called cars right
6373
03:55:00,080 --> 03:55:01,920
perfect like how did i type it in so
6374
03:55:01,920 --> 03:55:03,439
fast i use tab
6375
03:55:03,439 --> 03:55:05,680
it will auto complete it for you and
6376
03:55:05,680 --> 03:55:09,439
then we do read and then as far right
6377
03:55:09,439 --> 03:55:12,960
and then we had the csv csv reader here
6378
03:55:12,960 --> 03:55:14,880
and then we take the csv and we took the
6379
03:55:14,880 --> 03:55:15,760
dict
6380
03:55:15,760 --> 03:55:17,840
reader remember and it just takes the
6381
03:55:17,840 --> 03:55:20,800
file right remember that good
6382
03:55:20,800 --> 03:55:23,520
and uh then we just need the cars let's
6383
03:55:23,520 --> 03:55:25,840
just call it cars here
6384
03:55:25,840 --> 03:55:27,199
because it's a list of cars you could
6385
03:55:27,199 --> 03:55:29,840
also the car list but let's just call it
6386
03:55:29,840 --> 03:55:33,760
cars here for simplicity list of the csv
6387
03:55:33,760 --> 03:55:36,080
reader right so now you actually have
6388
03:55:36,080 --> 03:55:38,720
them all here but again if i just print
6389
03:55:38,720 --> 03:55:40,080
a knob there it's going to be a long
6390
03:55:40,080 --> 03:55:41,600
list so let's just
6391
03:55:41,600 --> 03:55:43,279
use
6392
03:55:43,279 --> 03:55:45,199
just look at the first one here
6393
03:55:45,199 --> 03:55:47,120
and you see here here we have the first
6394
03:55:47,120 --> 03:55:48,479
car here
6395
03:55:48,479 --> 03:55:50,960
and it is the first line of the csv
6396
03:55:50,960 --> 03:55:52,800
files if you wanted to check it right we
6397
03:55:52,800 --> 03:55:55,600
have a maker audi and it says horsepower
6398
03:55:55,600 --> 03:55:57,840
250 right so you can just check here
6399
03:55:57,840 --> 03:55:59,439
this is the first one
6400
03:55:59,439 --> 03:56:02,399
it's an audi and it has horsepower 250
6401
03:56:02,399 --> 03:56:05,520
right so this is actually nice right and
6402
03:56:05,520 --> 03:56:07,279
again you see the advantage of reading
6403
03:56:07,279 --> 03:56:09,680
the dict reader it is it puts it really
6404
03:56:09,680 --> 03:56:12,000
easy and nice to get
6405
03:56:12,000 --> 03:56:13,760
and also as mentioned
6406
03:56:13,760 --> 03:56:16,399
make is a car brand
6407
03:56:16,399 --> 03:56:17,840
okay
6408
03:56:17,840 --> 03:56:21,439
so the third one use a dictionaries have
6409
03:56:21,439 --> 03:56:24,239
a list of horsepowers for each car brand
6410
03:56:24,239 --> 03:56:25,359
and hint
6411
03:56:25,359 --> 03:56:28,080
the car brand is called make in the data
6412
03:56:28,080 --> 03:56:32,000
set and use get car make
6413
03:56:32,000 --> 03:56:34,880
here and concatenate the horsepower to
6414
03:56:34,880 --> 03:56:37,680
it right so let's try to do that right
6415
03:56:37,680 --> 03:56:38,399
so
6416
03:56:38,399 --> 03:56:41,439
let's call it car
6417
03:56:41,439 --> 03:56:43,040
brands
6418
03:56:43,040 --> 03:56:44,560
and have a
6419
03:56:44,560 --> 03:56:46,479
dictionary for that and then we do the
6420
03:56:46,479 --> 03:56:48,239
for loop for
6421
03:56:48,239 --> 03:56:51,040
remember the cars is a list
6422
03:56:51,040 --> 03:56:55,439
of cars so for car in cars
6423
03:56:55,439 --> 03:56:58,000
that is we have a car here and this car
6424
03:56:58,000 --> 03:57:00,239
would be similar to have a data set
6425
03:57:00,239 --> 03:57:02,399
similar to this one here right the first
6426
03:57:02,399 --> 03:57:04,319
one is actually this one here
6427
03:57:04,319 --> 03:57:06,880
so what is it that we want to do well we
6428
03:57:06,880 --> 03:57:10,319
have the car brands here
6429
03:57:10,640 --> 03:57:14,160
and then we want to put the car
6430
03:57:14,160 --> 03:57:16,720
make here that's the car brand
6431
03:57:16,720 --> 03:57:17,520
and
6432
03:57:17,520 --> 03:57:20,000
what do we want to do well we take the
6433
03:57:20,000 --> 03:57:20,800
car
6434
03:57:20,800 --> 03:57:22,880
brands and we do the get method here
6435
03:57:22,880 --> 03:57:24,160
right and
6436
03:57:24,160 --> 03:57:27,359
then we are looking up if we have
6437
03:57:27,359 --> 03:57:29,760
something already
6438
03:57:29,760 --> 03:57:32,239
a car if i have something already on car
6439
03:57:32,239 --> 03:57:34,560
make right the car brand if not we
6440
03:57:34,560 --> 03:57:37,040
return a empty list right so instead of
6441
03:57:37,040 --> 03:57:39,359
returning 0 here we return the empty
6442
03:57:39,359 --> 03:57:41,279
list this is a nice trick and then we
6443
03:57:41,279 --> 03:57:43,920
concatenate the horsepower of this one
6444
03:57:43,920 --> 03:57:46,399
here so car
6445
03:57:46,399 --> 03:57:48,880
here we take the horse
6446
03:57:48,880 --> 03:57:51,199
power right
6447
03:57:51,199 --> 03:57:54,080
that's basically it
6448
03:57:54,399 --> 03:57:56,080
that's basically it yeah so let's try to
6449
03:57:56,080 --> 03:57:57,279
execute that
6450
03:57:57,279 --> 03:58:00,720
and uh if you look at car brands now
6451
03:58:00,720 --> 03:58:02,800
let's just look at that one and we just
6452
03:58:02,800 --> 03:58:04,960
take audi we know audi exists here we
6453
03:58:04,960 --> 03:58:06,800
don't want to read it all we have a list
6454
03:58:06,800 --> 03:58:09,120
here right so lots of audi is actually
6455
03:58:09,120 --> 03:58:11,359
here we have a list here right
6456
03:58:11,359 --> 03:58:12,640
and uh
6457
03:58:12,640 --> 03:58:14,000
this list here
6458
03:58:14,000 --> 03:58:14,800
is
6459
03:58:14,800 --> 03:58:17,600
containing the horsepower for each one
6460
03:58:17,600 --> 03:58:19,279
of
6461
03:58:19,279 --> 03:58:22,319
the cars of audi brand right
6462
03:58:22,319 --> 03:58:23,600
perfect
6463
03:58:23,600 --> 03:58:25,359
i actually want to delete this one here
6464
03:58:25,359 --> 03:58:28,880
again it's too large to be there okay
6465
03:58:28,880 --> 03:58:31,120
good that was second step
6466
03:58:31,120 --> 03:58:32,720
or third step right and then we have the
6467
03:58:32,720 --> 03:58:34,160
step four
6468
03:58:34,160 --> 03:58:35,680
use a new dictionary to keep the
6469
03:58:35,680 --> 03:58:38,000
calculated average horsepowers we will
6470
03:58:38,000 --> 03:58:40,239
calculate in a for loop over the
6471
03:58:40,239 --> 03:58:42,840
dictionary from step three
6472
03:58:42,840 --> 03:58:46,160
so the hint is to use a nested for loop
6473
03:58:46,160 --> 03:58:47,840
inside the for loop to sum up the
6474
03:58:47,840 --> 03:58:50,880
horsepowers okay and i i do agree you
6475
03:58:50,880 --> 03:58:52,800
can do this smarter than i'm gonna do it
6476
03:58:52,800 --> 03:58:54,479
here but
6477
03:58:54,479 --> 03:58:57,520
it's also to keep it simple
6478
03:58:57,520 --> 03:59:00,080
good so
6479
03:59:00,080 --> 03:59:01,760
car
6480
03:59:01,760 --> 03:59:03,840
brand
6481
03:59:03,840 --> 03:59:05,840
horsepower right let's let's call the
6482
03:59:05,840 --> 03:59:08,880
dictionary that i'm very
6483
03:59:08,880 --> 03:59:10,399
very good right
6484
03:59:10,399 --> 03:59:11,359
so
6485
03:59:11,359 --> 03:59:14,479
now we have the car brands and this is
6486
03:59:14,479 --> 03:59:17,199
this one here this one has the list of
6487
03:59:17,199 --> 03:59:19,120
them right
6488
03:59:19,120 --> 03:59:22,160
so what do you want you want to have
6489
03:59:22,160 --> 03:59:23,760
four
6490
03:59:23,760 --> 03:59:25,439
car and
6491
03:59:25,439 --> 03:59:26,880
powers right this is a list of
6492
03:59:26,880 --> 03:59:28,640
horsepowers
6493
03:59:28,640 --> 03:59:29,840
in
6494
03:59:29,840 --> 03:59:31,040
car
6495
03:59:31,040 --> 03:59:32,800
brands
6496
03:59:32,800 --> 03:59:34,640
items right remember this is how you
6497
03:59:34,640 --> 03:59:37,439
iterate over a dictionary right and
6498
03:59:37,439 --> 03:59:39,840
don't worry i call it here this is a key
6499
03:59:39,840 --> 03:59:42,000
and this is a value right so the key is
6500
03:59:42,000 --> 03:59:44,080
a car brand actually
6501
03:59:44,080 --> 03:59:45,600
so maybe we should call this one car
6502
03:59:45,600 --> 03:59:47,680
brand to be more
6503
03:59:47,680 --> 03:59:49,600
specific and this is a list of
6504
03:59:49,600 --> 03:59:52,880
horsepowers right horsepower list let's
6505
03:59:52,880 --> 03:59:54,479
call it that
6506
03:59:54,479 --> 03:59:55,439
right
6507
03:59:55,439 --> 03:59:57,199
so
6508
03:59:57,199 --> 03:59:58,479
this
6509
03:59:58,479 --> 04:00:01,120
is a key this is a value right so what
6510
04:00:01,120 --> 04:00:04,800
do we do now right so
6511
04:00:04,800 --> 04:00:07,199
we want to sum up the list here this
6512
04:00:07,199 --> 04:00:10,239
list here and divided by the length of
6513
04:00:10,239 --> 04:00:13,920
it afterwards this will be the
6514
04:00:13,920 --> 04:00:16,160
average horsepower we are looking for so
6515
04:00:16,160 --> 04:00:18,399
let's try to do that so
6516
04:00:18,399 --> 04:00:20,319
horsepower sum
6517
04:00:20,319 --> 04:00:23,680
we start by zero and then four
6518
04:00:23,680 --> 04:00:27,040
horsepower in horsepower list right
6519
04:00:27,040 --> 04:00:29,760
then we take the hp sum
6520
04:00:29,760 --> 04:00:31,199
and we
6521
04:00:31,199 --> 04:00:32,560
add
6522
04:00:32,560 --> 04:00:36,080
here the end of hp remember hp the
6523
04:00:36,080 --> 04:00:39,279
horsepower in the list is a string right
6524
04:00:39,279 --> 04:00:41,520
remember we are keeping everything as a
6525
04:00:41,520 --> 04:00:43,840
string here inside
6526
04:00:43,840 --> 04:00:45,439
the list here that's what i said you
6527
04:00:45,439 --> 04:00:47,680
need to convert it somehow somewhere
6528
04:00:47,680 --> 04:00:49,040
we're just going to do it down there you
6529
04:00:49,040 --> 04:00:50,720
could also have done it here right i
6530
04:00:50,720 --> 04:00:52,399
didn't
6531
04:00:52,399 --> 04:00:54,560
and then we have the sum of all the
6532
04:00:54,560 --> 04:00:56,560
horsepowers now we need the average of
6533
04:00:56,560 --> 04:00:58,319
it right so car
6534
04:00:58,319 --> 04:01:00,399
brand hp
6535
04:01:00,399 --> 04:01:02,560
and then we have the car here
6536
04:01:02,560 --> 04:01:05,199
and we add yeah we need the carb no we
6537
04:01:05,199 --> 04:01:07,120
don't we just need this
6538
04:01:07,120 --> 04:01:11,920
hp sum here divided by the length of
6539
04:01:11,920 --> 04:01:14,479
of the hp list
6540
04:01:14,479 --> 04:01:15,439
right
6541
04:01:15,439 --> 04:01:17,520
so what i'm doing here right so here we
6542
04:01:17,520 --> 04:01:19,760
summed it all up all the items and then
6543
04:01:19,760 --> 04:01:22,239
they divided by the length of the list
6544
04:01:22,239 --> 04:01:24,640
which gives the average right so let's
6545
04:01:24,640 --> 04:01:27,840
execute that and
6546
04:01:28,080 --> 04:01:31,199
unhashable type dict
6547
04:01:31,199 --> 04:01:33,439
oh yeah i didn't call it car call the
6548
04:01:33,439 --> 04:01:35,439
car brand here right
6549
04:01:35,439 --> 04:01:37,520
thank you for reminding me right so i
6550
04:01:37,520 --> 04:01:39,359
was forgetting i didn't i changed this
6551
04:01:39,359 --> 04:01:41,359
car to car brand right
6552
04:01:41,359 --> 04:01:43,439
so you needed to put the correct one
6553
04:01:43,439 --> 04:01:46,960
here right perfect awesome so now you
6554
04:01:46,960 --> 04:01:48,960
actually have the car
6555
04:01:48,960 --> 04:01:51,359
brand hp here and now we're just gonna
6556
04:01:51,359 --> 04:01:55,040
list it all we have not that extr
6557
04:01:55,040 --> 04:01:57,760
dream long list now right so we have all
6558
04:01:57,760 --> 04:01:59,920
audi here so we see the average of the
6559
04:01:59,920 --> 04:02:02,560
horsepower is around 300
6560
04:02:02,560 --> 04:02:08,160
and uh bmv here is a 347 a volvo is 247
6561
04:02:08,160 --> 04:02:11,359
and just to take one volkswagen is 120
6562
04:02:11,359 --> 04:02:12,960
i mean of these specific brands here
6563
04:02:12,960 --> 04:02:15,199
right this is not scientific or anything
6564
04:02:15,199 --> 04:02:16,000
right
6565
04:02:16,000 --> 04:02:17,199
is there anything interesting on this
6566
04:02:17,199 --> 04:02:18,720
list here
6567
04:02:18,720 --> 04:02:21,199
aston martin that's pretty nice car too
6568
04:02:21,199 --> 04:02:26,880
british car 470 ferrari 540.
6569
04:02:26,880 --> 04:02:28,399
is there anything else did i miss
6570
04:02:28,399 --> 04:02:29,920
something
6571
04:02:29,920 --> 04:02:32,800
i often miss them oh there's my favorite
6572
04:02:32,800 --> 04:02:34,800
lamborghini i know i know i'm a
6573
04:02:34,800 --> 04:02:37,680
lamborghini fan
6574
04:02:38,160 --> 04:02:39,439
nice
6575
04:02:39,439 --> 04:02:42,560
perfect okay so this actually does all
6576
04:02:42,560 --> 04:02:44,239
we wanted to do right
6577
04:02:44,239 --> 04:02:46,160
we have done what we wanted to do we
6578
04:02:46,160 --> 04:02:48,080
wanted to have calculate the average
6579
04:02:48,080 --> 04:02:50,479
horsepower of each car brand right and
6580
04:02:50,479 --> 04:02:52,080
again this this number doesn't really
6581
04:02:52,080 --> 04:02:54,160
make any scientific sense or anything
6582
04:02:54,160 --> 04:02:55,680
it's just you know to learn to do some
6583
04:02:55,680 --> 04:02:58,399
tools and uh i love cars so why not do
6584
04:02:58,399 --> 04:03:00,720
something with a car list you can do it
6585
04:03:00,720 --> 04:03:02,000
with your own project with something
6586
04:03:02,000 --> 04:03:04,560
else now because now you have the tools
6587
04:03:04,560 --> 04:03:06,000
awesome huh
6588
04:03:06,000 --> 04:03:06,720
so
6589
04:03:06,720 --> 04:03:09,520
unless anything else no let's see you in
6590
04:03:09,520 --> 04:03:12,800
the next one bye bye
6591
04:03:15,760 --> 04:03:19,920
recursion and this is amazing because
6592
04:03:19,920 --> 04:03:21,520
this is one of these things that a lot
6593
04:03:21,520 --> 04:03:23,120
of programmers
6594
04:03:23,120 --> 04:03:25,680
don't really understand at the beginning
6595
04:03:25,680 --> 04:03:28,560
and i understand it's a bit tricky but
6596
04:03:28,560 --> 04:03:31,920
recursion actually doesn't give you more
6597
04:03:31,920 --> 04:03:34,479
power as a programmer but it makes you
6598
04:03:34,479 --> 04:03:37,359
solve problems that are complex in an
6599
04:03:37,359 --> 04:03:39,199
easier way
6600
04:03:39,199 --> 04:03:41,760
right remember again the sin of
6601
04:03:41,760 --> 04:03:44,800
python readability is everything simple
6602
04:03:44,800 --> 04:03:46,960
is everything right you need to keep it
6603
04:03:46,960 --> 04:03:48,000
simple
6604
04:03:48,000 --> 04:03:51,120
so often why you would use recursion is
6605
04:03:51,120 --> 04:03:53,840
to make things simpler and easier to
6606
04:03:53,840 --> 04:03:56,560
understand the problem with recursion is
6607
04:03:56,560 --> 04:03:57,760
in the beginning
6608
04:03:57,760 --> 04:03:59,840
often people find well this doesn't make
6609
04:03:59,840 --> 04:04:01,120
it simpler because it's difficult to
6610
04:04:01,120 --> 04:04:03,439
understand but that's
6611
04:04:03,439 --> 04:04:05,520
just until you get
6612
04:04:05,520 --> 04:04:06,800
so that's what we're going to try to
6613
04:04:06,800 --> 04:04:08,800
capture in this one here we're going to
6614
04:04:08,800 --> 04:04:11,680
capture it so we're going to do it
6615
04:04:11,680 --> 04:04:13,680
in this lecture where we're going to
6616
04:04:13,680 --> 04:04:16,319
start with looking at a simple recursive
6617
04:04:16,319 --> 04:04:17,279
function
6618
04:04:17,279 --> 04:04:18,399
and then we're going to solve one of the
6619
04:04:18,399 --> 04:04:21,120
classical problems uh fibonacci sequence
6620
04:04:21,120 --> 04:04:22,479
i don't know what it is don't worry
6621
04:04:22,479 --> 04:04:24,720
about it we'll get there but this is
6622
04:04:24,720 --> 04:04:26,319
something which is actually defined
6623
04:04:26,319 --> 04:04:29,279
recursive um maybe get you started
6624
04:04:29,279 --> 04:04:31,760
understanding recursion in the project
6625
04:04:31,760 --> 04:04:33,520
it's gonna be amazing we're gonna solve
6626
04:04:33,520 --> 04:04:35,680
the tower of hanois
6627
04:04:35,680 --> 04:04:39,760
the tower of hanoi is a crazy problem to
6628
04:04:39,760 --> 04:04:41,680
solve and when you think about it in the
6629
04:04:41,680 --> 04:04:43,359
beginning it just seems like this is
6630
04:04:43,359 --> 04:04:45,520
impossible to solve how can i program
6631
04:04:45,520 --> 04:04:48,160
this but when you get recursion it's
6632
04:04:48,160 --> 04:04:49,840
going to be simple
6633
04:04:49,840 --> 04:04:51,680
yeah i know often
6634
04:04:51,680 --> 04:04:53,680
i remember myself when i got the problem
6635
04:04:53,680 --> 04:04:55,920
in college when i was a student i didn't
6636
04:04:55,920 --> 04:04:56,960
really get it in the beginning but
6637
04:04:56,960 --> 04:04:59,040
suddenly just fell down and just wow now
6638
04:04:59,040 --> 04:05:00,800
i get it and it's just like how could i
6639
04:05:00,800 --> 04:05:02,960
spend so much time figuring this one out
6640
04:05:02,960 --> 04:05:04,880
maybe because it wasn't explained well
6641
04:05:04,880 --> 04:05:06,239
but uh
6642
04:05:06,239 --> 04:05:08,880
yeah recursion just flew over my head in
6643
04:05:08,880 --> 04:05:10,640
the beginning but when you get recursion
6644
04:05:10,640 --> 04:05:12,319
it's going to be amazing it's going to
6645
04:05:12,319 --> 04:05:15,279
make things easy and make some problems
6646
04:05:15,279 --> 04:05:18,399
easier to solve so are you ready i hope
6647
04:05:18,399 --> 04:05:20,560
so because this is so exciting and let's
6648
04:05:20,560 --> 04:05:23,199
jump to jupyter notebook and get started
6649
04:05:23,199 --> 04:05:25,760
so in our jupyter notebook here we have
6650
04:05:25,760 --> 04:05:27,680
the title recursion
6651
04:05:27,680 --> 04:05:29,760
and the purpose is to learn about
6652
04:05:29,760 --> 04:05:32,800
recursion and recursive functions so
6653
04:05:32,800 --> 04:05:36,000
recursive recursive functions are using
6654
04:05:36,000 --> 04:05:37,840
recursion right
6655
04:05:37,840 --> 04:05:40,080
so just a little quote here in computer
6656
04:05:40,080 --> 04:05:43,359
science recursion is a method of solving
6657
04:05:43,359 --> 04:05:44,640
a problem
6658
04:05:44,640 --> 04:05:47,520
where the solution depends on solutions
6659
04:05:47,520 --> 04:05:49,920
to a smaller instance of the same
6660
04:05:49,920 --> 04:05:52,800
problem right so basically you have a
6661
04:05:52,800 --> 04:05:54,640
big problem and you break it down to a
6662
04:05:54,640 --> 04:05:57,199
smaller problem so how can we exemplify
6663
04:05:57,199 --> 04:05:59,760
this symbol right so let's try to make a
6664
04:05:59,760 --> 04:06:02,239
function right so this one should count
6665
04:06:02,239 --> 04:06:03,920
this function should count
6666
04:06:03,920 --> 04:06:05,680
and the point is that this should count
6667
04:06:05,680 --> 04:06:07,279
the values
6668
04:06:07,279 --> 04:06:09,840
uh if you say we call it let's just
6669
04:06:09,840 --> 04:06:12,560
assume here we call it count six here
6670
04:06:12,560 --> 04:06:15,120
right what this should result in is the
6671
04:06:15,120 --> 04:06:18,640
sum of six plus five plus
6672
04:06:18,640 --> 04:06:20,399
four plus
6673
04:06:20,399 --> 04:06:21,760
three
6674
04:06:21,760 --> 04:06:25,040
plus two plus one right
6675
04:06:25,040 --> 04:06:28,239
this is what it should return right
6676
04:06:28,239 --> 04:06:30,560
so this is a sum right this is a count
6677
04:06:30,560 --> 04:06:32,640
it's actually not the account it's just
6678
04:06:32,640 --> 04:06:34,399
maybe count was the wrong name for this
6679
04:06:34,399 --> 04:06:36,560
one right but don't worry about that we
6680
04:06:36,560 --> 04:06:39,199
can live with that
6681
04:06:39,600 --> 04:06:41,680
how can we solve this right
6682
04:06:41,680 --> 04:06:44,000
well
6683
04:06:44,319 --> 04:06:46,479
we can solve it with an uh with a loop
6684
04:06:46,479 --> 04:06:48,399
right a for loop but we don't want that
6685
04:06:48,399 --> 04:06:49,760
in this one here we want to solve it
6686
04:06:49,760 --> 04:06:51,359
recursively right
6687
04:06:51,359 --> 04:06:53,840
so the key thing remember when you call
6688
04:06:53,840 --> 04:06:55,359
it with six you should
6689
04:06:55,359 --> 04:06:57,920
depend on a solution of a smaller
6690
04:06:57,920 --> 04:07:00,160
instance of the problem that's what it
6691
04:07:00,160 --> 04:07:01,199
says right
6692
04:07:01,199 --> 04:07:04,960
so if we return here now instead we say
6693
04:07:04,960 --> 04:07:08,880
six for instance and we add count 5.
6694
04:07:08,880 --> 04:07:11,199
what will happen now right
6695
04:07:11,199 --> 04:07:12,399
well
6696
04:07:12,399 --> 04:07:14,080
first of all
6697
04:07:14,080 --> 04:07:15,600
we should probably not use 6 here
6698
04:07:15,600 --> 04:07:17,520
because it's n that we are calling with
6699
04:07:17,520 --> 04:07:20,000
but then we call with n minus 1 here
6700
04:07:20,000 --> 04:07:20,960
right
6701
04:07:20,960 --> 04:07:23,199
and in this case we have broken it down
6702
04:07:23,199 --> 04:07:25,359
to a smaller problem while this
6703
04:07:25,359 --> 04:07:27,600
definition sounds pretty nice this is
6704
04:07:27,600 --> 04:07:29,439
one problem if you think about it right
6705
04:07:29,439 --> 04:07:31,600
so let's actually just try to run this
6706
04:07:31,600 --> 04:07:32,640
one and
6707
04:07:32,640 --> 04:07:35,359
run it down here and what happens is
6708
04:07:35,359 --> 04:07:38,000
well actually nothing happens until it
6709
04:07:38,000 --> 04:07:40,000
says recursion error right
6710
04:07:40,000 --> 04:07:42,640
and what does it say it says maximum
6711
04:07:42,640 --> 04:07:46,000
recursion depth exceeded right so what
6712
04:07:46,000 --> 04:07:49,199
happens it keeps calling itself right so
6713
04:07:49,199 --> 04:07:51,680
remember remember here we call this six
6714
04:07:51,680 --> 04:07:53,199
it's a six here and then it calls with
6715
04:07:53,199 --> 04:07:55,199
six minus one is five then it calls
6716
04:07:55,199 --> 04:07:57,840
itself right it calls itself here and
6717
04:07:57,840 --> 04:07:59,920
then it's called with five and then five
6718
04:07:59,920 --> 04:08:01,439
is here and then it calls itself with
6719
04:08:01,439 --> 04:08:05,359
four calls itself the three two
6720
04:08:05,359 --> 04:08:06,399
one
6721
04:08:06,399 --> 04:08:07,439
zero
6722
04:08:07,439 --> 04:08:10,800
minus one minus two minus three and so
6723
04:08:10,800 --> 04:08:13,279
on and continues right and this is bad
6724
04:08:13,279 --> 04:08:16,159
why is this bad because it never ends so
6725
04:08:16,159 --> 04:08:19,279
we need a base case right so if n is
6726
04:08:19,279 --> 04:08:22,000
let's say less equal to zero
6727
04:08:22,000 --> 04:08:26,880
less equal to zero then we return n
6728
04:08:26,880 --> 04:08:28,800
just keep it simple right
6729
04:08:28,800 --> 04:08:30,720
because what this will do is when we
6730
04:08:30,720 --> 04:08:34,000
reach n in this case it will return
6731
04:08:34,000 --> 04:08:35,920
reach zero in this case it will return
6732
04:08:35,920 --> 04:08:36,800
zero
6733
04:08:36,800 --> 04:08:38,479
and then it'll return all the way back
6734
04:08:38,479 --> 04:08:41,199
right let's try to do this now right did
6735
04:08:41,199 --> 04:08:43,680
i execute this one above no here we go
6736
04:08:43,680 --> 04:08:46,000
and then we get 21. let's try to see
6737
04:08:46,000 --> 04:08:47,920
that right let's try to write it out
6738
04:08:47,920 --> 04:08:48,880
there so
6739
04:08:48,880 --> 04:08:50,000
count
6740
04:08:50,000 --> 04:08:51,040
six
6741
04:08:51,040 --> 04:08:53,840
well it is this one here right and then
6742
04:08:53,840 --> 04:08:55,040
we change
6743
04:08:55,040 --> 04:08:56,720
six to
6744
04:08:56,720 --> 04:09:00,159
the n to six and n minus one to 5.
6745
04:09:00,159 --> 04:09:03,279
count 5 here well this is this one again
6746
04:09:03,279 --> 04:09:04,159
right
6747
04:09:04,159 --> 04:09:07,120
and we put it in here and then we put 5
6748
04:09:07,120 --> 04:09:10,399
here and then we add 4 here right
6749
04:09:10,399 --> 04:09:13,040
but 4 here it's again a call to itself
6750
04:09:13,040 --> 04:09:14,479
so we get it again
6751
04:09:14,479 --> 04:09:16,640
and then we have three
6752
04:09:16,640 --> 04:09:18,800
four here and
6753
04:09:18,800 --> 04:09:21,040
three here but three here again it's a
6754
04:09:21,040 --> 04:09:25,120
call to itself so we do it again three
6755
04:09:25,120 --> 04:09:26,159
two
6756
04:09:26,159 --> 04:09:29,120
and again the call here is call again
6757
04:09:29,120 --> 04:09:31,279
and we have two
6758
04:09:31,279 --> 04:09:32,479
and
6759
04:09:32,479 --> 04:09:33,359
one
6760
04:09:33,359 --> 04:09:35,439
and one here is also a call so we call
6761
04:09:35,439 --> 04:09:38,159
again one and then we call this zero
6762
04:09:38,159 --> 04:09:39,279
right
6763
04:09:39,279 --> 04:09:41,439
so what happens when we call with zero
6764
04:09:41,439 --> 04:09:43,359
remember then we come into this one we
6765
04:09:43,359 --> 04:09:45,040
just return zero
6766
04:09:45,040 --> 04:09:47,520
so we return zero here so this is
6767
04:09:47,520 --> 04:09:49,120
actually what happens right and then we
6768
04:09:49,120 --> 04:09:50,800
have six
6769
04:09:50,800 --> 04:09:52,239
plus five
6770
04:09:52,239 --> 04:09:56,800
eleven plus ten four four fifteen plus 3
6771
04:09:56,800 --> 04:10:00,640
is 18 plus 2 is 20 plus 1 is 21 plus 0
6772
04:10:00,640 --> 04:10:03,359
is 21 right so we get the 21 here right
6773
04:10:03,359 --> 04:10:06,399
so this is actually correct right so you
6774
04:10:06,399 --> 04:10:08,560
see how the recursion is working right
6775
04:10:08,560 --> 04:10:11,199
we call down and down and down and then
6776
04:10:11,199 --> 04:10:13,600
we return the value value the key thing
6777
04:10:13,600 --> 04:10:15,279
to understand we need the base case here
6778
04:10:15,279 --> 04:10:17,520
otherwise it goes crazy as we saw
6779
04:10:17,520 --> 04:10:21,199
previously right let's just remove this
6780
04:10:21,199 --> 04:10:22,479
good
6781
04:10:22,479 --> 04:10:24,479
now that was a simple
6782
04:10:24,479 --> 04:10:26,720
count example as i showed here
6783
04:10:26,720 --> 04:10:28,720
now we want to go to the fibonacci
6784
04:10:28,720 --> 04:10:31,120
numbers right and fibonacci numbers are
6785
04:10:31,120 --> 04:10:32,880
defined like this
6786
04:10:32,880 --> 04:10:34,399
and you can read about more about them
6787
04:10:34,399 --> 04:10:36,960
down here if you want i mean don't don't
6788
04:10:36,960 --> 04:10:38,560
bother because it's all defined here
6789
04:10:38,560 --> 04:10:39,439
right
6790
04:10:39,439 --> 04:10:42,159
so the fibonacci numbers is a sequence
6791
04:10:42,159 --> 04:10:46,640
of f0 f1 f2 f3 and all the way up right
6792
04:10:46,640 --> 04:10:50,560
so f0 is defined as 0 and f1 is defined
6793
04:10:50,560 --> 04:10:52,479
to 1.
6794
04:10:52,479 --> 04:10:55,199
f2 is defined by this formula right so
6795
04:10:55,199 --> 04:10:57,680
if 2 equals
6796
04:10:57,680 --> 04:11:01,680
so n is 2 in this case then we have f
6797
04:11:01,680 --> 04:11:04,960
n minus 1 that's f1 and fn minus 2 is f0
6798
04:11:04,960 --> 04:11:08,720
right so f2 equals f1 minus plus f2
6799
04:11:08,720 --> 04:11:09,840
right
6800
04:11:09,840 --> 04:11:13,199
so the sequence begins as follows 0 1
6801
04:11:13,199 --> 04:11:18,560
yes 1 again 2 3 5 8 13 21 and so forth
6802
04:11:18,560 --> 04:11:20,319
let's just try to play around with this
6803
04:11:20,319 --> 04:11:23,520
so if we put f0 here to be 0
6804
04:11:23,520 --> 04:11:26,800
and f1 to b1
6805
04:11:26,800 --> 04:11:28,720
now we have that right
6806
04:11:28,720 --> 04:11:31,279
so let's try to make f2 here right so f2
6807
04:11:31,279 --> 04:11:35,520
was equal to f1 plus f0 right so let's
6808
04:11:35,520 --> 04:11:37,760
just also just get the value here it's 1
6809
04:11:37,760 --> 04:11:39,600
again right so remember the sequence is
6810
04:11:39,600 --> 04:11:40,960
0 1 1
6811
04:11:40,960 --> 04:11:43,439
0 1 1 right
6812
04:11:43,439 --> 04:11:47,199
then we have f 3 here which is then f
6813
04:11:47,199 --> 04:11:50,720
2 plus f 1 right because we're using
6814
04:11:50,720 --> 04:11:55,040
this formula here f 3 is if 2 plus f 1
6815
04:11:55,040 --> 04:11:56,080
right
6816
04:11:56,080 --> 04:11:57,359
and let's just
6817
04:11:57,359 --> 04:11:59,520
get it out here it is 2 right as it
6818
04:11:59,520 --> 04:12:01,760
should be right remember
6819
04:12:01,760 --> 04:12:03,600
zero one one two so the next one should
6820
04:12:03,600 --> 04:12:05,439
be three five eight let's just try to
6821
04:12:05,439 --> 04:12:06,880
make those
6822
04:12:06,880 --> 04:12:07,840
f
6823
04:12:07,840 --> 04:12:12,000
four is x f three plus f two that's f
6824
04:12:12,000 --> 04:12:13,040
four
6825
04:12:13,040 --> 04:12:16,319
and those three f five is equal to f4
6826
04:12:16,319 --> 04:12:19,920
plus f3 so we have f5 here and i can
6827
04:12:19,920 --> 04:12:21,600
continue like this i think you get the
6828
04:12:21,600 --> 04:12:23,439
point and you also see a problem here
6829
04:12:23,439 --> 04:12:25,439
this is this is not nice programming
6830
04:12:25,439 --> 04:12:27,359
right this is this
6831
04:12:27,359 --> 04:12:29,600
i need f 100 right how do you get that
6832
04:12:29,600 --> 04:12:31,920
right hmm well i continue like this
6833
04:12:31,920 --> 04:12:33,760
forever right you don't want that you
6834
04:12:33,760 --> 04:12:35,680
want a function that can calculate this
6835
04:12:35,680 --> 04:12:38,560
for you so how do you do that
6836
04:12:38,560 --> 04:12:41,520
yeah you're ready okay so let's try
6837
04:12:41,520 --> 04:12:42,399
def
6838
04:12:42,399 --> 04:12:43,199
uh
6839
04:12:43,199 --> 04:12:46,159
not def def def fibonacci fibonacci here
6840
04:12:46,159 --> 04:12:49,920
we just call it fibrin and call n here
6841
04:12:49,920 --> 04:12:52,479
so the base case
6842
04:12:52,479 --> 04:12:53,920
is actually
6843
04:12:53,920 --> 04:12:56,000
f0 and f1 right
6844
04:12:56,000 --> 04:12:57,760
so if
6845
04:12:57,760 --> 04:13:03,040
n is less or equal to 1 we just return
6846
04:13:03,040 --> 04:13:04,800
n right
6847
04:13:04,800 --> 04:13:06,159
that's it
6848
04:13:06,159 --> 04:13:07,760
get it
6849
04:13:07,760 --> 04:13:09,760
perfect
6850
04:13:09,760 --> 04:13:12,399
then we return and this is where it
6851
04:13:12,399 --> 04:13:15,120
becomes tricky right we return this one
6852
04:13:15,120 --> 04:13:17,359
this formula here right
6853
04:13:17,359 --> 04:13:19,439
and this basically means that we take
6854
04:13:19,439 --> 04:13:21,120
fib
6855
04:13:21,120 --> 04:13:22,080
off
6856
04:13:22,080 --> 04:13:22,880
n
6857
04:13:22,880 --> 04:13:24,319
minus one
6858
04:13:24,319 --> 04:13:25,279
plus
6859
04:13:25,279 --> 04:13:26,640
fib
6860
04:13:26,640 --> 04:13:28,800
and minus two
6861
04:13:28,800 --> 04:13:29,760
i'm
6862
04:13:29,760 --> 04:13:32,000
mr minus there right and that's
6863
04:13:32,000 --> 04:13:33,279
basically it
6864
04:13:33,279 --> 04:13:35,279
let's try it
6865
04:13:35,279 --> 04:13:36,720
fib
6866
04:13:36,720 --> 04:13:39,840
we calculated three up there or four
6867
04:13:39,840 --> 04:13:40,640
there
6868
04:13:40,640 --> 04:13:42,159
it's three right
6869
04:13:42,159 --> 04:13:44,560
as we see it should be f4 is three so
6870
04:13:44,560 --> 04:13:47,520
fib four is three right and
6871
04:13:47,520 --> 04:13:48,560
fib
6872
04:13:48,560 --> 04:13:49,520
five
6873
04:13:49,520 --> 04:13:51,680
is five right and fib
6874
04:13:51,680 --> 04:13:52,479
six
6875
04:13:52,479 --> 04:13:53,840
is eight
6876
04:13:53,840 --> 04:13:55,120
right
6877
04:13:55,120 --> 04:13:57,040
thirteen twenty one thirty three right
6878
04:13:57,040 --> 04:13:58,960
she will just try
6879
04:13:58,960 --> 04:14:01,199
fib
6880
04:14:01,520 --> 04:14:02,399
seven
6881
04:14:02,399 --> 04:14:04,239
thirteen fib
6882
04:14:04,239 --> 04:14:05,520
eight
6883
04:14:05,520 --> 04:14:06,960
twenty one right and you can continue
6884
04:14:06,960 --> 04:14:08,840
like that but you see here the
6885
04:14:08,840 --> 04:14:12,080
simplicity of this
6886
04:14:12,080 --> 04:14:14,720
formula here now
6887
04:14:14,720 --> 04:14:16,720
most people don't appreciate it just
6888
04:14:16,720 --> 04:14:18,479
seeing it like this but just take
6889
04:14:18,479 --> 04:14:19,920
yourself a moment and look at the
6890
04:14:19,920 --> 04:14:22,080
formula up here
6891
04:14:22,080 --> 04:14:24,239
how would you calculate this
6892
04:14:24,239 --> 04:14:25,040
if
6893
04:14:25,040 --> 04:14:27,359
you couldn't use recursion
6894
04:14:27,359 --> 04:14:30,080
it is possible yeah it's not a problem
6895
04:14:30,080 --> 04:14:33,520
it just becomes more complex and
6896
04:14:33,520 --> 04:14:35,359
if you're curious about that there are
6897
04:14:35,359 --> 04:14:37,359
many you can find that online as well
6898
04:14:37,359 --> 04:14:39,439
but this is just you know when you just
6899
04:14:39,439 --> 04:14:41,600
figure out recursion how easy it is wow
6900
04:14:41,600 --> 04:14:43,199
it's amazing right
6901
04:14:43,199 --> 04:14:44,399
so
6902
04:14:44,399 --> 04:14:46,880
now we understand what recursion is and
6903
04:14:46,880 --> 04:14:49,279
how it calls sub problems
6904
04:14:49,279 --> 04:14:51,600
like we did in this case here and how
6905
04:14:51,600 --> 04:14:54,000
you need a base case here to return
6906
04:14:54,000 --> 04:14:55,840
otherwise it will continue forever if i
6907
04:14:55,840 --> 04:14:58,159
took this if statement out here it will
6908
04:14:58,159 --> 04:15:00,080
get the same recursion error we did
6909
04:15:00,080 --> 04:15:01,040
before
6910
04:15:01,040 --> 04:15:03,760
okay so now we're ready for the tower of
6911
04:15:03,760 --> 04:15:05,359
hanoi it's going to be exciting i'm
6912
04:15:05,359 --> 04:15:07,199
telling you it's going to be amazing so
6913
04:15:07,199 --> 04:15:08,399
see you
6914
04:15:08,399 --> 04:15:12,560
in a moment huh yeah good
6915
04:15:15,359 --> 04:15:18,000
tower of hanoi this project is going to
6916
04:15:18,000 --> 04:15:20,479
be amazing it's going to be a big one
6917
04:15:20,479 --> 04:15:22,720
and
6918
04:15:22,960 --> 04:15:24,399
i don't know if it's big one but it
6919
04:15:24,399 --> 04:15:26,319
takes time to understand it let's let's
6920
04:15:26,319 --> 04:15:27,840
say it like that right
6921
04:15:27,840 --> 04:15:30,479
so the project here and the goal is to
6922
04:15:30,479 --> 04:15:32,560
solve tower of hanoi
6923
04:15:32,560 --> 04:15:34,000
recursively
6924
04:15:34,000 --> 04:15:36,399
you are free to do it non-recursively i
6925
04:15:36,399 --> 04:15:38,720
just say recursively is easier when you
6926
04:15:38,720 --> 04:15:40,640
get it right
6927
04:15:40,640 --> 04:15:43,120
so what is the tower of hanoi right
6928
04:15:43,120 --> 04:15:45,120
the tower of hanai is a mathematical
6929
04:15:45,120 --> 04:15:48,640
game which was which has three rules
6930
04:15:48,640 --> 04:15:50,479
before we set the rules let's see how
6931
04:15:50,479 --> 04:15:52,720
our universe looks like right so the
6932
04:15:52,720 --> 04:15:54,880
universe is we have the three towers
6933
04:15:54,880 --> 04:15:56,479
here or rods
6934
04:15:56,479 --> 04:15:57,279
and
6935
04:15:57,279 --> 04:15:59,439
then there's some discs and the base
6936
04:15:59,439 --> 04:16:01,439
simple case people solve first is this
6937
04:16:01,439 --> 04:16:04,479
case with three disks you can have many
6938
04:16:04,479 --> 04:16:06,239
disks on top here but there's something
6939
04:16:06,239 --> 04:16:07,760
you should notice that there are
6940
04:16:07,760 --> 04:16:10,800
different sizes so we have disk of size
6941
04:16:10,800 --> 04:16:12,560
one two three and if you had more disk
6942
04:16:12,560 --> 04:16:14,960
it would be four five six and so forth
6943
04:16:14,960 --> 04:16:16,159
uh
6944
04:16:16,159 --> 04:16:19,040
perfect right so this is it so this is
6945
04:16:19,040 --> 04:16:20,880
the universe and the goal is to get all
6946
04:16:20,880 --> 04:16:23,760
these discs over on this rod or this
6947
04:16:23,760 --> 04:16:25,920
tower over here right
6948
04:16:25,920 --> 04:16:27,439
perfect
6949
04:16:27,439 --> 04:16:29,920
so as i said here the disks have
6950
04:16:29,920 --> 04:16:33,120
different sizes and the goal is to move
6951
04:16:33,120 --> 04:16:34,640
the disk from
6952
04:16:34,640 --> 04:16:37,840
one tower the first one to the one with
6953
04:16:37,840 --> 04:16:40,239
the following three rules right
6954
04:16:40,239 --> 04:16:42,399
so we have three rules so one other
6955
04:16:42,399 --> 04:16:45,199
thing you can only move one disk at the
6956
04:16:45,199 --> 04:16:47,359
time
6957
04:16:47,359 --> 04:16:49,359
only one disk like here i take one disk
6958
04:16:49,359 --> 04:16:51,359
here right you can only take the top
6959
04:16:51,359 --> 04:16:53,199
disk and place it on top of another rod
6960
04:16:53,199 --> 04:16:55,600
right so you take this one one on top of
6961
04:16:55,600 --> 04:16:57,520
this one if there's nothing it's on the
6962
04:16:57,520 --> 04:16:58,640
top right
6963
04:16:58,640 --> 04:17:00,560
you cannot place a bigger disc on top of
6964
04:17:00,560 --> 04:17:02,000
a smaller disc that means you cannot
6965
04:17:02,000 --> 04:17:04,000
place this one on this one right
6966
04:17:04,000 --> 04:17:06,319
so the first two rules combined means
6967
04:17:06,319 --> 04:17:08,640
you can only take one top disc and move
6968
04:17:08,640 --> 04:17:10,880
it right so you can only take top moves
6969
04:17:10,880 --> 04:17:12,319
you can never take number three here
6970
04:17:12,319 --> 04:17:15,920
before the other ones are removed right
6971
04:17:15,920 --> 04:17:17,920
the third rule says that you cannot take
6972
04:17:17,920 --> 04:17:19,439
disk number two and put it on here
6973
04:17:19,439 --> 04:17:21,279
because it's bigger than this one here
6974
04:17:21,279 --> 04:17:22,159
right
6975
04:17:22,159 --> 04:17:24,720
you get it okay
6976
04:17:24,720 --> 04:17:26,159
now
6977
04:17:26,159 --> 04:17:28,560
how do you get from here right
6978
04:17:28,560 --> 04:17:31,120
to here following the three rules
6979
04:17:31,120 --> 04:17:33,199
i encourage you to sit and think about
6980
04:17:33,199 --> 04:17:34,960
it for a moment
6981
04:17:34,960 --> 04:17:38,560
and uh maybe you get an idea but it's
6982
04:17:38,560 --> 04:17:40,159
often difficult to just you know what
6983
04:17:40,159 --> 04:17:41,920
should i do just experiment right and
6984
04:17:41,920 --> 04:17:43,439
that's what most people do experiment i
6985
04:17:43,439 --> 04:17:44,960
think i did that too myself the first
6986
04:17:44,960 --> 04:17:46,399
time i saw it right
6987
04:17:46,399 --> 04:17:48,239
so it's just experimenting with back and
6988
04:17:48,239 --> 04:17:50,239
forth but that's not a good strategy
6989
04:17:50,239 --> 04:17:51,840
right and this is where recursion will
6990
04:17:51,840 --> 04:17:54,159
come into the picture right
6991
04:17:54,159 --> 04:17:55,600
uh
6992
04:17:55,600 --> 04:17:57,359
because it's not easy and
6993
04:17:57,359 --> 04:17:59,040
before we continue also just take a
6994
04:17:59,040 --> 04:18:00,479
moment also
6995
04:18:00,479 --> 04:18:02,479
then imagine that you need to program
6996
04:18:02,479 --> 04:18:03,920
this
6997
04:18:03,920 --> 04:18:05,600
and we're gonna do that in this project
6998
04:18:05,600 --> 04:18:07,199
right but imagine you have to do that
6999
04:18:07,199 --> 04:18:09,520
right now with without any more thinking
7000
04:18:09,520 --> 04:18:11,040
and i'm pretty sure that you're gonna
7001
04:18:11,040 --> 04:18:13,120
get stuck in this one because it's it's
7002
04:18:13,120 --> 04:18:14,479
difficult
7003
04:18:14,479 --> 04:18:15,920
very difficult
7004
04:18:15,920 --> 04:18:19,199
before you know it and then it's easy
7005
04:18:19,199 --> 04:18:22,880
so here's the trick you ready
7006
04:18:22,880 --> 04:18:25,600
how to solve the tower of hanoi
7007
04:18:25,600 --> 04:18:28,000
assume you can solve the smaller problem
7008
04:18:28,000 --> 04:18:31,199
of two disks right
7009
04:18:31,199 --> 04:18:33,439
so basically this is a recursion right
7010
04:18:33,439 --> 04:18:34,640
you solve the
7011
04:18:34,640 --> 04:18:36,640
smaller problem right
7012
04:18:36,640 --> 04:18:38,159
so now we just assume you can solve that
7013
04:18:38,159 --> 04:18:40,080
that's a recursion call remember you
7014
04:18:40,080 --> 04:18:41,920
call down to something that can solve
7015
04:18:41,920 --> 04:18:44,159
the smaller problem and then you solve
7016
04:18:44,159 --> 04:18:45,920
the problem you're in right now so now
7017
04:18:45,920 --> 04:18:48,159
you just make a recursive call and say
7018
04:18:48,159 --> 04:18:50,319
remove the two disks
7019
04:18:50,319 --> 04:18:52,720
remove or move to smaller disk
7020
04:18:52,720 --> 04:18:54,239
then you can move to disk at the same
7021
04:18:54,239 --> 04:18:56,080
time right so that's what you do how
7022
04:18:56,080 --> 04:18:57,840
would you solve it now right so you take
7023
04:18:57,840 --> 04:19:01,120
the two disk and put them here
7024
04:19:01,199 --> 04:19:03,359
and then you move the third disk from
7025
04:19:03,359 --> 04:19:05,520
here to here
7026
04:19:05,520 --> 04:19:07,520
and then you take the smaller problem
7027
04:19:07,520 --> 04:19:10,080
again and move them here
7028
04:19:10,080 --> 04:19:10,880
right
7029
04:19:10,880 --> 04:19:13,279
that's easy because you can
7030
04:19:13,279 --> 04:19:15,359
in recursion you just assume you're
7031
04:19:15,359 --> 04:19:18,000
moving solving the smaller problem right
7032
04:19:18,000 --> 04:19:19,840
just like that with a call and that's
7033
04:19:19,840 --> 04:19:21,920
what recursion does for you
7034
04:19:21,920 --> 04:19:24,319
right did you see that now you actually
7035
04:19:24,319 --> 04:19:26,880
have the recipe of solving it and i know
7036
04:19:26,880 --> 04:19:28,720
at first here it might be a bit complex
7037
04:19:28,720 --> 04:19:29,439
right
7038
04:19:29,439 --> 04:19:32,080
how did he do that but again just
7039
04:19:32,080 --> 04:19:34,239
imagine this is a recursive don't don't
7040
04:19:34,239 --> 04:19:35,760
worry about this one right you take the
7041
04:19:35,760 --> 04:19:38,000
two discs and put them here
7042
04:19:38,000 --> 04:19:39,760
then you take the third disc and put it
7043
04:19:39,760 --> 04:19:40,880
over here
7044
04:19:40,880 --> 04:19:42,880
then you take the two small discs that
7045
04:19:42,880 --> 04:19:44,319
are here and put them here and you have
7046
04:19:44,319 --> 04:19:46,399
solved the problem right
7047
04:19:46,399 --> 04:19:48,880
with that recursive call the recursive
7048
04:19:48,880 --> 04:19:52,239
call does the exact same thing
7049
04:19:54,080 --> 04:19:56,319
so this is the formula and all you need
7050
04:19:56,319 --> 04:19:58,800
to know right move the smaller problem
7051
04:19:58,800 --> 04:20:00,399
of two discs in this case and it could
7052
04:20:00,399 --> 04:20:02,000
be one disc if it's even smaller when
7053
04:20:02,000 --> 04:20:04,000
you call again down there and move them
7054
04:20:04,000 --> 04:20:05,920
from the first rod to the second rod
7055
04:20:05,920 --> 04:20:08,560
move the big disc from the
7056
04:20:08,560 --> 04:20:11,120
first tower to the last tower right and
7057
04:20:11,120 --> 04:20:13,359
then move the smaller problem to this to
7058
04:20:13,359 --> 04:20:14,720
the second
7059
04:20:14,720 --> 04:20:16,560
to the last right from the second to the
7060
04:20:16,560 --> 04:20:18,479
last this is exactly what we did here
7061
04:20:18,479 --> 04:20:20,880
right move the two to here
7062
04:20:20,880 --> 04:20:23,279
move the big one here move the two from
7063
04:20:23,279 --> 04:20:25,199
here right perfect
7064
04:20:25,199 --> 04:20:27,359
now we have the recipe so now we just
7065
04:20:27,359 --> 04:20:29,279
need to use some hints here to do it
7066
04:20:29,279 --> 04:20:30,080
right
7067
04:20:30,080 --> 04:20:31,680
so step one
7068
04:20:31,680 --> 04:20:34,080
represent the towers as a list of lists
7069
04:20:34,080 --> 04:20:36,640
right so you see here we have a list of
7070
04:20:36,640 --> 04:20:40,000
lists and the second list has uh
7071
04:20:40,000 --> 04:20:42,080
disks with numbers representing the
7072
04:20:42,080 --> 04:20:44,239
sizes right and if it's empty there's
7073
04:20:44,239 --> 04:20:45,439
nothing on the rod so this is the
7074
04:20:45,439 --> 04:20:47,680
beginning situation right
7075
04:20:47,680 --> 04:20:49,680
that's step one this is how we represent
7076
04:20:49,680 --> 04:20:50,170
them right
7077
04:20:50,170 --> 04:20:52,239
[Music]
7078
04:20:52,239 --> 04:20:54,560
step two create a move function so we
7079
04:20:54,560 --> 04:20:56,560
create a helper function right a move
7080
04:20:56,560 --> 04:20:59,199
function which takes the towers and move
7081
04:20:59,199 --> 04:21:01,120
a disk from one tower to another tower
7082
04:21:01,120 --> 04:21:01,920
right
7083
04:21:01,920 --> 04:21:04,000
and how do you do that well you can use
7084
04:21:04,000 --> 04:21:06,000
pop and append on these ones here right
7085
04:21:06,000 --> 04:21:09,600
so there'll be a from disk to t from
7086
04:21:09,600 --> 04:21:11,760
tower to a two tower right or something
7087
04:21:11,760 --> 04:21:14,239
like that from tower to tower right and
7088
04:21:14,239 --> 04:21:17,279
then you do a pop and then bend
7089
04:21:17,279 --> 04:21:19,120
then step three make a helper function
7090
04:21:19,120 --> 04:21:20,640
to print the towers and the reason why
7091
04:21:20,640 --> 04:21:23,040
you want to do that is if something goes
7092
04:21:23,040 --> 04:21:24,479
wrong it's also really nice to see how
7093
04:21:24,479 --> 04:21:27,199
it works but also
7094
04:21:27,199 --> 04:21:29,040
if you want to see how it actually moves
7095
04:21:29,040 --> 04:21:31,920
it is really really fun to have and this
7096
04:21:31,920 --> 04:21:33,520
one doesn't have to be fancy it's just
7097
04:21:33,520 --> 04:21:35,840
you know just print it out i'll show you
7098
04:21:35,840 --> 04:21:38,479
how i would do it and it's just
7099
04:21:38,479 --> 04:21:40,080
simple because we're going to assume we
7100
04:21:40,080 --> 04:21:41,680
have three towers and three disks
7101
04:21:41,680 --> 04:21:43,120
because obviously you could have
7102
04:21:43,120 --> 04:21:44,800
multiple disks here and then you have to
7103
04:21:44,800 --> 04:21:46,720
modify this printer function and the
7104
04:21:46,720 --> 04:21:48,239
functionality we do would will work
7105
04:21:48,239 --> 04:21:50,880
whether we have three disk or 10 000
7106
04:21:50,880 --> 04:21:52,399
disks
7107
04:21:52,399 --> 04:21:54,560
okay and then the recursive function
7108
04:21:54,560 --> 04:21:57,600
right solve tower of hanoi we call it
7109
04:21:57,600 --> 04:21:59,680
that it will have the towers these are
7110
04:21:59,680 --> 04:22:02,080
the towers here then they have n i'll
7111
04:22:02,080 --> 04:22:04,399
come back to n then that'll start tower
7112
04:22:04,399 --> 04:22:06,880
destination tower and auxiliary tower
7113
04:22:06,880 --> 04:22:09,439
right so what do that
7114
04:22:09,439 --> 04:22:11,680
what does that mean right
7115
04:22:11,680 --> 04:22:13,840
so if we are here in the beginning
7116
04:22:13,840 --> 04:22:15,439
here right
7117
04:22:15,439 --> 04:22:17,120
then we have a
7118
04:22:17,120 --> 04:22:19,279
what you want is we want this is the
7119
04:22:19,279 --> 04:22:22,720
from tower and this is a two tower right
7120
04:22:22,720 --> 04:22:24,720
and then we have an auxiliary tower here
7121
04:22:24,720 --> 04:22:25,520
right
7122
04:22:25,520 --> 04:22:26,960
and the end is
7123
04:22:26,960 --> 04:22:29,600
how many disks we are having in this
7124
04:22:29,600 --> 04:22:31,279
recursive call right
7125
04:22:31,279 --> 04:22:33,840
perfect
7126
04:22:35,120 --> 04:22:36,560
perfect right
7127
04:22:36,560 --> 04:22:38,399
so n is the number of disks we move
7128
04:22:38,399 --> 04:22:40,000
starting with three and then the cursor
7129
04:22:40,000 --> 04:22:42,479
called down to one and zero right
7130
04:22:42,479 --> 04:22:45,040
the base case is n0 then just return to
7131
04:22:45,040 --> 04:22:46,640
that case and we don't do anything right
7132
04:22:46,640 --> 04:22:48,880
because in this case we don't need to
7133
04:22:48,880 --> 04:22:50,960
have a start tower destination tower or
7134
04:22:50,960 --> 04:22:52,399
auxiliary tower we don't do anything
7135
04:22:52,399 --> 04:22:53,920
because there are no disks to move right
7136
04:22:53,920 --> 04:22:55,520
if we had one disk we needed to move
7137
04:22:55,520 --> 04:22:57,439
from the start tower to destination
7138
04:22:57,439 --> 04:22:59,600
tower right
7139
04:22:59,600 --> 04:23:00,399
good
7140
04:23:00,399 --> 04:23:01,600
and uh
7141
04:23:01,600 --> 04:23:03,840
what we do then in our recursive call is
7142
04:23:03,840 --> 04:23:05,760
remove the sub problem for n minus one
7143
04:23:05,760 --> 04:23:07,680
disk right in this case we take two
7144
04:23:07,680 --> 04:23:08,720
disks
7145
04:23:08,720 --> 04:23:11,600
uh from the start tower to the axillary
7146
04:23:11,600 --> 04:23:14,800
tower right and then you move the disk n
7147
04:23:14,800 --> 04:23:17,120
to destination tower right
7148
04:23:17,120 --> 04:23:18,880
and if you want you can do the calling a
7149
04:23:18,880 --> 04:23:20,800
print function right after this one it's
7150
04:23:20,800 --> 04:23:22,239
going to be look nice
7151
04:23:22,239 --> 04:23:24,239
and then finally we move the sub problem
7152
04:23:24,239 --> 04:23:26,399
of n minus one disk from auxiliary tower
7153
04:23:26,399 --> 04:23:29,040
to destination tower wow this sounds too
7154
04:23:29,040 --> 04:23:30,640
easy and it is this is exactly what you
7155
04:23:30,640 --> 04:23:33,840
need to do but it takes time
7156
04:23:33,840 --> 04:23:35,439
to figure it out
7157
04:23:35,439 --> 04:23:37,439
i encourage you to spend some time
7158
04:23:37,439 --> 04:23:39,920
solving this it's it's amazing problem
7159
04:23:39,920 --> 04:23:41,279
and you're going to feel awesome when
7160
04:23:41,279 --> 04:23:43,120
you solve it and don't worry if you
7161
04:23:43,120 --> 04:23:44,159
don't really
7162
04:23:44,159 --> 04:23:47,120
get it finally well
7163
04:23:47,120 --> 04:23:50,000
jump along to my video the next one here
7164
04:23:50,000 --> 04:23:52,319
and then we'll solve it together okay
7165
04:23:52,319 --> 04:23:55,720
see you in a moment
7166
04:23:57,600 --> 04:24:00,080
are you ready for this i hope so and i
7167
04:24:00,080 --> 04:24:01,680
hope you try to play around with it
7168
04:24:01,680 --> 04:24:03,920
because it's gonna pay off remember
7169
04:24:03,920 --> 04:24:06,880
again your learning is the mo you get
7170
04:24:06,880 --> 04:24:08,640
the most out of this if you try to play
7171
04:24:08,640 --> 04:24:10,720
with play around with it before you see
7172
04:24:10,720 --> 04:24:12,800
the solution and don't worry you will
7173
04:24:12,800 --> 04:24:13,760
learn
7174
04:24:13,760 --> 04:24:15,359
even though you didn't solve it yourself
7175
04:24:15,359 --> 04:24:16,800
because now you see how to do it and
7176
04:24:16,800 --> 04:24:18,560
then i still encourage you to do it
7177
04:24:18,560 --> 04:24:21,279
afterwards again actually because
7178
04:24:21,279 --> 04:24:22,720
sometimes you need to have multiple
7179
04:24:22,720 --> 04:24:25,199
times and it doesn't mean that
7180
04:24:25,199 --> 04:24:26,800
you will never get good at programming
7181
04:24:26,800 --> 04:24:28,479
me personally i've done things that i
7182
04:24:28,479 --> 04:24:30,319
didn't get i had to do it redo it again
7183
04:24:30,319 --> 04:24:32,159
and again and again and it took long
7184
04:24:32,159 --> 04:24:33,920
time before i got it but the key thing
7185
04:24:33,920 --> 04:24:36,239
is to continue until you get it right
7186
04:24:36,239 --> 04:24:38,319
perfect are you ready let's jump to
7187
04:24:38,319 --> 04:24:40,880
jupiter notebook so we are right down
7188
04:24:40,880 --> 04:24:44,000
here at the tower of hanoi here right
7189
04:24:44,000 --> 04:24:45,760
starting of that and we're at the end
7190
04:24:45,760 --> 04:24:48,000
here where we just need to implement it
7191
04:24:48,000 --> 04:24:50,399
in the last part we went through how to
7192
04:24:50,399 --> 04:24:51,840
describe
7193
04:24:51,840 --> 04:24:54,560
understand it so we jump straight right
7194
04:24:54,560 --> 04:24:56,720
right into solving the problem
7195
04:24:56,720 --> 04:24:59,199
good so at step one here we need to
7196
04:24:59,199 --> 04:25:01,359
represent the towers as follows right so
7197
04:25:01,359 --> 04:25:03,040
let's just do that let's just copy it
7198
04:25:03,040 --> 04:25:05,520
down here
7199
04:25:05,840 --> 04:25:07,439
towers we just call it and then we have
7200
04:25:07,439 --> 04:25:10,239
the towers like that and uh as you see
7201
04:25:10,239 --> 04:25:12,000
you can just see the towers like that
7202
04:25:12,000 --> 04:25:14,960
it's just list of lists right so
7203
04:25:14,960 --> 04:25:18,399
in theory if you wanted the first
7204
04:25:18,399 --> 04:25:21,520
rod or tower you can just access it like
7205
04:25:21,520 --> 04:25:23,760
this and the second one like this is
7206
04:25:23,760 --> 04:25:26,000
empty and the third one is here right so
7207
04:25:26,000 --> 04:25:27,920
the goal is to move them all from one to
7208
04:25:27,920 --> 04:25:29,680
the other right so this is step one
7209
04:25:29,680 --> 04:25:31,279
that's pretty easy right
7210
04:25:31,279 --> 04:25:32,880
then we need to create a move function
7211
04:25:32,880 --> 04:25:36,159
which takes the towers and
7212
04:25:36,159 --> 04:25:38,399
moves a disk from one tower to another
7213
04:25:38,399 --> 04:25:41,600
tower so let's try to do that right
7214
04:25:41,600 --> 04:25:42,880
so def
7215
04:25:42,880 --> 04:25:44,800
move we just call it and it takes the
7216
04:25:44,800 --> 04:25:48,399
towers and then just call it from tower
7217
04:25:48,399 --> 04:25:51,600
to destination tower right
7218
04:25:51,600 --> 04:25:53,279
let's just call it like that
7219
04:25:53,279 --> 04:25:55,199
and this function here
7220
04:25:55,199 --> 04:25:57,120
it just assumes we're not doing anything
7221
04:25:57,120 --> 04:26:00,880
illegal because if we are
7222
04:26:01,199 --> 04:26:02,720
yeah we are
7223
04:26:02,720 --> 04:26:05,279
either we do a move it's not possible
7224
04:26:05,279 --> 04:26:07,920
which is uh making an exception if it's
7225
04:26:07,920 --> 04:26:10,239
an empty list we take from or not or we
7226
04:26:10,239 --> 04:26:12,720
make a put a bigger one or a smaller one
7227
04:26:12,720 --> 04:26:14,239
but we can make a print function so we
7228
04:26:14,239 --> 04:26:17,520
can verify we don't do that okay
7229
04:26:17,520 --> 04:26:19,520
okay let's start so
7230
04:26:19,520 --> 04:26:22,080
how can we do that right so
7231
04:26:22,080 --> 04:26:23,680
we need to
7232
04:26:23,680 --> 04:26:26,960
take a disk from the from tower right so
7233
04:26:26,960 --> 04:26:28,960
let's do that so
7234
04:26:28,960 --> 04:26:30,560
towers
7235
04:26:30,560 --> 04:26:32,159
and then we take
7236
04:26:32,159 --> 04:26:34,159
from
7237
04:26:34,159 --> 04:26:35,120
tower
7238
04:26:35,120 --> 04:26:37,279
and we do a pop on that one right so it
7239
04:26:37,279 --> 04:26:39,840
takes the last element and then we need
7240
04:26:39,840 --> 04:26:43,600
the towers and then we do
7241
04:26:43,600 --> 04:26:46,239
destination
7242
04:26:46,239 --> 04:26:48,880
tower and then we just appended right
7243
04:26:48,880 --> 04:26:51,600
the disk here right so this is basically
7244
04:26:51,600 --> 04:26:53,439
it and and
7245
04:26:53,439 --> 04:26:56,720
it is a list but i really often like to
7246
04:26:56,720 --> 04:26:59,279
return it as well
7247
04:26:59,279 --> 04:27:01,680
strictly speaking it's not necessary but
7248
04:27:01,680 --> 04:27:03,840
uh then you have like uh
7249
04:27:03,840 --> 04:27:05,439
then you can just like
7250
04:27:05,439 --> 04:27:07,120
i think the syntax is easier to
7251
04:27:07,120 --> 04:27:08,720
understand so you don't get confused
7252
04:27:08,720 --> 04:27:09,920
whether
7253
04:27:09,920 --> 04:27:12,880
you do something different with towers
7254
04:27:12,880 --> 04:27:13,680
right
7255
04:27:13,680 --> 04:27:15,840
so let's let's just try there right so
7256
04:27:15,840 --> 04:27:17,439
towers
7257
04:27:17,439 --> 04:27:20,319
move and we take it from uh
7258
04:27:20,319 --> 04:27:22,560
and take the towers there and we take it
7259
04:27:22,560 --> 04:27:26,000
from zero to two right boom and now we
7260
04:27:26,000 --> 04:27:28,640
can look at the towers we have the one
7261
04:27:28,640 --> 04:27:30,960
the smallest one so we took the smallest
7262
04:27:30,960 --> 04:27:33,600
one and added over there right
7263
04:27:33,600 --> 04:27:34,560
so
7264
04:27:34,560 --> 04:27:37,760
again we can just move it back towers
7265
04:27:37,760 --> 04:27:40,159
and we take two to zero right and then
7266
04:27:40,159 --> 04:27:42,000
we have towers here and it's back to
7267
04:27:42,000 --> 04:27:44,399
normal right perfect so far so good
7268
04:27:44,399 --> 04:27:48,159
right that was step two
7269
04:27:48,159 --> 04:27:49,840
step three make a helper function to
7270
04:27:49,840 --> 04:27:51,600
print the towers hint assume we have
7271
04:27:51,600 --> 04:27:53,359
three towers and three disks right so
7272
04:27:53,359 --> 04:27:56,000
don't try to over complicate this
7273
04:27:56,000 --> 04:27:57,760
function here it's just to help you
7274
04:27:57,760 --> 04:28:00,960
right def so let's call it print towers
7275
04:28:00,960 --> 04:28:03,920
right and then take towers here right
7276
04:28:03,920 --> 04:28:05,840
perfect
7277
04:28:05,840 --> 04:28:08,239
perfect perfect perfect
7278
04:28:08,239 --> 04:28:10,399
so for i in
7279
04:28:10,399 --> 04:28:12,640
range and
7280
04:28:12,640 --> 04:28:14,960
what do we want here we want to
7281
04:28:14,960 --> 04:28:16,239
print
7282
04:28:16,239 --> 04:28:17,279
the three
7283
04:28:17,279 --> 04:28:19,279
the three towers
7284
04:28:19,279 --> 04:28:21,199
and we can actually do it we want to
7285
04:28:21,199 --> 04:28:23,199
print it from the top right so at the
7286
04:28:23,199 --> 04:28:25,279
top we have the top one so let's
7287
04:28:25,279 --> 04:28:26,960
actually do a
7288
04:28:26,960 --> 04:28:27,920
a
7289
04:28:27,920 --> 04:28:29,199
how is it called
7290
04:28:29,199 --> 04:28:31,920
a negative count here and you probably
7291
04:28:31,920 --> 04:28:33,760
didn't see that
7292
04:28:33,760 --> 04:28:36,080
here but you can actually start from
7293
04:28:36,080 --> 04:28:37,920
three here and count down to zero
7294
04:28:37,920 --> 04:28:40,880
exclusive and then the step is minus
7295
04:28:40,880 --> 04:28:43,840
one right so if we actually print i here
7296
04:28:43,840 --> 04:28:47,520
you see here that if we called
7297
04:28:47,520 --> 04:28:49,520
print towers
7298
04:28:49,520 --> 04:28:51,920
and we need something here towers here
7299
04:28:51,920 --> 04:28:54,239
we'll go three one
7300
04:28:54,239 --> 04:28:57,920
three two one right
7301
04:28:57,920 --> 04:28:59,439
i don't actually know if this is the
7302
04:28:59,439 --> 04:29:01,120
best thing we're doing right now but
7303
04:29:01,120 --> 04:29:05,199
let's just do it like this okay
7304
04:29:05,199 --> 04:29:06,399
so for
7305
04:29:06,399 --> 04:29:10,159
so for tower in towers right so what
7306
04:29:10,159 --> 04:29:12,159
we're going to do is now we take each of
7307
04:29:12,159 --> 04:29:14,720
the towers right first this one this one
7308
04:29:14,720 --> 04:29:18,239
this one what we want to know is if the
7309
04:29:18,239 --> 04:29:20,960
length of tower
7310
04:29:20,960 --> 04:29:23,439
is larger than this i value because in
7311
04:29:23,439 --> 04:29:26,319
this case we know that in the first case
7312
04:29:26,319 --> 04:29:28,479
it's three we know we have three items
7313
04:29:28,479 --> 04:29:30,479
in it right what do we need to print
7314
04:29:30,479 --> 04:29:34,080
then we need to print that item right
7315
04:29:34,080 --> 04:29:35,920
and how do we print that item that's
7316
04:29:35,920 --> 04:29:38,159
tower but we want to print it from the
7317
04:29:38,159 --> 04:29:39,439
reverse
7318
04:29:39,439 --> 04:29:40,800
order right
7319
04:29:40,800 --> 04:29:43,120
or do we no we don't we don't we want to
7320
04:29:43,120 --> 04:29:45,359
print it from so we actually want to
7321
04:29:45,359 --> 04:29:47,680
print from i minus one right so if we
7322
04:29:47,680 --> 04:29:49,600
have that number of elements we want to
7323
04:29:49,600 --> 04:29:51,359
print the element before right that's
7324
04:29:51,359 --> 04:29:53,439
how it is and this should also be equal
7325
04:29:53,439 --> 04:29:54,640
to right
7326
04:29:54,640 --> 04:29:57,040
and then we want an end here and we just
7327
04:29:57,040 --> 04:29:59,840
use space here to have that right and
7328
04:29:59,840 --> 04:30:02,239
else what do you want to print else we
7329
04:30:02,239 --> 04:30:04,960
print just something here i don't know
7330
04:30:04,960 --> 04:30:06,880
should we print a pipe
7331
04:30:06,880 --> 04:30:10,080
and end here and
7332
04:30:10,080 --> 04:30:13,040
also need a spacer and after this one we
7333
04:30:13,040 --> 04:30:15,199
need to print a new line here right so i
7334
04:30:15,199 --> 04:30:17,520
think this should actually do it right
7335
04:30:17,520 --> 04:30:20,880
and we can also just for the fun of it
7336
04:30:20,880 --> 04:30:22,000
print a
7337
04:30:22,000 --> 04:30:24,720
base here
7338
04:30:26,000 --> 04:30:27,520
and i think they should do it right so
7339
04:30:27,520 --> 04:30:29,600
we kind of have like the base here
7340
04:30:29,600 --> 04:30:30,960
and uh
7341
04:30:30,960 --> 04:30:35,439
yeah i think maybe this is one too much
7342
04:30:35,439 --> 04:30:37,600
i think this is fine
7343
04:30:37,600 --> 04:30:40,880
i mean maybe we actually want a space in
7344
04:30:40,880 --> 04:30:44,720
front of this i don't do we want that
7345
04:30:44,800 --> 04:30:46,319
i think this is fine i think we just do
7346
04:30:46,319 --> 04:30:49,439
it like this right so
7347
04:30:50,239 --> 04:30:53,120
is there a space coming too much here
7348
04:30:53,120 --> 04:30:54,399
one two
7349
04:30:54,399 --> 04:30:56,560
one two three i think so so where does
7350
04:30:56,560 --> 04:30:58,880
this extra space come from oh i added
7351
04:30:58,880 --> 04:31:01,520
these spaces here that's why
7352
04:31:01,520 --> 04:31:04,080
okay now it's like this here
7353
04:31:04,080 --> 04:31:06,080
and um
7354
04:31:06,080 --> 04:31:06,960
yeah
7355
04:31:06,960 --> 04:31:10,279
good question
7356
04:31:11,120 --> 04:31:13,120
perfect
7357
04:31:13,120 --> 04:31:14,960
perfect here we have a visualization of
7358
04:31:14,960 --> 04:31:17,520
the towers it's not nice it's not pretty
7359
04:31:17,520 --> 04:31:19,920
but uh yeah maybe we just add an
7360
04:31:19,920 --> 04:31:22,159
additional space here right boom boom
7361
04:31:22,159 --> 04:31:24,560
boom yeah i don't know you can play
7362
04:31:24,560 --> 04:31:26,159
around with it
7363
04:31:26,159 --> 04:31:27,600
honestly it's just to show you how it
7364
04:31:27,600 --> 04:31:29,359
looks like it doesn't really matter that
7365
04:31:29,359 --> 04:31:31,359
much okay that was step
7366
04:31:31,359 --> 04:31:32,640
step
7367
04:31:32,640 --> 04:31:35,120
three right so step four
7368
04:31:35,120 --> 04:31:37,680
the recursive function right so this is
7369
04:31:37,680 --> 04:31:40,960
actually all we need to do right so what
7370
04:31:40,960 --> 04:31:44,080
i'm going to do now is just to copy this
7371
04:31:44,080 --> 04:31:46,960
step here down actually we just move all
7372
04:31:46,960 --> 04:31:49,040
the text down there let's just do that
7373
04:31:49,040 --> 04:31:51,199
because what i want to do is actually
7374
04:31:51,199 --> 04:31:55,359
have it when i write the code because
7375
04:31:59,040 --> 04:32:01,439
because
7376
04:32:01,520 --> 04:32:05,600
here we have it right so let's do this
7377
04:32:05,600 --> 04:32:07,439
function here and we just copy that
7378
04:32:07,439 --> 04:32:09,840
right so def here right
7379
04:32:09,840 --> 04:32:12,319
perfect this is what we want to do so n
7380
04:32:12,319 --> 04:32:14,000
is the number of disks we move right so
7381
04:32:14,000 --> 04:32:15,840
the base case is this one here that
7382
04:32:15,840 --> 04:32:18,000
means actually so if n
7383
04:32:18,000 --> 04:32:20,880
is equal equals zero we can also
7384
04:32:20,880 --> 04:32:22,720
sometimes just to make sure it doesn't
7385
04:32:22,720 --> 04:32:25,279
matter here equal to zero we just return
7386
04:32:25,279 --> 04:32:28,000
as it says right
7387
04:32:28,000 --> 04:32:29,840
and then we have this case here right
7388
04:32:29,840 --> 04:32:32,080
and remember we can put comments in the
7389
04:32:32,080 --> 04:32:35,840
code like this if you want is this
7390
04:32:35,840 --> 04:32:38,319
hash symbol here
7391
04:32:38,319 --> 04:32:40,399
this will not be executed right
7392
04:32:40,399 --> 04:32:42,239
then actually we
7393
04:32:42,239 --> 04:32:45,439
do the same we call the same function
7394
04:32:45,439 --> 04:32:48,080
here but now we need to be strict right
7395
04:32:48,080 --> 04:32:50,159
so we call it with towers again but we
7396
04:32:50,159 --> 04:32:52,399
call this with n minus
7397
04:32:52,399 --> 04:32:54,000
one obviously because it's a smaller
7398
04:32:54,000 --> 04:32:56,640
problem and then we take the disk from
7399
04:32:56,640 --> 04:33:00,720
start tower to auxiliary tower right so
7400
04:33:00,720 --> 04:33:04,640
this is actually what we do
7401
04:33:06,320 --> 04:33:08,480
here right
7402
04:33:08,480 --> 04:33:10,160
perfect right so we switch those two
7403
04:33:10,160 --> 04:33:11,438
around right
7404
04:33:11,438 --> 04:33:13,438
and then we do
7405
04:33:13,438 --> 04:33:16,919
this one here
7406
04:33:18,160 --> 04:33:19,438
you see
7407
04:33:19,438 --> 04:33:21,520
then we move the disk right so this is
7408
04:33:21,520 --> 04:33:24,000
where we actually do the move here right
7409
04:33:24,000 --> 04:33:26,719
so we do move the towers
7410
04:33:26,719 --> 04:33:30,279
and then we take
7411
04:33:30,639 --> 04:33:33,119
from
7412
04:33:33,599 --> 04:33:36,480
start tower
7413
04:33:36,480 --> 04:33:38,160
to destination
7414
04:33:38,160 --> 04:33:42,000
tower right so this is basically what we
7415
04:33:42,000 --> 04:33:44,320
have been looking for right so we move
7416
04:33:44,320 --> 04:33:46,480
the smaller problem so this one here it
7417
04:33:46,480 --> 04:33:49,278
moves a smaller problem from start tower
7418
04:33:49,278 --> 04:33:51,840
to auxiliary tower right this is what we
7419
04:33:51,840 --> 04:33:52,799
do
7420
04:33:52,799 --> 04:33:54,959
in
7421
04:33:55,599 --> 04:33:57,278
this one here we take the smaller
7422
04:33:57,278 --> 04:33:59,039
problem put the auxiliary tower and then
7423
04:33:59,039 --> 04:34:00,561
the next one is we take number three
7424
04:34:00,561 --> 04:34:02,719
here the big one and moves in over here
7425
04:34:02,719 --> 04:34:04,400
right
7426
04:34:04,400 --> 04:34:06,639
these are these two steps right
7427
04:34:06,639 --> 04:34:08,480
and then
7428
04:34:08,480 --> 04:34:12,439
let me do this one here
7429
04:34:13,840 --> 04:34:16,719
let's see if we can do it correctly now
7430
04:34:16,719 --> 04:34:19,359
and again we have a smaller problem and
7431
04:34:19,359 --> 04:34:24,240
then we take it from auxiliary tower to
7432
04:34:25,520 --> 04:34:27,919
auxiliary tower
7433
04:34:27,919 --> 04:34:29,438
and we take
7434
04:34:29,438 --> 04:34:32,399
start tower
7435
04:34:32,879 --> 04:34:35,520
no this is destination tower we need it
7436
04:34:35,520 --> 04:34:37,759
too and then we use start tower as an
7437
04:34:37,759 --> 04:34:39,438
auxiliary right
7438
04:34:39,438 --> 04:34:40,639
start
7439
04:34:40,639 --> 04:34:42,480
tower here right
7440
04:34:42,480 --> 04:34:44,799
perfect right because we can use we can
7441
04:34:44,799 --> 04:34:48,000
put something on top of that right
7442
04:34:48,000 --> 04:34:50,160
awesome and then it actually said here
7443
04:34:50,160 --> 04:34:52,000
we could have print
7444
04:34:52,000 --> 04:34:55,799
towers here right
7445
04:34:56,320 --> 04:34:57,599
towers
7446
04:34:57,599 --> 04:34:59,520
are you ready to try this
7447
04:34:59,520 --> 04:35:01,039
i'm not
7448
04:35:01,039 --> 04:35:02,160
okay so
7449
04:35:02,160 --> 04:35:03,438
towers
7450
04:35:03,438 --> 04:35:05,278
let's just put them here so we know we
7451
04:35:05,278 --> 04:35:08,639
have them correctly
7452
04:35:08,639 --> 04:35:10,719
nothing more annoying than not having
7453
04:35:10,719 --> 04:35:12,240
them correctly
7454
04:35:12,240 --> 04:35:16,080
and then we call this function here
7455
04:35:16,799 --> 04:35:18,561
and
7456
04:35:18,561 --> 04:35:21,199
what we're going to do is
7457
04:35:21,199 --> 04:35:24,320
yeah let's just print
7458
04:35:24,320 --> 04:35:26,958
towers here
7459
04:35:26,958 --> 04:35:28,400
towers
7460
04:35:28,400 --> 04:35:29,919
and then we take the towers we take
7461
04:35:29,919 --> 04:35:32,160
number three here start tower zero
7462
04:35:32,160 --> 04:35:34,799
destination tower is two auxiliary
7463
04:35:34,799 --> 04:35:37,759
towers one right so let's try to do that
7464
04:35:37,759 --> 04:35:39,680
so first we start by
7465
04:35:39,680 --> 04:35:41,199
printing the tower and let's look at the
7466
04:35:41,199 --> 04:35:43,680
end we have the correct solution here in
7467
04:35:43,680 --> 04:35:45,840
the end right we have all the three uh
7468
04:35:45,840 --> 04:35:48,240
disks here right so what it does along
7469
04:35:48,240 --> 04:35:51,278
the way right it just takes here
7470
04:35:51,278 --> 04:35:54,000
so the first call it does is it calls
7471
04:35:54,000 --> 04:35:56,958
recursively down on this one here so it
7472
04:35:56,958 --> 04:35:59,520
calls with two right and when calls with
7473
04:35:59,520 --> 04:36:01,680
two it starts and this start here again
7474
04:36:01,680 --> 04:36:03,199
and then it calls with
7475
04:36:03,199 --> 04:36:05,599
one here and when calls one here calls
7476
04:36:05,599 --> 04:36:08,000
with zero here and zero returns so then
7477
04:36:08,000 --> 04:36:10,639
it returns with one right and then we do
7478
04:36:10,639 --> 04:36:12,639
the actual move so the first move we do
7479
04:36:12,639 --> 04:36:14,958
is that move here right
7480
04:36:14,958 --> 04:36:16,400
so we move
7481
04:36:16,400 --> 04:36:19,359
this one here then we move this two here
7482
04:36:19,359 --> 04:36:22,320
then we remove move disc one back right
7483
04:36:22,320 --> 04:36:25,039
so this is the recursive method right
7484
04:36:25,039 --> 04:36:27,118
and then we're back to the next layer
7485
04:36:27,118 --> 04:36:29,118
recursive move the three here and then
7486
04:36:29,118 --> 04:36:31,118
we are back in the recursive move one
7487
04:36:31,118 --> 04:36:34,080
here and then two here and then one in
7488
04:36:34,080 --> 04:36:36,240
the end over here right
7489
04:36:36,240 --> 04:36:38,160
you see
7490
04:36:38,160 --> 04:36:40,480
i highly encourage you to check it out
7491
04:36:40,480 --> 04:36:42,080
again here it is
7492
04:36:42,080 --> 04:36:44,080
i know it's a bit confusing at first
7493
04:36:44,080 --> 04:36:46,879
when you see it but it's amazing
7494
04:36:46,879 --> 04:36:48,799
and
7495
04:36:48,799 --> 04:36:51,759
it's magic to be honest it's magic but
7496
04:36:51,759 --> 04:36:53,438
again you see
7497
04:36:53,438 --> 04:36:55,199
the mindset you need to have is just
7498
04:36:55,199 --> 04:36:58,000
thinking how can i solve it if i can
7499
04:36:58,000 --> 04:37:00,400
solve a smaller instance can i then
7500
04:37:00,400 --> 04:37:02,400
solve it and yes i can and then you just
7501
04:37:02,400 --> 04:37:04,799
call down and then you need a base case
7502
04:37:04,799 --> 04:37:06,799
right and then it's salted right this
7503
04:37:06,799 --> 04:37:08,799
recipe is quite simple just sit and
7504
04:37:08,799 --> 04:37:11,118
think how you would solve it without
7505
04:37:11,118 --> 04:37:13,359
recursion now right it'll be complex it
7506
04:37:13,359 --> 04:37:15,438
is possible but complex
7507
04:37:15,438 --> 04:37:18,000
so are you excited i hope so this was
7508
04:37:18,000 --> 04:37:21,760
amazing see you in the next one
7509
04:37:24,320 --> 04:37:26,719
list comprehension right people love
7510
04:37:26,719 --> 04:37:29,359
this aspect about python and i do
7511
04:37:29,359 --> 04:37:31,039
understand why because it makes your
7512
04:37:31,039 --> 04:37:33,278
program more readable
7513
04:37:33,278 --> 04:37:35,599
if you understand them right and again
7514
04:37:35,599 --> 04:37:37,438
if you're on a level where you don't
7515
04:37:37,438 --> 04:37:39,039
really understand this comprehension it
7516
04:37:39,039 --> 04:37:41,278
doesn't make your code more readable but
7517
04:37:41,278 --> 04:37:44,480
your goal is to be able to comprehend
7518
04:37:44,480 --> 04:37:46,799
this comprehension right enough talking
7519
04:37:46,799 --> 04:37:48,719
let's let's jump to jupiter notebook and
7520
04:37:48,719 --> 04:37:51,199
see what these comprehensions are both
7521
04:37:51,199 --> 04:37:52,879
list and dictionary
7522
04:37:52,879 --> 04:37:54,240
here we are
7523
04:37:54,240 --> 04:37:56,320
comprehension the goal is what is a
7524
04:37:56,320 --> 04:37:58,480
comprehension learn list comprehension
7525
04:37:58,480 --> 04:38:00,639
and learn dictionary comprehension both
7526
04:38:00,639 --> 04:38:02,400
are awesome so
7527
04:38:02,400 --> 04:38:04,879
get ready for this
7528
04:38:04,879 --> 04:38:06,000
okay
7529
04:38:06,000 --> 04:38:07,840
the best way just to see it is just to
7530
04:38:07,840 --> 04:38:10,000
see an example and see how you do it
7531
04:38:10,000 --> 04:38:12,160
with a normal code right so let's make
7532
04:38:12,160 --> 04:38:13,520
my list here
7533
04:38:13,520 --> 04:38:15,680
and like make a list comprehension so
7534
04:38:15,680 --> 04:38:17,840
this comprehension is basically
7535
04:38:17,840 --> 04:38:19,278
you do
7536
04:38:19,278 --> 04:38:21,118
write some code inside here that does
7537
04:38:21,118 --> 04:38:26,240
things for you right so i for i in range
7538
04:38:26,240 --> 04:38:28,160
let's just take 10 right
7539
04:38:28,160 --> 04:38:30,400
so what does this do right
7540
04:38:30,400 --> 04:38:32,240
well if you let's just try to read it
7541
04:38:32,240 --> 04:38:33,199
and guess
7542
04:38:33,199 --> 04:38:37,438
i for i in range 10 right so i in for i
7543
04:38:37,438 --> 04:38:39,840
enraged 10 that means that i is
7544
04:38:39,840 --> 04:38:43,039
incremented from 0 all the way up to
7545
04:38:43,039 --> 04:38:45,278
10 exclusive right
7546
04:38:45,278 --> 04:38:46,400
so
7547
04:38:46,400 --> 04:38:50,561
maybe that's what i is i for i n right
7548
04:38:50,561 --> 04:38:53,840
let's try to see it
7549
04:38:55,520 --> 04:38:58,561
execute yeah that's what it did right
7550
04:38:58,561 --> 04:38:59,359
so
7551
04:38:59,359 --> 04:39:01,199
this is nice but let's just think about
7552
04:39:01,199 --> 04:39:03,278
it how would we do this if we didn't
7553
04:39:03,278 --> 04:39:05,520
have this comprehension we can do that
7554
04:39:05,520 --> 04:39:07,919
right so you can make empty list here
7555
04:39:07,919 --> 04:39:11,759
and then you would say for i in range 10
7556
04:39:11,759 --> 04:39:15,039
and then you would say my list
7557
04:39:15,039 --> 04:39:17,438
my list
7558
04:39:17,438 --> 04:39:18,840
append
7559
04:39:18,840 --> 04:39:21,840
i right this is how you would do it
7560
04:39:21,840 --> 04:39:23,919
right because now you have my list here
7561
04:39:23,919 --> 04:39:24,719
is
7562
04:39:24,719 --> 04:39:27,199
the same here right
7563
04:39:27,199 --> 04:39:29,278
so basically what you have done here in
7564
04:39:29,278 --> 04:39:31,359
this comprehension is taking this one
7565
04:39:31,359 --> 04:39:33,840
here and folded it inside here so you
7566
04:39:33,840 --> 04:39:36,561
avoid creating an empty list out here
7567
04:39:36,561 --> 04:39:38,240
and appending to it it appends
7568
04:39:38,240 --> 04:39:40,638
automatically inside the list right so
7569
04:39:40,638 --> 04:39:43,200
this is one way to use it another way is
7570
04:39:43,200 --> 04:39:44,400
actually you could also make
7571
04:39:44,400 --> 04:39:46,560
calculations inside there so actually if
7572
04:39:46,560 --> 04:39:48,560
you take the same thing here let's just
7573
04:39:48,560 --> 04:39:51,360
use mice list again here then you say i
7574
04:39:51,360 --> 04:39:55,440
times i for instance for i in range
7575
04:39:55,440 --> 04:39:56,798
10 again right
7576
04:39:56,798 --> 04:39:58,958
so in this case here
7577
04:39:58,958 --> 04:40:00,160
what you've done here is just
7578
04:40:00,160 --> 04:40:03,200
multiplying i zero is zero zero times
7579
04:40:03,200 --> 04:40:05,440
zero is zero one times one is one two
7580
04:40:05,440 --> 04:40:08,160
times two is four three times three is
7581
04:40:08,160 --> 04:40:09,120
nine
7582
04:40:09,120 --> 04:40:11,120
four times four is sixteen and so forth
7583
04:40:11,120 --> 04:40:13,920
up all the way to nine times nine is
7584
04:40:13,920 --> 04:40:18,320
eighty nine so you see you can also make
7585
04:40:18,320 --> 04:40:19,680
something in here and you can make it
7586
04:40:19,680 --> 04:40:22,320
even more advanced actually
7587
04:40:22,320 --> 04:40:24,958
and similar you could do the same here
7588
04:40:24,958 --> 04:40:28,000
just multiply by multiply here right so
7589
04:40:28,000 --> 04:40:30,718
this is basically it so i want to
7590
04:40:30,718 --> 04:40:32,638
emphasize here that here you could also
7591
04:40:32,638 --> 04:40:34,798
have a formula if you wanted to but it's
7592
04:40:34,798 --> 04:40:36,480
not needed
7593
04:40:36,480 --> 04:40:37,360
good
7594
04:40:37,360 --> 04:40:38,160
but
7595
04:40:38,160 --> 04:40:40,480
what if you probably say
7596
04:40:40,480 --> 04:40:43,360
what if i only wanted every
7597
04:40:43,360 --> 04:40:45,760
all the even numbers right
7598
04:40:45,760 --> 04:40:47,840
you wanted to do something if statement
7599
04:40:47,840 --> 04:40:50,480
right well my list can do that or this
7600
04:40:50,480 --> 04:40:52,878
comprehension can do that as well right
7601
04:40:52,878 --> 04:40:57,200
so here we have i for i in range
7602
04:40:57,200 --> 04:40:58,638
10
7603
04:40:58,638 --> 04:41:00,878
if
7604
04:41:00,878 --> 04:41:02,400
i
7605
04:41:02,400 --> 04:41:05,280
percentage two equals e
7606
04:41:05,280 --> 04:41:06,958
equals equals zero right so what does
7607
04:41:06,958 --> 04:41:09,920
this do let's just see it first
7608
04:41:09,920 --> 04:41:12,638
it takes all the even numbers right 2
7609
04:41:12,638 --> 04:41:15,600
0 2 4 8 6 8.
7610
04:41:15,600 --> 04:41:18,400
so what this statement here does it
7611
04:41:18,400 --> 04:41:20,320
actually says we do the same here thing
7612
04:41:20,320 --> 04:41:23,440
but only if this is true right
7613
04:41:23,440 --> 04:41:24,718
so it's kind of
7614
04:41:24,718 --> 04:41:26,560
i don't know if it's logical syntax this
7615
04:41:26,560 --> 04:41:29,600
one here but if you read it i
7616
04:41:29,600 --> 04:41:33,840
for i in range if i
7617
04:41:34,000 --> 04:41:38,320
is zero right remember this one here the
7618
04:41:38,320 --> 04:41:40,080
remainder calculation right this is
7619
04:41:40,080 --> 04:41:41,760
taking all the
7620
04:41:41,760 --> 04:41:45,200
even numbers right remember that right
7621
04:41:45,200 --> 04:41:48,878
good so this is perfect right hmm
7622
04:41:48,878 --> 04:41:51,040
interesting what if i wanted an else
7623
04:41:51,040 --> 04:41:52,878
statement and this is where i think the
7624
04:41:52,878 --> 04:41:55,840
syntax is kind of i don't know
7625
04:41:55,840 --> 04:41:58,000
it's beautiful let's just say that
7626
04:41:58,000 --> 04:41:59,600
if i
7627
04:41:59,600 --> 04:42:01,440
uh i
7628
04:42:01,440 --> 04:42:02,560
if
7629
04:42:02,560 --> 04:42:04,160
now we actually change the syntax you
7630
04:42:04,160 --> 04:42:06,638
see here i else
7631
04:42:06,638 --> 04:42:08,798
what could you do at
7632
04:42:08,798 --> 04:42:10,638
minus i
7633
04:42:10,638 --> 04:42:14,798
uh let's just do that for i in range 10
7634
04:42:14,798 --> 04:42:15,600
right
7635
04:42:15,600 --> 04:42:17,760
so
7636
04:42:18,480 --> 04:42:21,440
so here we have it right so if i
7637
04:42:21,440 --> 04:42:23,920
still if i is here
7638
04:42:23,920 --> 04:42:26,638
then we add this one here else we put
7639
04:42:26,638 --> 04:42:29,600
minus 1 or minus i here right you see
7640
04:42:29,600 --> 04:42:31,760
now they come negative here right
7641
04:42:31,760 --> 04:42:34,000
before we just excluded them but here we
7642
04:42:34,000 --> 04:42:36,160
just add them as negatives you could do
7643
04:42:36,160 --> 04:42:37,600
whatever you wanted here right again you
7644
04:42:37,600 --> 04:42:39,120
could have functions you could have
7645
04:42:39,120 --> 04:42:41,600
whatever in these two ones here right a
7646
04:42:41,600 --> 04:42:44,080
4i in range of the same thing here right
7647
04:42:44,080 --> 04:42:45,200
so you see you can have the else
7648
04:42:45,200 --> 04:42:47,600
statement there yeah if you have an if
7649
04:42:47,600 --> 04:42:49,200
statement it's only behind if you have
7650
04:42:49,200 --> 04:42:51,120
if and else it's in front
7651
04:42:51,120 --> 04:42:52,638
yeah i don't know
7652
04:42:52,638 --> 04:42:54,000
maybe it makes sense maybe it doesn't
7653
04:42:54,000 --> 04:42:56,320
make sense i don't know this is a syntax
7654
04:42:56,320 --> 04:42:59,920
so we love it because python decided we
7655
04:42:59,920 --> 04:43:01,600
have to love it right
7656
04:43:01,600 --> 04:43:03,520
perfect right
7657
04:43:03,520 --> 04:43:06,560
we can do similar thing with a
7658
04:43:06,560 --> 04:43:09,520
list inside it right so let's just put
7659
04:43:09,520 --> 04:43:14,160
my list here again to be i in
7660
04:43:14,160 --> 04:43:15,600
for i in
7661
04:43:15,600 --> 04:43:18,798
range 10 here then we have that one then
7662
04:43:18,798 --> 04:43:21,120
we have my
7663
04:43:21,120 --> 04:43:22,560
another list here
7664
04:43:22,560 --> 04:43:26,240
which is comprehended by
7665
04:43:26,400 --> 04:43:29,120
what should we do here
7666
04:43:29,120 --> 04:43:32,120
i
7667
04:43:32,480 --> 04:43:35,120
times i for i in
7668
04:43:35,120 --> 04:43:37,440
my list right so you probably guessed
7669
04:43:37,440 --> 04:43:39,680
that that this is
7670
04:43:39,680 --> 04:43:41,280
obviously the same thing is happening
7671
04:43:41,280 --> 04:43:43,440
here it takes i from the list here right
7672
04:43:43,440 --> 04:43:44,878
so i just want to emphasize that it
7673
04:43:44,878 --> 04:43:46,160
doesn't have to be range here it could
7674
04:43:46,160 --> 04:43:47,680
also be a list here
7675
04:43:47,680 --> 04:43:49,120
or yeah
7676
04:43:49,120 --> 04:43:51,600
at least there right so we can do the
7677
04:43:51,600 --> 04:43:53,200
same for dictionaries this is pretty
7678
04:43:53,200 --> 04:43:55,840
nice actually so let's put a dictionary
7679
04:43:55,840 --> 04:43:58,560
here and let's say we actually want to
7680
04:43:58,560 --> 04:44:01,040
do the same thing here but now we want
7681
04:44:01,040 --> 04:44:05,920
to have a key value pair right for i in
7682
04:44:05,920 --> 04:44:08,958
in let's just take my list here just to
7683
04:44:08,958 --> 04:44:10,718
emphasize it right
7684
04:44:10,718 --> 04:44:13,200
so what it does here as you see here it
7685
04:44:13,200 --> 04:44:16,080
has index or key here
7686
04:44:16,080 --> 04:44:17,120
zero
7687
04:44:17,120 --> 04:44:19,600
as the first one here the first one of
7688
04:44:19,600 --> 04:44:21,760
uh where's
7689
04:44:21,760 --> 04:44:24,480
my list here we put it here
7690
04:44:24,480 --> 04:44:26,798
and then it multiplies multiplies as a
7691
04:44:26,798 --> 04:44:30,160
value right so key value key value key
7692
04:44:30,160 --> 04:44:33,360
value key value key value key value key
7693
04:44:33,360 --> 04:44:36,000
value right so see how nice this is so
7694
04:44:36,000 --> 04:44:38,798
you can make a dictionary in this sense
7695
04:44:38,798 --> 04:44:40,718
here
7696
04:44:40,718 --> 04:44:42,638
so this is a lot of new things and i
7697
04:44:42,638 --> 04:44:44,080
think the best way to learn about these
7698
04:44:44,080 --> 04:44:46,160
things is actually to look back on on
7699
04:44:46,160 --> 04:44:48,638
some of the projects we made and
7700
04:44:48,638 --> 04:44:50,080
try to use this
7701
04:44:50,080 --> 04:44:52,240
comprehension and see how we could have
7702
04:44:52,240 --> 04:44:54,958
solved those problems differently if we
7703
04:44:54,958 --> 04:44:57,440
knew about this comprehension right are
7704
04:44:57,440 --> 04:44:59,760
you excited i hope so because this is
7705
04:44:59,760 --> 04:45:01,360
this is going to be amazing see you in a
7706
04:45:01,360 --> 04:45:03,680
moment
7707
04:45:06,080 --> 04:45:07,840
are you ready for this project it's
7708
04:45:07,840 --> 04:45:09,200
going to be amazing because now you're
7709
04:45:09,200 --> 04:45:11,280
going to see how you can make
7710
04:45:11,280 --> 04:45:14,080
make some of your old codes in a this
7711
04:45:14,080 --> 04:45:15,920
conventional way right are you excited
7712
04:45:15,920 --> 04:45:17,760
about what well there's probably more
7713
04:45:17,760 --> 04:45:19,680
than this but this was the things these
7714
04:45:19,680 --> 04:45:21,120
were the things i thought you should do
7715
04:45:21,120 --> 04:45:23,520
because these are just you know it's
7716
04:45:23,520 --> 04:45:25,120
obvious to make this comprehension or
7717
04:45:25,120 --> 04:45:25,920
dick
7718
04:45:25,920 --> 04:45:28,000
dick dictionary comprehension dict
7719
04:45:28,000 --> 04:45:30,400
comprehension right good so here in
7720
04:45:30,400 --> 04:45:33,200
jupiter notebook we're with uh dick list
7721
04:45:33,200 --> 04:45:35,680
and dick comprehension the goal is
7722
04:45:35,680 --> 04:45:38,480
obviously to learn how to use a list and
7723
04:45:38,480 --> 04:45:40,718
dict comprehension right
7724
04:45:40,718 --> 04:45:41,520
and
7725
04:45:41,520 --> 04:45:43,600
what we need to do is redo some of our
7726
04:45:43,600 --> 04:45:46,080
old code here right that's that's all we
7727
04:45:46,080 --> 04:45:47,200
need to do
7728
04:45:47,200 --> 04:45:50,958
so remember csr cipher i don't know if
7729
04:45:50,958 --> 04:45:53,200
do you remember that i think so good
7730
04:45:53,200 --> 04:45:56,160
because back then we used use this uh
7731
04:45:56,160 --> 04:45:58,320
function encrypt char
7732
04:45:58,320 --> 04:46:01,200
before we use the encrypt message
7733
04:46:01,200 --> 04:46:03,360
function right but in this one we're
7734
04:46:03,360 --> 04:46:05,360
just going to use this encrypt chart
7735
04:46:05,360 --> 04:46:07,680
function and this comprehension to
7736
04:46:07,680 --> 04:46:11,120
encrypt the string you are awesome right
7737
04:46:11,120 --> 04:46:13,600
and hint you can use join right
7738
04:46:13,600 --> 04:46:14,400
so
7739
04:46:14,400 --> 04:46:16,958
i left the function here for you to use
7740
04:46:16,958 --> 04:46:18,878
it because this one is a bit complex to
7741
04:46:18,878 --> 04:46:20,400
remember and i didn't want you to go
7742
04:46:20,400 --> 04:46:23,760
through that again right so you have the
7743
04:46:23,760 --> 04:46:26,320
character here and so on the ordinary
7744
04:46:26,320 --> 04:46:28,878
the yeah never mind about all that we
7745
04:46:28,878 --> 04:46:30,878
covered that so far so you have that for
7746
04:46:30,878 --> 04:46:33,120
free to use so all you need to do is use
7747
04:46:33,120 --> 04:46:35,360
this function here this comprehension
7748
04:46:35,360 --> 04:46:37,360
and you probably need to use join
7749
04:46:37,360 --> 04:46:39,920
remember join is a
7750
04:46:39,920 --> 04:46:42,320
method on strings
7751
04:46:42,320 --> 04:46:43,920
so if you join something on the empty
7752
04:46:43,920 --> 04:46:45,680
string it joins a list right remember
7753
04:46:45,680 --> 04:46:47,360
that okay good
7754
04:46:47,360 --> 04:46:49,760
perfect and then we want to decrypt it
7755
04:46:49,760 --> 04:46:51,840
afterwards right and uh we use the
7756
04:46:51,840 --> 04:46:54,560
decrypt char here and you see this just
7757
04:46:54,560 --> 04:46:56,638
called encrypt char with
7758
04:46:56,638 --> 04:46:58,878
26 minus key here right
7759
04:46:58,878 --> 04:47:01,200
remember that okay and again you use
7760
04:47:01,200 --> 04:47:02,958
list comprehension to decrypt the cipher
7761
04:47:02,958 --> 04:47:04,958
it's just to see the circle
7762
04:47:04,958 --> 04:47:07,280
works
7763
04:47:07,280 --> 04:47:08,400
good
7764
04:47:08,400 --> 04:47:10,160
then for the last one here we need to
7765
04:47:10,160 --> 04:47:12,240
use addict comprehension for frequency
7766
04:47:12,240 --> 04:47:15,600
count remember when we added a text
7767
04:47:15,600 --> 04:47:18,240
we could calculate the occurrences of
7768
04:47:18,240 --> 04:47:20,638
each character in that text
7769
04:47:20,638 --> 04:47:22,798
so prompt the user for a line of text
7770
04:47:22,798 --> 04:47:25,120
right use addict comprehension to
7771
04:47:25,120 --> 04:47:27,680
conduct count the number of currents of
7772
04:47:27,680 --> 04:47:30,480
each character right for example a a b b
7773
04:47:30,480 --> 04:47:33,600
c c c cccc should give two a's right two
7774
04:47:33,600 --> 04:47:36,958
a's two b's and five c's right
7775
04:47:36,958 --> 04:47:38,798
and hint here you can use count on a
7776
04:47:38,798 --> 04:47:40,878
string and it will return the number of
7777
04:47:40,878 --> 04:47:42,638
currencies of a right
7778
04:47:42,638 --> 04:47:45,360
so does that sound exciting i hope so
7779
04:47:45,360 --> 04:47:47,680
because it is really exciting to use
7780
04:47:47,680 --> 04:47:50,480
these list and dictionary comprehensions
7781
04:47:50,480 --> 04:47:52,638
and uh don't worry if you don't get it
7782
04:47:52,638 --> 04:47:54,718
in the immediately that's why in the
7783
04:47:54,718 --> 04:47:56,560
next one i'm gonna show you how i would
7784
04:47:56,560 --> 04:47:58,798
solve it and uh
7785
04:47:58,798 --> 04:47:59,600
yeah
7786
04:47:59,600 --> 04:48:02,160
use some time and leave some comments on
7787
04:48:02,160 --> 04:48:04,320
what you find is difficult do you like
7788
04:48:04,320 --> 04:48:06,160
this comprehension this is one of the
7789
04:48:06,160 --> 04:48:08,160
people's favorites about python remember
7790
04:48:08,160 --> 04:48:09,840
in the beginning of the course i had a
7791
04:48:09,840 --> 04:48:12,480
list of what people love this is the
7792
04:48:12,480 --> 04:48:14,240
biggest those are the biggest surveys
7793
04:48:14,240 --> 04:48:16,320
done on python so this is what people
7794
04:48:16,320 --> 04:48:18,958
love about it okay so you're ready see
7795
04:48:18,958 --> 04:48:21,680
you in the next one
7796
04:48:24,240 --> 04:48:26,878
are you ready i hope so because this is
7797
04:48:26,878 --> 04:48:29,520
really really exciting uh we need to do
7798
04:48:29,520 --> 04:48:32,320
list and dict comprehension did you
7799
04:48:32,320 --> 04:48:34,160
manage yourself and you just want to
7800
04:48:34,160 --> 04:48:35,840
sure make sure that i'm not doing
7801
04:48:35,840 --> 04:48:38,080
something fancy well let me know in the
7802
04:48:38,080 --> 04:48:40,080
comment down below there because this is
7803
04:48:40,080 --> 04:48:41,760
really exciting right
7804
04:48:41,760 --> 04:48:44,400
okay let's jump right into it right so
7805
04:48:44,400 --> 04:48:47,600
remember the encrypt char
7806
04:48:47,600 --> 04:48:50,320
originally in the csu cipher had another
7807
04:48:50,320 --> 04:48:52,878
function encrypt message and this is
7808
04:48:52,878 --> 04:48:54,480
actually the function we want to
7809
04:48:54,480 --> 04:48:58,160
implement with list comprehension and
7810
04:48:58,160 --> 04:49:00,160
join actually it says here right
7811
04:49:00,160 --> 04:49:00,958
so
7812
04:49:00,958 --> 04:49:03,040
let's just remember this encrypt chart
7813
04:49:03,040 --> 04:49:05,040
let's just execute it right so remember
7814
04:49:05,040 --> 04:49:06,878
it just takes
7815
04:49:06,878 --> 04:49:10,240
encrypt charge just take a char here for
7816
04:49:10,240 --> 04:49:12,400
instance let's take the y from you are
7817
04:49:12,400 --> 04:49:15,040
awesome right and it needs a key right
7818
04:49:15,040 --> 04:49:17,280
and the key here let's just say three
7819
04:49:17,280 --> 04:49:20,718
right so it would encrypt y to b right
7820
04:49:20,718 --> 04:49:22,560
this is what it says here right
7821
04:49:22,560 --> 04:49:24,560
and i'm pretty sure that is correct
7822
04:49:24,560 --> 04:49:27,760
right so we need to use this one here in
7823
04:49:27,760 --> 04:49:29,680
order to
7824
04:49:29,680 --> 04:49:31,920
encrypt it right so let's jump
7825
04:49:31,920 --> 04:49:34,560
immediately down to have the message
7826
04:49:34,560 --> 04:49:35,680
here
7827
04:49:35,680 --> 04:49:36,638
and
7828
04:49:36,638 --> 04:49:39,200
we want to
7829
04:49:39,440 --> 04:49:41,200
encrypt a string it doesn't say we have
7830
04:49:41,200 --> 04:49:42,798
to encrypt this one but let's just take
7831
04:49:42,798 --> 04:49:44,718
this one but we need to notice here that
7832
04:49:44,718 --> 04:49:46,718
this is lowercase and we have uppercase
7833
04:49:46,718 --> 04:49:48,240
here but we are getting comfortable
7834
04:49:48,240 --> 04:49:50,560
about all that so one way to do it is to
7835
04:49:50,560 --> 04:49:52,638
take the message and immediately put it
7836
04:49:52,638 --> 04:49:55,600
in uppercase or whatever we want
7837
04:49:55,600 --> 04:49:56,878
we will do it
7838
04:49:56,878 --> 04:49:59,120
in one way or another right but first
7839
04:49:59,120 --> 04:50:00,878
let's look at this comprehension right
7840
04:50:00,878 --> 04:50:03,760
so here we have it right so if we take c
7841
04:50:03,760 --> 04:50:07,840
for c in message
7842
04:50:07,840 --> 04:50:09,680
we actually have it here right so we
7843
04:50:09,680 --> 04:50:13,200
have each character in a list now right
7844
04:50:13,200 --> 04:50:15,600
you are awesome right and one way to
7845
04:50:15,600 --> 04:50:17,520
make sure it's upper is just to call
7846
04:50:17,520 --> 04:50:19,280
upper on this one for instance you are
7847
04:50:19,280 --> 04:50:21,200
awesome right
7848
04:50:21,200 --> 04:50:23,600
so if we call directly encrypt message
7849
04:50:23,600 --> 04:50:25,680
on this one we will also encrypt the
7850
04:50:25,680 --> 04:50:27,520
spaces and remember we didn't want to
7851
04:50:27,520 --> 04:50:29,440
encrypt spaces in the old ones we need
7852
04:50:29,440 --> 04:50:32,400
to use an if statement but let's just
7853
04:50:32,400 --> 04:50:35,360
for now just call it here and let's just
7854
04:50:35,360 --> 04:50:37,360
add a key here and
7855
04:50:37,360 --> 04:50:39,840
say the key is equal three right
7856
04:50:39,840 --> 04:50:41,360
uh
7857
04:50:41,360 --> 04:50:43,040
it didn't like that actually it was it
7858
04:50:43,040 --> 04:50:45,040
was not called encrypt encrypted char
7859
04:50:45,040 --> 04:50:46,958
thank you for reminding me right
7860
04:50:46,958 --> 04:50:48,878
good so now we have it here except that
7861
04:50:48,878 --> 04:50:50,160
we have these
7862
04:50:50,160 --> 04:50:52,400
here are encrypted to something
7863
04:50:52,400 --> 04:50:54,320
the spaces are encrypted to something we
7864
04:50:54,320 --> 04:50:56,480
don't want right so
7865
04:50:56,480 --> 04:50:59,040
we only want to encrypt it if
7866
04:50:59,040 --> 04:51:01,040
c
7867
04:51:01,040 --> 04:51:02,480
not in
7868
04:51:02,480 --> 04:51:05,760
the sequence of space we also use comma
7869
04:51:05,760 --> 04:51:07,200
and dot
7870
04:51:07,200 --> 04:51:09,280
else we just need to leave c as it is
7871
04:51:09,280 --> 04:51:11,360
right this is a syntax right so we do
7872
04:51:11,360 --> 04:51:13,840
this if this is the case else we just
7873
04:51:13,840 --> 04:51:16,000
leave the character right so now we
7874
04:51:16,000 --> 04:51:17,920
actually have the encrypted message here
7875
04:51:17,920 --> 04:51:22,400
right the problem is that as is here
7876
04:51:22,400 --> 04:51:24,798
our cipher list let's call it cipher
7877
04:51:24,798 --> 04:51:29,840
list here this list here is
7878
04:51:30,480 --> 04:51:32,160
is character by character right so in
7879
04:51:32,160 --> 04:51:34,000
order to make that to a
7880
04:51:34,000 --> 04:51:36,400
string we can use join as it says here
7881
04:51:36,400 --> 04:51:40,560
the empty join here on cipher list right
7882
04:51:40,560 --> 04:51:42,480
so then you actually have it as a string
7883
04:51:42,480 --> 04:51:44,160
here right and that's actually what we
7884
04:51:44,160 --> 04:51:45,840
wanted right
7885
04:51:45,840 --> 04:51:46,958
perfect
7886
04:51:46,958 --> 04:51:47,920
good
7887
04:51:47,920 --> 04:51:49,520
that was actually it
7888
04:51:49,520 --> 04:51:50,958
thank you for helping me so the next one
7889
04:51:50,958 --> 04:51:52,638
here is going to be easy right so
7890
04:51:52,638 --> 04:51:56,000
basically we have this one here
7891
04:51:56,000 --> 04:51:57,440
which you can take the cipher here and
7892
04:51:57,440 --> 04:51:59,280
this one here and immediately we should
7893
04:51:59,280 --> 04:52:01,440
remember to execute this one here
7894
04:52:01,440 --> 04:52:03,440
and then we take key again here to be
7895
04:52:03,440 --> 04:52:06,718
three right and then we take a message
7896
04:52:06,718 --> 04:52:08,798
list again here
7897
04:52:08,798 --> 04:52:10,878
make it in two steps here
7898
04:52:10,878 --> 04:52:12,240
and then we have
7899
04:52:12,240 --> 04:52:13,520
decrypt
7900
04:52:13,520 --> 04:52:14,718
char
7901
04:52:14,718 --> 04:52:15,600
c
7902
04:52:15,600 --> 04:52:18,160
comma key
7903
04:52:18,160 --> 04:52:19,440
if c
7904
04:52:19,440 --> 04:52:21,040
not in
7905
04:52:21,040 --> 04:52:23,200
one of these
7906
04:52:23,200 --> 04:52:25,360
else c for
7907
04:52:25,360 --> 04:52:26,878
c in
7908
04:52:26,878 --> 04:52:28,480
uh cipher
7909
04:52:28,480 --> 04:52:30,320
upper we don't need upper in this case
7910
04:52:30,320 --> 04:52:32,560
but we just do it anyway right
7911
04:52:32,560 --> 04:52:35,040
so here okay so now i'll forget to join
7912
04:52:35,040 --> 04:52:36,878
it right we need to join it here
7913
04:52:36,878 --> 04:52:39,360
bum join
7914
04:52:39,360 --> 04:52:40,480
message
7915
04:52:40,480 --> 04:52:42,240
list right
7916
04:52:42,240 --> 04:52:45,200
here you have it you are awesome so this
7917
04:52:45,200 --> 04:52:47,120
went pretty pretty easy right and again
7918
04:52:47,120 --> 04:52:49,760
it's the same syntax we did up here
7919
04:52:49,760 --> 04:52:50,958
uh
7920
04:52:50,958 --> 04:52:53,760
ifc not in this one here then else blah
7921
04:52:53,760 --> 04:52:56,560
blah blah run you see it right
7922
04:52:56,560 --> 04:52:59,440
isn't that amazing so
7923
04:52:59,440 --> 04:53:02,000
basically
7924
04:53:02,000 --> 04:53:04,240
basically this is like two lines of code
7925
04:53:04,240 --> 04:53:06,798
you could combine this in one line
7926
04:53:06,798 --> 04:53:08,080
and uh
7927
04:53:08,080 --> 04:53:11,040
except have instead of having this uh
7928
04:53:11,040 --> 04:53:14,000
decrypt message and encrypt message
7929
04:53:14,000 --> 04:53:16,320
methods or functions we made
7930
04:53:16,320 --> 04:53:18,480
in the csr cipher do you feel cheated
7931
04:53:18,480 --> 04:53:20,878
now i hope not because this is just you
7932
04:53:20,878 --> 04:53:23,680
learn more concepts and uh
7933
04:53:23,680 --> 04:53:25,280
if you see this the first time you see
7934
04:53:25,280 --> 04:53:27,040
it i don't think it's more clear what's
7935
04:53:27,040 --> 04:53:28,718
happening i think actually the
7936
04:53:28,718 --> 04:53:31,040
for loops we did did in the caesar
7937
04:53:31,040 --> 04:53:32,958
cipher exercise it's more
7938
04:53:32,958 --> 04:53:34,718
explaining what it is but now we
7939
04:53:34,718 --> 04:53:36,400
understand that concept we can take it
7940
04:53:36,400 --> 04:53:37,920
here to the next level where we
7941
04:53:37,920 --> 04:53:39,440
understand the list and dictionary
7942
04:53:39,440 --> 04:53:41,120
comprehension right
7943
04:53:41,120 --> 04:53:42,560
good
7944
04:53:42,560 --> 04:53:44,718
now ready for the
7945
04:53:44,718 --> 04:53:46,958
frequency count there where we need dict
7946
04:53:46,958 --> 04:53:49,680
use addict comprehension right so let's
7947
04:53:49,680 --> 04:53:51,280
try to do what it says here prompt the
7948
04:53:51,280 --> 04:53:54,080
user for a line of text text
7949
04:53:54,080 --> 04:53:55,840
input
7950
04:53:55,840 --> 04:53:58,560
input line of text
7951
04:53:58,560 --> 04:54:00,400
thank you user
7952
04:54:00,400 --> 04:54:02,000
use a dick comprehension to count the
7953
04:54:02,000 --> 04:54:04,638
number of currents of each character
7954
04:54:04,638 --> 04:54:05,440
okay
7955
04:54:05,440 --> 04:54:08,958
let's try to do that
7956
04:54:09,120 --> 04:54:11,360
okay so we have a
7957
04:54:11,360 --> 04:54:13,040
dictionary here
7958
04:54:13,040 --> 04:54:14,080
and
7959
04:54:14,080 --> 04:54:16,878
how do we do it so
7960
04:54:16,878 --> 04:54:18,718
we need to
7961
04:54:18,718 --> 04:54:19,680
take
7962
04:54:19,680 --> 04:54:22,480
we have the text here right so we have
7963
04:54:22,480 --> 04:54:24,958
the c here and then we can have the
7964
04:54:24,958 --> 04:54:26,958
count right the hint here and the count
7965
04:54:26,958 --> 04:54:28,798
here on the string then we're gonna take
7966
04:54:28,798 --> 04:54:32,160
the text here and count on it the c here
7967
04:54:32,160 --> 04:54:35,520
for c in text right i should actually do
7968
04:54:35,520 --> 04:54:37,840
it so input the line of text
7969
04:54:37,840 --> 04:54:40,718
a a b b c c c c
7970
04:54:40,718 --> 04:54:42,160
and you see it you actually have it here
7971
04:54:42,160 --> 04:54:42,958
right
7972
04:54:42,958 --> 04:54:44,400
so
7973
04:54:44,400 --> 04:54:47,440
did this go a bit too fast
7974
04:54:47,440 --> 04:54:49,120
so what happens here right because you
7975
04:54:49,120 --> 04:54:51,200
might see some
7976
04:54:51,200 --> 04:54:54,320
small details here right that's
7977
04:54:54,320 --> 04:54:56,160
maybe a little bit fast right so what
7978
04:54:56,160 --> 04:54:58,798
happens here right so for c in text it
7979
04:54:58,798 --> 04:55:01,200
takes each character in the text right
7980
04:55:01,200 --> 04:55:03,200
so first it takes a
7981
04:55:03,200 --> 04:55:04,560
and then it says
7982
04:55:04,560 --> 04:55:06,480
a
7983
04:55:06,480 --> 04:55:09,280
key a should have text of count a that
7984
04:55:09,280 --> 04:55:10,958
means it counts a number of currents of
7985
04:55:10,958 --> 04:55:14,000
eight that puts it two perfect a maps to
7986
04:55:14,000 --> 04:55:14,878
two
7987
04:55:14,878 --> 04:55:16,400
then it takes the next character but the
7988
04:55:16,400 --> 04:55:18,480
next character is also a
7989
04:55:18,480 --> 04:55:20,860
so it puts the key a and maps it to
7990
04:55:20,860 --> 04:55:22,878
[Music]
7991
04:55:22,878 --> 04:55:25,120
two right because the count of them is
7992
04:55:25,120 --> 04:55:26,958
two so you actually overwrite the same
7993
04:55:26,958 --> 04:55:29,040
one again and it doesn't matter actually
7994
04:55:29,040 --> 04:55:30,718
and then it takes b and does the same
7995
04:55:30,718 --> 04:55:32,560
and it overrides again and then c it
7996
04:55:32,560 --> 04:55:34,480
overwrites actually five times the same
7997
04:55:34,480 --> 04:55:37,040
key of c right
7998
04:55:37,040 --> 04:55:39,120
so you might think oh isn't that a bit
7999
04:55:39,120 --> 04:55:40,798
overkill to do the same again and again
8000
04:55:40,798 --> 04:55:44,160
yeah it is might be so alternatively you
8001
04:55:44,160 --> 04:55:46,160
could actually
8002
04:55:46,160 --> 04:55:48,080
you could actually have what's called a
8003
04:55:48,080 --> 04:55:50,718
set here this is like a bonus
8004
04:55:50,718 --> 04:55:52,878
if you are comfortable i mean this is
8005
04:55:52,878 --> 04:55:54,560
this is fine up here
8006
04:55:54,560 --> 04:55:56,480
this is just a set right so what does a
8007
04:55:56,480 --> 04:55:58,560
set do right
8008
04:55:58,560 --> 04:56:00,638
well let's look at that right
8009
04:56:00,638 --> 04:56:02,080
so
8010
04:56:02,080 --> 04:56:03,040
print
8011
04:56:03,040 --> 04:56:05,040
text here we have it here
8012
04:56:05,040 --> 04:56:06,840
and then we
8013
04:56:06,840 --> 04:56:08,400
print
8014
04:56:08,400 --> 04:56:11,360
set of text here so let's do that right
8015
04:56:11,360 --> 04:56:16,320
so aa b b c c c c c boom
8016
04:56:16,320 --> 04:56:18,638
and you see here
8017
04:56:18,638 --> 04:56:20,160
the text here is this one here right
8018
04:56:20,160 --> 04:56:21,680
this is obviously the text we entered
8019
04:56:21,680 --> 04:56:23,840
here but the set here it actually looks
8020
04:56:23,840 --> 04:56:25,280
a bit like a dictionary except it
8021
04:56:25,280 --> 04:56:27,200
doesn't have the colons here right it
8022
04:56:27,200 --> 04:56:30,160
says we have a b and c so this is a set
8023
04:56:30,160 --> 04:56:32,240
is like the unique
8024
04:56:32,240 --> 04:56:33,600
unique
8025
04:56:33,600 --> 04:56:36,958
values in an iterable right like a
8026
04:56:36,958 --> 04:56:39,280
string right or it could be a list then
8027
04:56:39,280 --> 04:56:41,600
it takes all the unique elements of it
8028
04:56:41,600 --> 04:56:43,680
and puts it in there right so in this
8029
04:56:43,680 --> 04:56:46,400
case here it only takes a
8030
04:56:46,400 --> 04:56:48,480
it takes b and c so it doesn't just do
8031
04:56:48,480 --> 04:56:50,480
it multiple times right
8032
04:56:50,480 --> 04:56:51,920
and the count does the same thing right
8033
04:56:51,920 --> 04:56:53,760
so this is basically
8034
04:56:53,760 --> 04:56:55,200
just
8035
04:56:55,200 --> 04:56:57,360
ensuring for instance if this string was
8036
04:56:57,360 --> 04:57:01,120
extremely long and extremely many
8037
04:57:01,120 --> 04:57:03,760
duplicates right then this might be
8038
04:57:03,760 --> 04:57:05,440
faster right you put a step here where
8039
04:57:05,440 --> 04:57:07,040
you remove all the duplicates and only
8040
04:57:07,040 --> 04:57:09,200
have unique values and then you iterate
8041
04:57:09,200 --> 04:57:12,000
over that instead right
8042
04:57:12,000 --> 04:57:14,718
so this is just optional
8043
04:57:14,718 --> 04:57:17,360
and if you like this it's fine it's
8044
04:57:17,360 --> 04:57:19,360
maybe better
8045
04:57:19,360 --> 04:57:21,600
otherwise it's fine to do it as this one
8046
04:57:21,600 --> 04:57:23,360
up here right because basically you
8047
04:57:23,360 --> 04:57:24,718
didn't know the set thing here i just
8048
04:57:24,718 --> 04:57:26,480
wanted to show you so you know it for
8049
04:57:26,480 --> 04:57:29,200
another time right so how do you like
8050
04:57:29,200 --> 04:57:30,718
list comprehension and dict
8051
04:57:30,718 --> 04:57:32,400
comprehension please let me know in the
8052
04:57:32,400 --> 04:57:33,520
comments because this is one of the
8053
04:57:33,520 --> 04:57:35,680
things that people love about python if
8054
04:57:35,680 --> 04:57:37,120
you don't get them yet please let me
8055
04:57:37,120 --> 04:57:38,798
know too because maybe it needs more
8056
04:57:38,798 --> 04:57:42,480
explanation uh some more practice and
8057
04:57:42,480 --> 04:57:43,840
then you'll get them and you will love
8058
04:57:43,840 --> 04:57:45,760
them monday i think so please let me
8059
04:57:45,760 --> 04:57:46,480
know
8060
04:57:46,480 --> 04:57:49,600
see you in the next one
8061
04:57:53,000 --> 04:57:55,120
object-oriented programming this is
8062
04:57:55,120 --> 04:57:56,878
amazing because this is one of those
8063
04:57:56,878 --> 04:57:59,120
concepts you just want to master
8064
04:57:59,120 --> 04:58:00,878
why you might ask because
8065
04:58:00,878 --> 04:58:02,878
object-oriented programming will make
8066
04:58:02,878 --> 04:58:04,878
your programming
8067
04:58:04,878 --> 04:58:07,760
easier to understand because it wants to
8068
04:58:07,760 --> 04:58:10,560
try to resemble reality that means the
8069
04:58:10,560 --> 04:58:12,798
things you program
8070
04:58:12,798 --> 04:58:15,440
looks more like reality you know so you
8071
04:58:15,440 --> 04:58:17,920
don't need to do so many transformation
8072
04:58:17,920 --> 04:58:20,718
on how the computer understands things
8073
04:58:20,718 --> 04:58:22,878
so in order to understand this concept
8074
04:58:22,878 --> 04:58:24,560
we're going to create a game together a
8075
04:58:24,560 --> 04:58:26,560
card game where we're going to introduce
8076
04:58:26,560 --> 04:58:30,480
objects of card deck and hand so three
8077
04:58:30,480 --> 04:58:32,320
different types of objects that we're
8078
04:58:32,320 --> 04:58:35,200
going to use to simulate or play or
8079
04:58:35,200 --> 04:58:37,920
write our game right so
8080
04:58:37,920 --> 04:58:39,760
enough talking i think the best way to
8081
04:58:39,760 --> 04:58:42,560
learn is just to see it and
8082
04:58:42,560 --> 04:58:44,798
start doing it are you ready i hope so
8083
04:58:44,798 --> 04:58:47,040
because this is going to be exciting so
8084
04:58:47,040 --> 04:58:49,120
let's jump to jupiter notebook so in
8085
04:58:49,120 --> 04:58:50,718
jupiter notebook here we have the
8086
04:58:50,718 --> 04:58:53,520
object-order programming so the goal is
8087
04:58:53,520 --> 04:58:55,280
to learn the basics behind object
8088
04:58:55,280 --> 04:58:58,000
oriented programming okay so first
8089
04:58:58,000 --> 04:59:00,638
question first what is this thing and
8090
04:59:00,638 --> 04:59:02,480
what is a hype about
8091
04:59:02,480 --> 04:59:05,760
at its core object-oriented programming
8092
04:59:05,760 --> 04:59:08,240
helps you with structuring your programs
8093
04:59:08,240 --> 04:59:10,878
to resemble reality that's what i said
8094
04:59:10,878 --> 04:59:11,680
right
8095
04:59:11,680 --> 04:59:15,200
so you kind of create these objects
8096
04:59:15,200 --> 04:59:17,680
from definitions of classes i'll get
8097
04:59:17,680 --> 04:59:19,280
back to that in a moment
8098
04:59:19,280 --> 04:59:22,798
but these objects are resembling reality
8099
04:59:22,798 --> 04:59:25,600
in our case we're gonna start by using a
8100
04:59:25,600 --> 04:59:27,680
card game and we're gonna have the
8101
04:59:27,680 --> 04:59:29,920
objects types of card
8102
04:59:29,920 --> 04:59:33,360
deck and hand okay
8103
04:59:33,360 --> 04:59:34,240
so
8104
04:59:34,240 --> 04:59:35,120
more
8105
04:59:35,120 --> 04:59:37,120
said differently right that is you
8106
04:59:37,120 --> 04:59:39,520
declare objects with parameters and
8107
04:59:39,520 --> 04:59:41,280
methods
8108
04:59:41,280 --> 04:59:43,840
you need on them right so again here on
8109
04:59:43,840 --> 04:59:46,080
the card we need a suit and a rank and
8110
04:59:46,080 --> 04:59:48,878
we need something called sdr and lsn
8111
04:59:48,878 --> 04:59:50,958
that's a string representation of the
8112
04:59:50,958 --> 04:59:54,160
object and the less than so these have
8113
04:59:54,160 --> 04:59:56,798
double underscores in front and
8114
04:59:56,798 --> 04:59:58,718
and back of the
8115
04:59:58,718 --> 05:00:00,560
methods
8116
05:00:00,560 --> 05:00:04,480
it means it's kind of the s built-in
8117
05:00:04,480 --> 05:00:08,000
python things that are used by all the
8118
05:00:08,000 --> 05:00:10,480
all the python functionalities you might
8119
05:00:10,480 --> 05:00:12,080
say
8120
05:00:12,080 --> 05:00:14,480
the deck here on the other hand it has
8121
05:00:14,480 --> 05:00:16,400
cards which is a list of cards and then
8122
05:00:16,400 --> 05:00:18,160
it has a length
8123
05:00:18,160 --> 05:00:21,040
method and then add card pop a card and
8124
05:00:21,040 --> 05:00:22,480
shuffle the deck
8125
05:00:22,480 --> 05:00:24,958
the hand here is actually said to be a
8126
05:00:24,958 --> 05:00:27,600
subclass of the deck and what that means
8127
05:00:27,600 --> 05:00:29,360
is actually that
8128
05:00:29,360 --> 05:00:31,680
the hand resembles the deck in many
8129
05:00:31,680 --> 05:00:33,840
senses right it has cards you can add a
8130
05:00:33,840 --> 05:00:35,200
card you can
8131
05:00:35,200 --> 05:00:37,120
pop a card remove a card right or
8132
05:00:37,120 --> 05:00:39,120
shuffle the cards in your hand right but
8133
05:00:39,120 --> 05:00:41,680
on top of that it has it has a label it
8134
05:00:41,680 --> 05:00:43,280
might be your
8135
05:00:43,280 --> 05:00:45,760
your hand so you put your name on it and
8136
05:00:45,760 --> 05:00:47,200
it might in this game here we're going
8137
05:00:47,200 --> 05:00:48,958
to have a win count how many games you
8138
05:00:48,958 --> 05:00:50,320
want right so
8139
05:00:50,320 --> 05:00:51,680
the hand is going to remember that so
8140
05:00:51,680 --> 05:00:53,840
it's also kind of hand off the person of
8141
05:00:53,840 --> 05:00:55,120
the player right
8142
05:00:55,120 --> 05:00:57,680
and for this hand here we also want to
8143
05:00:57,680 --> 05:01:00,480
be able to print it so that's a string
8144
05:01:00,480 --> 05:01:03,600
here again this is makes it easier easy
8145
05:01:03,600 --> 05:01:05,360
for us to get the
8146
05:01:05,360 --> 05:01:08,000
string representation of the object and
8147
05:01:08,000 --> 05:01:10,000
this is a standard python method so
8148
05:01:10,000 --> 05:01:12,240
again so we can when we call print a
8149
05:01:12,240 --> 05:01:14,400
print will automatically call string
8150
05:01:14,400 --> 05:01:17,200
here to get the string representation
8151
05:01:17,200 --> 05:01:18,798
then we have the get label which is the
8152
05:01:18,798 --> 05:01:21,680
label of the hand and the round winner
8153
05:01:21,680 --> 05:01:24,080
that increments the win count and then
8154
05:01:24,080 --> 05:01:28,480
they could get a win count which is
8155
05:01:28,878 --> 05:01:31,680
the current count of the hand right
8156
05:01:31,680 --> 05:01:35,280
so this is kind of a diagram and
8157
05:01:35,280 --> 05:01:37,760
you see multiple ways of drawing these
8158
05:01:37,760 --> 05:01:39,600
diagrams i'm not going to go into them
8159
05:01:39,600 --> 05:01:41,600
but these each one of them kind of
8160
05:01:41,600 --> 05:01:44,240
describe the classes that we are going
8161
05:01:44,240 --> 05:01:47,280
to implement in python and the classes
8162
05:01:47,280 --> 05:01:51,120
is kind of the recipe of the objects so
8163
05:01:51,120 --> 05:01:54,160
the objects are the one that we create
8164
05:01:54,160 --> 05:01:58,160
and use inside so the class defines them
8165
05:01:58,160 --> 05:02:01,200
objects are instances often right so in
8166
05:02:01,200 --> 05:02:03,200
a card right we can have in a decker
8167
05:02:03,200 --> 05:02:06,320
card we usually have 52 cards if there
8168
05:02:06,320 --> 05:02:08,560
are no special cards right so there will
8169
05:02:08,560 --> 05:02:10,958
be 52 different cards with different
8170
05:02:10,958 --> 05:02:12,798
suit and different rank in our game
8171
05:02:12,798 --> 05:02:15,440
right so these are objects in the deck
8172
05:02:15,440 --> 05:02:18,000
here the class is defining it the deck
8173
05:02:18,000 --> 05:02:20,400
is for instance having 52 cards in the
8174
05:02:20,400 --> 05:02:22,958
beginning and then you play along you
8175
05:02:22,958 --> 05:02:25,200
maybe you take some cards out or you add
8176
05:02:25,200 --> 05:02:27,120
some cards on top of them right and you
8177
05:02:27,120 --> 05:02:29,840
can shuffle it
8178
05:02:30,000 --> 05:02:32,080
also the hand it's similar to the deck
8179
05:02:32,080 --> 05:02:33,840
in that sense
8180
05:02:33,840 --> 05:02:36,320
it has the same functionality or methods
8181
05:02:36,320 --> 05:02:38,240
down here and some additional ones here
8182
05:02:38,240 --> 05:02:39,040
right
8183
05:02:39,040 --> 05:02:42,320
so this concept of
8184
05:02:42,320 --> 05:02:44,718
of a super class and a class here this
8185
05:02:44,718 --> 05:02:46,878
relationship is commonly used in object
8186
05:02:46,878 --> 05:02:49,040
order programming because you say for
8187
05:02:49,040 --> 05:02:50,160
instance
8188
05:02:50,160 --> 05:02:52,320
you categorize things in reality too
8189
05:02:52,320 --> 05:02:55,600
right so for instance take fruits right
8190
05:02:55,600 --> 05:02:57,440
a banana is a fruit an apple isn't a
8191
05:02:57,440 --> 05:02:59,120
fruit right so they both have the same
8192
05:02:59,120 --> 05:03:01,760
characteristic of being a fruit so the
8193
05:03:01,760 --> 05:03:04,638
fruit is a class superclass and the
8194
05:03:04,638 --> 05:03:06,080
banana and
8195
05:03:06,080 --> 05:03:08,638
banana class and apple class are
8196
05:03:08,638 --> 05:03:11,360
instances of fruits right
8197
05:03:11,360 --> 05:03:13,840
so all fruits can you can say are
8198
05:03:13,840 --> 05:03:16,080
eatable right so
8199
05:03:16,080 --> 05:03:17,440
one thing you can do with the fruit is
8200
05:03:17,440 --> 05:03:19,600
to eat it right well you could do that
8201
05:03:19,600 --> 05:03:21,120
with all fruits so you put that in a
8202
05:03:21,120 --> 05:03:22,718
super class when it makes sense you
8203
05:03:22,718 --> 05:03:24,878
don't want to over complicate things but
8204
05:03:24,878 --> 05:03:27,440
you know just to get it there so are you
8205
05:03:27,440 --> 05:03:29,520
ready to implement this
8206
05:03:29,520 --> 05:03:31,200
again you don't know how to do that so
8207
05:03:31,200 --> 05:03:33,920
that's why we do that in the session
8208
05:03:33,920 --> 05:03:36,480
lesson here and in the next one you when
8209
05:03:36,480 --> 05:03:39,200
we implemented the three classes here
8210
05:03:39,200 --> 05:03:40,638
you're gonna implement the game it's
8211
05:03:40,638 --> 05:03:42,320
gonna be awesome right a card game right
8212
05:03:42,320 --> 05:03:45,280
a real card game amazing
8213
05:03:45,280 --> 05:03:46,320
okay
8214
05:03:46,320 --> 05:03:50,000
so how do you define a class
8215
05:03:50,000 --> 05:03:51,920
do it by class
8216
05:03:51,920 --> 05:03:55,040
class card and a colon and a colon again
8217
05:03:55,040 --> 05:03:57,520
represent that the code internet after
8218
05:03:57,520 --> 05:04:00,480
that belongs to this class right
8219
05:04:00,480 --> 05:04:02,878
so in python as i already told you you
8220
05:04:02,878 --> 05:04:05,200
have these double underscores here these
8221
05:04:05,200 --> 05:04:07,440
are the methods that are
8222
05:04:07,440 --> 05:04:10,080
belonging to python syntax so we're
8223
05:04:10,080 --> 05:04:12,400
going to create a
8224
05:04:12,400 --> 05:04:14,480
init function
8225
05:04:14,480 --> 05:04:17,120
which is like the constructor which is
8226
05:04:17,120 --> 05:04:21,360
called when you construct a card object
8227
05:04:21,360 --> 05:04:24,240
and the syntax of classes is it has
8228
05:04:24,240 --> 05:04:26,718
itself along with all the methods the
8229
05:04:26,718 --> 05:04:29,280
self is referring to the self so
8230
05:04:29,280 --> 05:04:31,520
everything you assign to self can be
8231
05:04:31,520 --> 05:04:34,560
accessed anywhere inside the object okay
8232
05:04:34,560 --> 05:04:36,958
so let's just try this one here and say
8233
05:04:36,958 --> 05:04:40,080
self and we put a suit here and we add
8234
05:04:40,080 --> 05:04:43,040
this suit to be let's say
8235
05:04:43,040 --> 05:04:44,160
let's say
8236
05:04:44,160 --> 05:04:45,360
zero right
8237
05:04:45,360 --> 05:04:48,480
and self rank here we put that to zero
8238
05:04:48,480 --> 05:04:50,080
here in this case here so now we can
8239
05:04:50,080 --> 05:04:52,160
create an object of
8240
05:04:52,160 --> 05:04:55,200
class but right now all of them will
8241
05:04:55,200 --> 05:04:57,360
have suit zero and rank zero so let's
8242
05:04:57,360 --> 05:05:00,160
just exemplify this so we create a card
8243
05:05:00,160 --> 05:05:00,958
here
8244
05:05:00,958 --> 05:05:02,560
and
8245
05:05:02,560 --> 05:05:05,840
this card here we'll call this init
8246
05:05:05,840 --> 05:05:07,520
function here when we create the
8247
05:05:07,520 --> 05:05:10,080
instance of this one here right so here
8248
05:05:10,080 --> 05:05:13,440
we have card we can see suit here is
8249
05:05:13,440 --> 05:05:16,400
zero and if we try rank as well it's
8250
05:05:16,400 --> 05:05:18,718
zero as well right as you see here right
8251
05:05:18,718 --> 05:05:20,638
if you created another card it will be
8252
05:05:20,638 --> 05:05:22,638
another instance of it
8253
05:05:22,638 --> 05:05:24,718
and it will have the same student rank
8254
05:05:24,718 --> 05:05:26,718
because we hard coded them here so what
8255
05:05:26,718 --> 05:05:28,320
you want to do is actually be able to
8256
05:05:28,320 --> 05:05:31,680
put suit and rank in here suit rank here
8257
05:05:31,680 --> 05:05:34,560
as arguments and assign them here so now
8258
05:05:34,560 --> 05:05:36,400
you'll see what happens right now we
8259
05:05:36,400 --> 05:05:38,320
execute this one and when we execute
8260
05:05:38,320 --> 05:05:40,000
this one here we need to add the suit
8261
05:05:40,000 --> 05:05:41,760
and rank so let's for the first one just
8262
05:05:41,760 --> 05:05:43,440
add zero
8263
05:05:43,440 --> 05:05:46,958
zero and zero and let's just call it c1
8264
05:05:46,958 --> 05:05:48,560
for card one
8265
05:05:48,560 --> 05:05:50,798
and uh let's make a card two immediately
8266
05:05:50,798 --> 05:05:51,600
here
8267
05:05:51,600 --> 05:05:53,440
and have card here
8268
05:05:53,440 --> 05:05:56,798
one by one for instance right
8269
05:05:56,798 --> 05:05:59,200
and now we can see c1 here
8270
05:05:59,200 --> 05:06:01,920
suit here is zero still but
8271
05:06:01,920 --> 05:06:07,120
c2 here suit here is one right because
8272
05:06:07,120 --> 05:06:09,520
they have been assigned to different
8273
05:06:09,520 --> 05:06:10,878
values
8274
05:06:10,878 --> 05:06:13,680
inside here in the init function here
8275
05:06:13,680 --> 05:06:14,878
you see
8276
05:06:14,878 --> 05:06:16,958
so that's how it works this one is
8277
05:06:16,958 --> 05:06:19,840
assigned specifically to these
8278
05:06:19,840 --> 05:06:21,840
variables here which point at the
8279
05:06:21,840 --> 05:06:25,200
objects of the card and each card object
8280
05:06:25,200 --> 05:06:28,638
has its own set of suit and rank
8281
05:06:28,638 --> 05:06:31,200
variables we have inside here right
8282
05:06:31,200 --> 05:06:32,480
now there's a lot of things to
8283
05:06:32,480 --> 05:06:34,798
comprehend right but try to play around
8284
05:06:34,798 --> 05:06:37,440
with this so you understand the concept
8285
05:06:37,440 --> 05:06:40,160
here of these two things here so if it's
8286
05:06:40,160 --> 05:06:41,840
all new to you i would advise you to
8287
05:06:41,840 --> 05:06:43,440
stop the video and try to play around
8288
05:06:43,440 --> 05:06:45,920
with this code here and create some
8289
05:06:45,920 --> 05:06:47,840
instances so you really understand the
8290
05:06:47,840 --> 05:06:51,280
differences on objects and classes
8291
05:06:51,280 --> 05:06:52,480
good
8292
05:06:52,480 --> 05:06:54,560
so this was it actually but i actually
8293
05:06:54,560 --> 05:06:56,560
want to do something a bit more advanced
8294
05:06:56,560 --> 05:06:58,958
here in a moment but let's just keep it
8295
05:06:58,958 --> 05:07:01,360
at this
8296
05:07:01,760 --> 05:07:03,840
let's do the string here because when we
8297
05:07:03,840 --> 05:07:05,520
print it right now
8298
05:07:05,520 --> 05:07:06,958
if we print
8299
05:07:06,958 --> 05:07:09,440
c1 here you see it's
8300
05:07:09,440 --> 05:07:11,120
something that doesn't really make sense
8301
05:07:11,120 --> 05:07:12,718
here because
8302
05:07:12,718 --> 05:07:16,000
python doesn't know how this object
8303
05:07:16,000 --> 05:07:18,798
should be represented right so when you
8304
05:07:18,798 --> 05:07:20,638
call print on it it will just say well
8305
05:07:20,638 --> 05:07:23,200
this is main card object yada yada yada
8306
05:07:23,200 --> 05:07:24,798
right it doesn't make sense to us right
8307
05:07:24,798 --> 05:07:26,958
it makes sense to python because it's
8308
05:07:26,958 --> 05:07:29,200
object at this address here
8309
05:07:29,200 --> 05:07:31,360
which you can identify with it but when
8310
05:07:31,360 --> 05:07:33,520
we want to print an object we want it to
8311
05:07:33,520 --> 05:07:36,480
be represented in the suit and rank but
8312
05:07:36,480 --> 05:07:39,120
we can tell python that again by using
8313
05:07:39,120 --> 05:07:41,120
overwriting one of the
8314
05:07:41,120 --> 05:07:43,200
built-in functions which this one is
8315
05:07:43,200 --> 05:07:44,638
called string which is a string
8316
05:07:44,638 --> 05:07:46,160
representation
8317
05:07:46,160 --> 05:07:48,560
and as you see immediately i need to
8318
05:07:48,560 --> 05:07:51,200
put the self here as an argument which
8319
05:07:51,200 --> 05:07:53,840
is never sent to the object but it does
8320
05:07:53,840 --> 05:07:56,400
automatically by python and all the
8321
05:07:56,400 --> 05:07:58,400
thing we are assigned to the self can be
8322
05:07:58,400 --> 05:08:00,798
accessed in any methods here right so
8323
05:08:00,798 --> 05:08:04,240
here we will return the string
8324
05:08:04,240 --> 05:08:06,400
representation of the object so let's
8325
05:08:06,400 --> 05:08:08,240
try to do that
8326
05:08:08,240 --> 05:08:10,240
so it's excel
8327
05:08:10,240 --> 05:08:11,920
is it ranked first
8328
05:08:11,920 --> 05:08:14,958
yeah i think rank first and then we have
8329
05:08:14,958 --> 05:08:16,400
the self
8330
05:08:16,400 --> 05:08:18,080
suit here right
8331
05:08:18,080 --> 05:08:21,040
so this is a string representation of
8332
05:08:21,040 --> 05:08:23,680
our objects and you see now we changed
8333
05:08:23,680 --> 05:08:26,560
the class of that but we didn't change
8334
05:08:26,560 --> 05:08:31,200
these objects down here so if i was
8335
05:08:31,200 --> 05:08:32,798
printing again here
8336
05:08:32,798 --> 05:08:34,638
nothing changed but if i execute this
8337
05:08:34,638 --> 05:08:37,840
one here where i create new objects here
8338
05:08:37,840 --> 05:08:39,680
then it'll actually change and you see
8339
05:08:39,680 --> 05:08:42,080
here we have zero zero
8340
05:08:42,080 --> 05:08:43,600
and we can represent it as we want we
8341
05:08:43,600 --> 05:08:47,760
could say this is rank and this is
8342
05:08:47,760 --> 05:08:50,240
suit right
8343
05:08:50,240 --> 05:08:51,760
and now we have it again here and i can
8344
05:08:51,760 --> 05:08:53,920
actually print both of them inside here
8345
05:08:53,920 --> 05:08:57,200
right rank suit ranks you right you see
8346
05:08:57,200 --> 05:08:58,480
now
8347
05:08:58,480 --> 05:09:01,440
i want to represent it a bit nicer so
8348
05:09:01,440 --> 05:09:04,400
actually i throw in these two here
8349
05:09:04,400 --> 05:09:06,878
and what is that right so inside the
8350
05:09:06,878 --> 05:09:09,840
card class i sign some
8351
05:09:09,840 --> 05:09:13,600
lists here to represent the suit
8352
05:09:13,600 --> 05:09:14,560
by
8353
05:09:14,560 --> 05:09:16,320
unicode characters and you'll see in a
8354
05:09:16,320 --> 05:09:18,560
moment what they are they are the
8355
05:09:18,560 --> 05:09:21,200
hearts and clubs and so on spades and so
8356
05:09:21,200 --> 05:09:23,440
on and the ranks right i've done
8357
05:09:23,440 --> 05:09:25,760
something with the ranks i started by
8358
05:09:25,760 --> 05:09:28,638
two and end by a's right so these are
8359
05:09:28,638 --> 05:09:32,958
ordered in the row of uh value in our
8360
05:09:32,958 --> 05:09:34,798
card game right
8361
05:09:34,798 --> 05:09:37,600
but this is quite of nice but what it
8362
05:09:37,600 --> 05:09:40,480
also can do for us is actually make it
8363
05:09:40,480 --> 05:09:41,760
easier
8364
05:09:41,760 --> 05:09:44,000
prettier to print it so this is just to
8365
05:09:44,000 --> 05:09:46,160
make it pretty print
8366
05:09:46,160 --> 05:09:47,920
so how can i access this well i can
8367
05:09:47,920 --> 05:09:50,080
access those by
8368
05:09:50,080 --> 05:09:51,680
immediately just
8369
05:09:51,680 --> 05:09:52,878
access them
8370
05:09:52,878 --> 05:09:55,920
as a list of cards
8371
05:09:55,920 --> 05:09:59,040
on the object card right so that's
8372
05:09:59,040 --> 05:10:00,400
card here
8373
05:10:00,400 --> 05:10:02,480
uh ranks here
8374
05:10:02,480 --> 05:10:03,840
i think i did the opposite here it
8375
05:10:03,840 --> 05:10:05,920
should be ranks here i was talking to
8376
05:10:05,920 --> 05:10:06,840
you and
8377
05:10:06,840 --> 05:10:08,798
then
8378
05:10:08,798 --> 05:10:11,200
and then i messed it up
8379
05:10:11,200 --> 05:10:13,600
so here it should be suits right i think
8380
05:10:13,600 --> 05:10:17,040
i did it right now right
8381
05:10:17,040 --> 05:10:18,878
and then you see here then you get them
8382
05:10:18,878 --> 05:10:21,440
like this
8383
05:10:21,440 --> 05:10:22,718
right
8384
05:10:22,718 --> 05:10:24,320
three of hearts right
8385
05:10:24,320 --> 05:10:25,360
uh
8386
05:10:25,360 --> 05:10:28,000
perfect right so this just makes it look
8387
05:10:28,000 --> 05:10:30,798
prettier so this is strictly not needed
8388
05:10:30,798 --> 05:10:32,560
but it's just
8389
05:10:32,560 --> 05:10:35,040
yeah these are the unicodes right
8390
05:10:35,040 --> 05:10:37,040
so apparently this is hearts
8391
05:10:37,040 --> 05:10:39,840
hearts of three y is three when it was
8392
05:10:39,840 --> 05:10:43,360
one one right you see is because the one
8393
05:10:43,360 --> 05:10:45,680
index is this one and the one index is
8394
05:10:45,680 --> 05:10:47,360
this one right so this is unicode for
8395
05:10:47,360 --> 05:10:50,240
hearts and this is the value of 1 which
8396
05:10:50,240 --> 05:10:52,638
is 3 now right but that's because we
8397
05:10:52,638 --> 05:10:56,000
want ace to be the highest value
8398
05:10:56,000 --> 05:10:57,920
when we do our game
8399
05:10:57,920 --> 05:10:59,520
you don't know that yet but
8400
05:10:59,520 --> 05:11:01,600
that's how we rank it right so this was
8401
05:11:01,600 --> 05:11:03,600
a string
8402
05:11:03,600 --> 05:11:05,360
but we want to continue
8403
05:11:05,360 --> 05:11:07,120
we want to make something called a less
8404
05:11:07,120 --> 05:11:09,680
than and this is comparator because if
8405
05:11:09,680 --> 05:11:12,160
we compare the two right now if we say
8406
05:11:12,160 --> 05:11:13,840
c1
8407
05:11:13,840 --> 05:11:17,280
is let's say c1 is less than c2
8408
05:11:17,280 --> 05:11:18,958
it doesn't know what to do it because it
8409
05:11:18,958 --> 05:11:21,360
says well type error not supported
8410
05:11:21,360 --> 05:11:23,680
between instance of card and card
8411
05:11:23,680 --> 05:11:25,520
because we haven't defined
8412
05:11:25,520 --> 05:11:29,680
the function yet so let's do that lesson
8413
05:11:29,680 --> 05:11:32,718
self it takes itself and then the other
8414
05:11:32,718 --> 05:11:34,160
perfect
8415
05:11:34,160 --> 05:11:36,080
and what we want to do here is actually
8416
05:11:36,080 --> 05:11:38,160
if the rank
8417
05:11:38,160 --> 05:11:39,600
is the same
8418
05:11:39,600 --> 05:11:42,080
of the card that means we have
8419
05:11:42,080 --> 05:11:43,920
for instance we have three
8420
05:11:43,920 --> 05:11:45,760
of the rank and the other card is three
8421
05:11:45,760 --> 05:11:47,680
then we go to the suit and ordered by
8422
05:11:47,680 --> 05:11:50,480
that so let's do that so if
8423
05:11:50,480 --> 05:11:54,000
self rank equals equals other rank
8424
05:11:54,000 --> 05:11:55,600
this is the other card
8425
05:11:55,600 --> 05:11:59,480
in that case we return self suit
8426
05:11:59,480 --> 05:12:01,440
lessons
8427
05:12:01,440 --> 05:12:03,520
other suit right
8428
05:12:03,520 --> 05:12:05,280
and else
8429
05:12:05,280 --> 05:12:07,600
else we return
8430
05:12:07,600 --> 05:12:10,320
self rank because now they're not the
8431
05:12:10,320 --> 05:12:11,920
same suit
8432
05:12:11,920 --> 05:12:15,280
rank other rank here right so
8433
05:12:15,280 --> 05:12:17,360
what we can do now is compare them right
8434
05:12:17,360 --> 05:12:18,080
so
8435
05:12:18,080 --> 05:12:20,560
this less than comparator again this is
8436
05:12:20,560 --> 05:12:22,320
python doing all the
8437
05:12:22,320 --> 05:12:24,798
things for us it will take and take
8438
05:12:24,798 --> 05:12:27,520
another card and call it other and then
8439
05:12:27,520 --> 05:12:29,040
they will call it on this and then they
8440
05:12:29,040 --> 05:12:31,600
can order them based on that
8441
05:12:31,600 --> 05:12:34,160
and we just say how it should be ordered
8442
05:12:34,160 --> 05:12:36,320
it says if we have the same rank well
8443
05:12:36,320 --> 05:12:38,878
then we use a suit in this order up here
8444
05:12:38,878 --> 05:12:40,560
right
8445
05:12:40,560 --> 05:12:42,638
and if the rank are different then it's
8446
05:12:42,638 --> 05:12:45,200
a rank counting so let's try to execute
8447
05:12:45,200 --> 05:12:47,040
that
8448
05:12:47,040 --> 05:12:50,000
so in this case here we have true that
8449
05:12:50,000 --> 05:12:51,680
obviously these are smaller than this
8450
05:12:51,680 --> 05:12:53,280
one if you put it opposite it will be
8451
05:12:53,280 --> 05:12:55,120
false right so you see that
8452
05:12:55,120 --> 05:12:56,718
so that's how you can implement that and
8453
05:12:56,718 --> 05:12:58,878
now we have now we can order the card so
8454
05:12:58,878 --> 05:13:01,120
we in our card game can say which card
8455
05:13:01,120 --> 05:13:02,320
is higher
8456
05:13:02,320 --> 05:13:04,958
higher rank than the other card right
8457
05:13:04,958 --> 05:13:07,600
isn't that nice i think so
8458
05:13:07,600 --> 05:13:08,718
awesome
8459
05:13:08,718 --> 05:13:10,958
perfect that well that was actually the
8460
05:13:10,958 --> 05:13:13,040
first class here we did here so now we
8461
05:13:13,040 --> 05:13:16,240
have card class here and we can create
8462
05:13:16,240 --> 05:13:19,040
instances of this card now the next one
8463
05:13:19,040 --> 05:13:20,718
here is deck
8464
05:13:20,718 --> 05:13:23,680
so deck has a list of cards and it also
8465
05:13:23,680 --> 05:13:25,360
has a length
8466
05:13:25,360 --> 05:13:27,760
method and then they have add card
8467
05:13:27,760 --> 05:13:29,760
pop card and shuffle let's try and do
8468
05:13:29,760 --> 05:13:31,600
that
8469
05:13:31,600 --> 05:13:33,040
now we're actually getting experience
8470
05:13:33,040 --> 05:13:35,680
right so class deck
8471
05:13:35,680 --> 05:13:37,760
we need to do this init function because
8472
05:13:37,760 --> 05:13:39,120
what we want to do in that in the
8473
05:13:39,120 --> 05:13:40,638
function is
8474
05:13:40,638 --> 05:13:43,360
have the cards right the list of cards
8475
05:13:43,360 --> 05:13:45,040
there
8476
05:13:45,040 --> 05:13:46,718
so def
8477
05:13:46,718 --> 05:13:49,040
init
8478
05:13:49,040 --> 05:13:50,560
self
8479
05:13:50,560 --> 05:13:51,520
here
8480
05:13:51,520 --> 05:13:54,160
and then we do self-deck so so far it's
8481
05:13:54,160 --> 05:13:56,080
just an empty list let's just do it like
8482
05:13:56,080 --> 05:13:58,080
that and the first
8483
05:13:58,080 --> 05:14:01,600
method we implement is the length method
8484
05:14:01,600 --> 05:14:04,400
this one here right
8485
05:14:04,400 --> 05:14:05,920
and this is quite simple this is
8486
05:14:05,920 --> 05:14:07,760
actually so when you have a deck of
8487
05:14:07,760 --> 05:14:09,760
cards what makes sense to be the length
8488
05:14:09,760 --> 05:14:12,480
of it right it's the number of cards we
8489
05:14:12,480 --> 05:14:13,680
have in it right
8490
05:14:13,680 --> 05:14:16,240
so that will be basically return the
8491
05:14:16,240 --> 05:14:17,120
cell
8492
05:14:17,120 --> 05:14:20,320
or the length of self
8493
05:14:20,320 --> 05:14:21,680
self
8494
05:14:21,680 --> 05:14:23,200
attack here right
8495
05:14:23,200 --> 05:14:25,760
perfect so let's try to make a deck here
8496
05:14:25,760 --> 05:14:27,280
take here
8497
05:14:27,280 --> 05:14:28,480
deck
8498
05:14:28,480 --> 05:14:30,320
and then we can take the length of that
8499
05:14:30,320 --> 05:14:33,280
deck here and it will be zero right
8500
05:14:33,280 --> 05:14:35,520
makes sense right in a moment we will we
8501
05:14:35,520 --> 05:14:38,320
will create uh we will add some cards to
8502
05:14:38,320 --> 05:14:39,520
it right
8503
05:14:39,520 --> 05:14:40,718
def
8504
05:14:40,718 --> 05:14:41,600
add
8505
05:14:41,600 --> 05:14:42,638
card
8506
05:14:42,638 --> 05:14:44,560
self again we have to add self and then
8507
05:14:44,560 --> 05:14:46,080
we have a card here
8508
05:14:46,080 --> 05:14:47,520
and what should we do we should add the
8509
05:14:47,520 --> 05:14:50,560
card to the deck so we take it self
8510
05:14:50,560 --> 05:14:51,760
append
8511
05:14:51,760 --> 05:14:54,320
card right so let's actually try to do
8512
05:14:54,320 --> 05:14:55,920
that right and again we need to execute
8513
05:14:55,920 --> 05:14:58,240
this one here but let's just do it all
8514
05:14:58,240 --> 05:15:01,600
in this cell here so we took take deck
8515
05:15:01,600 --> 05:15:03,840
add
8516
05:15:04,000 --> 05:15:07,120
card and we just we had the c1 here and
8517
05:15:07,120 --> 05:15:09,920
then we take length of deck
8518
05:15:09,920 --> 05:15:14,160
and you see something went wrong here
8519
05:15:14,480 --> 05:15:17,440
and it says here add card
8520
05:15:17,440 --> 05:15:19,440
add card
8521
05:15:19,440 --> 05:15:22,480
deck object has no attributes self
8522
05:15:22,480 --> 05:15:25,120
oh it says self self that was my mistake
8523
05:15:25,120 --> 05:15:27,680
thank you for correcting that one
8524
05:15:27,680 --> 05:15:30,798
perfect oh it says again takeover is no
8525
05:15:30,798 --> 05:15:33,360
no self it was self no not sell self
8526
05:15:33,360 --> 05:15:35,280
itself tech i should
8527
05:15:35,280 --> 05:15:37,200
append here right thank you for helping
8528
05:15:37,200 --> 05:15:39,440
me out on that one right so now you see
8529
05:15:39,440 --> 05:15:40,638
here that
8530
05:15:40,638 --> 05:15:42,840
the length of
8531
05:15:42,840 --> 05:15:45,680
this is one now right because we added
8532
05:15:45,680 --> 05:15:47,920
one card when we create a deck here
8533
05:15:47,920 --> 05:15:51,040
similarly we could add another one here
8534
05:15:51,040 --> 05:15:54,958
deck add card c2 here right and then it
8535
05:15:54,958 --> 05:15:57,440
will be length of two now it should be
8536
05:15:57,440 --> 05:15:58,958
obvious right
8537
05:15:58,958 --> 05:16:01,520
good and we can also have the
8538
05:16:01,520 --> 05:16:02,878
pop card
8539
05:16:02,878 --> 05:16:04,480
pop card
8540
05:16:04,480 --> 05:16:06,798
itself it doesn't take anything but it
8541
05:16:06,798 --> 05:16:09,200
returns itself
8542
05:16:09,200 --> 05:16:11,760
and it takes a deck now i have to
8543
05:16:11,760 --> 05:16:14,000
remember right and pop from it because
8544
05:16:14,000 --> 05:16:16,718
this list we can append and pop right
8545
05:16:16,718 --> 05:16:20,240
and if we added these two we can have uh
8546
05:16:20,240 --> 05:16:22,798
deck and we pop again here
8547
05:16:22,798 --> 05:16:24,638
not poop pop
8548
05:16:24,638 --> 05:16:28,638
and uh it should be pop card
8549
05:16:28,638 --> 05:16:30,718
and there's one back here right perfect
8550
05:16:30,718 --> 05:16:33,520
you understand it now right
8551
05:16:33,520 --> 05:16:36,878
good so far so good so this is add card
8552
05:16:36,878 --> 05:16:38,240
and pop card
8553
05:16:38,240 --> 05:16:40,240
let's just jump back to the init method
8554
05:16:40,240 --> 05:16:42,638
here because in our game what we want to
8555
05:16:42,638 --> 05:16:45,120
do is have these 52 cards and why not
8556
05:16:45,120 --> 05:16:47,920
let the deck itself add these cards to
8557
05:16:47,920 --> 05:16:49,520
it and we kind of made that nice
8558
05:16:49,520 --> 05:16:52,080
remember how the card is defined right
8559
05:16:52,080 --> 05:16:54,480
it takes a suit and a rank right and the
8560
05:16:54,480 --> 05:16:56,878
suit is from index from zero one two
8561
05:16:56,878 --> 05:16:59,920
three and the rank is from zero one of
8562
05:16:59,920 --> 05:17:02,400
all the way to twelve
8563
05:17:02,400 --> 05:17:04,878
okay so let's do a four loop and a four
8564
05:17:04,878 --> 05:17:06,320
loop so four
8565
05:17:06,320 --> 05:17:09,040
suit in range
8566
05:17:09,040 --> 05:17:11,440
four right that's one two three four no
8567
05:17:11,440 --> 05:17:13,280
zero one two three thank you for
8568
05:17:13,280 --> 05:17:14,400
reminding me
8569
05:17:14,400 --> 05:17:17,840
and for rank in range
8570
05:17:17,840 --> 05:17:20,240
thirteen it's from zero to twelve now
8571
05:17:20,240 --> 05:17:21,520
you get it right
8572
05:17:21,520 --> 05:17:24,560
i get it at least uh self
8573
05:17:24,560 --> 05:17:26,160
deck
8574
05:17:26,160 --> 05:17:27,280
deck
8575
05:17:27,280 --> 05:17:28,798
append
8576
05:17:28,798 --> 05:17:31,680
and then we take a card and let's exude
8577
05:17:31,680 --> 05:17:33,520
and rank right so you see what's
8578
05:17:33,520 --> 05:17:35,760
happening now now we added all of them
8579
05:17:35,760 --> 05:17:37,040
to there so let's try to do that
8580
05:17:37,040 --> 05:17:38,480
actually dunk
8581
05:17:38,480 --> 05:17:41,440
and let's not do this one anymore let's
8582
05:17:41,440 --> 05:17:43,520
just create a deck and see there are 52
8583
05:17:43,520 --> 05:17:46,160
cards in it now right so you see
8584
05:17:46,160 --> 05:17:49,120
now we added all the cards and they're
8585
05:17:49,120 --> 05:17:52,000
only unique cards in it right you see
8586
05:17:52,000 --> 05:17:55,120
because we take it suit by suit and rank
8587
05:17:55,120 --> 05:17:58,798
by rank and add them one by one
8588
05:17:58,798 --> 05:18:00,718
and as you see here the final thing we
8589
05:18:00,718 --> 05:18:02,718
want to do is shuffle so let's try to
8590
05:18:02,718 --> 05:18:04,958
make a shuffle and to do that we need
8591
05:18:04,958 --> 05:18:07,680
some randomness right randomness we love
8592
05:18:07,680 --> 05:18:08,798
randomness
8593
05:18:08,798 --> 05:18:11,840
so let's just import random here import
8594
05:18:11,840 --> 05:18:15,120
random boom and random has what we need
8595
05:18:15,120 --> 05:18:17,680
right so let's just say def
8596
05:18:17,680 --> 05:18:20,080
shuffle
8597
05:18:20,080 --> 05:18:21,520
self
8598
05:18:21,520 --> 05:18:24,480
and then we take
8599
05:18:24,798 --> 05:18:26,090
random
8600
05:18:26,090 --> 05:18:27,440
[Music]
8601
05:18:27,440 --> 05:18:29,600
shuffle
8602
05:18:29,600 --> 05:18:33,400
and then we take
8603
05:18:33,920 --> 05:18:35,040
then we take
8604
05:18:35,040 --> 05:18:38,160
self deck on it right boom so what i
8605
05:18:38,160 --> 05:18:40,560
want to show now is that if we take the
8606
05:18:40,560 --> 05:18:42,798
deck here and we
8607
05:18:42,798 --> 05:18:47,120
print let's say we take the deck and
8608
05:18:47,120 --> 05:18:47,920
pop
8609
05:18:47,920 --> 05:18:48,798
card
8610
05:18:48,798 --> 05:18:50,638
what happens if if we play it again
8611
05:18:50,638 --> 05:18:53,040
again is the same card right
8612
05:18:53,040 --> 05:18:55,280
but what happens if we take deck now and
8613
05:18:55,280 --> 05:18:56,320
shuffle
8614
05:18:56,320 --> 05:18:57,440
what do you think
8615
05:18:57,440 --> 05:18:59,920
well we get a different card from game
8616
05:18:59,920 --> 05:19:01,200
to game
8617
05:19:01,200 --> 05:19:02,958
right you see
8618
05:19:02,958 --> 05:19:04,240
awesome right
8619
05:19:04,240 --> 05:19:06,240
and maybe we actually
8620
05:19:06,240 --> 05:19:08,560
just use the detail that actually we
8621
05:19:08,560 --> 05:19:10,240
just every time we
8622
05:19:10,240 --> 05:19:12,320
make a deck of cards let's just shuffle
8623
05:19:12,320 --> 05:19:15,120
them you could do that by calling self
8624
05:19:15,120 --> 05:19:17,280
shuffle right then you call shuffle on
8625
05:19:17,280 --> 05:19:19,040
yourself right so if you
8626
05:19:19,040 --> 05:19:20,798
create that then we actually don't need
8627
05:19:20,798 --> 05:19:22,638
to call shuffle here
8628
05:19:22,638 --> 05:19:26,080
then we get a new card every time right
8629
05:19:26,080 --> 05:19:28,638
so that's actually the deck so now we
8630
05:19:28,638 --> 05:19:30,160
are ready for the
8631
05:19:30,160 --> 05:19:31,840
hand over here
8632
05:19:31,840 --> 05:19:34,080
so what is the hand the hand is of type
8633
05:19:34,080 --> 05:19:36,638
deck and i'll show you how to do that
8634
05:19:36,638 --> 05:19:38,798
it has cards again it has a label and
8635
05:19:38,798 --> 05:19:40,320
win count and then it has a string
8636
05:19:40,320 --> 05:19:42,560
representation it has get label which is
8637
05:19:42,560 --> 05:19:44,718
the label we set here and a round winner
8638
05:19:44,718 --> 05:19:46,718
and get win count so let's try to do
8639
05:19:46,718 --> 05:19:49,200
that it's going to be exciting huh
8640
05:19:49,200 --> 05:19:50,718
so class
8641
05:19:50,718 --> 05:19:53,200
hand and because it's a type deck we
8642
05:19:53,200 --> 05:19:55,120
just add the deck here
8643
05:19:55,120 --> 05:19:58,000
so if we didn't create an init function
8644
05:19:58,000 --> 05:19:59,920
in this one it will call this init
8645
05:19:59,920 --> 05:20:04,080
function here right because it's of type
8646
05:20:04,080 --> 05:20:06,240
it's a bit confusing at first right but
8647
05:20:06,240 --> 05:20:08,320
hand we declare that of type deck that
8648
05:20:08,320 --> 05:20:11,600
means it inherits all these methods we
8649
05:20:11,600 --> 05:20:13,200
defined here
8650
05:20:13,200 --> 05:20:15,440
so but we also have the option of
8651
05:20:15,440 --> 05:20:16,958
overriding and we're going to do that
8652
05:20:16,958 --> 05:20:19,200
because in the hand we don't want
8653
05:20:19,200 --> 05:20:21,920
we don't want to shuffle a
8654
05:20:21,920 --> 05:20:23,600
total deck of cards so what we're gonna
8655
05:20:23,600 --> 05:20:26,320
do is init
8656
05:20:26,320 --> 05:20:27,280
here
8657
05:20:27,280 --> 05:20:29,840
and we need self and we need a label
8658
05:20:29,840 --> 05:20:31,600
also so it's also already different
8659
05:20:31,600 --> 05:20:33,680
right but we need to remember to have
8660
05:20:33,680 --> 05:20:36,480
the deck here because we don't
8661
05:20:36,480 --> 05:20:38,240
otherwise we don't have it right so this
8662
05:20:38,240 --> 05:20:39,040
is it
8663
05:20:39,040 --> 05:20:42,160
and then we have the self label
8664
05:20:42,160 --> 05:20:44,080
and we set the label and then we
8665
05:20:44,080 --> 05:20:45,520
remember we had the
8666
05:20:45,520 --> 05:20:48,400
win count was the win count i think so
8667
05:20:48,400 --> 05:20:51,120
and we add the win count there
8668
05:20:51,120 --> 05:20:52,480
so these are the
8669
05:20:52,480 --> 05:20:54,400
variables
8670
05:20:54,400 --> 05:20:57,200
or the parameters that our objects will
8671
05:20:57,200 --> 05:20:58,480
have right
8672
05:20:58,480 --> 05:21:00,320
and the next thing we wanted to do was
8673
05:21:00,320 --> 05:21:01,200
um
8674
05:21:01,200 --> 05:21:03,360
yeah what was the thing we weighed a bit
8675
05:21:03,360 --> 05:21:06,320
with string actually or should we no
8676
05:21:06,320 --> 05:21:10,400
let's just add string immediately def
8677
05:21:10,400 --> 05:21:11,760
string
8678
05:21:11,760 --> 05:21:13,680
and we have the self here
8679
05:21:13,680 --> 05:21:16,080
so string should represent the the
8680
05:21:16,080 --> 05:21:18,958
object that we're creating right so
8681
05:21:18,958 --> 05:21:21,760
return
8682
05:21:21,760 --> 05:21:23,120
i actually think we should take the
8683
05:21:23,120 --> 05:21:25,920
label here and we can just concatenate
8684
05:21:25,920 --> 05:21:29,280
here and then we concatenate a colon
8685
05:21:29,280 --> 05:21:30,718
so we have the
8686
05:21:30,718 --> 05:21:34,080
label of the hand the colon and then we
8687
05:21:34,080 --> 05:21:36,000
want to
8688
05:21:36,000 --> 05:21:37,760
actually we want to
8689
05:21:37,760 --> 05:21:39,840
take the deck we have and print it out
8690
05:21:39,840 --> 05:21:44,000
right so we do that by a join here
8691
05:21:44,000 --> 05:21:46,160
but this is catch right because we don't
8692
05:21:46,160 --> 05:21:48,878
need to call string on each object in
8693
05:21:48,878 --> 05:21:51,520
the deck otherwise it will not look nice
8694
05:21:51,520 --> 05:21:54,160
so string
8695
05:21:54,480 --> 05:21:55,760
card
8696
05:21:55,760 --> 05:21:57,680
for
8697
05:21:57,680 --> 05:21:59,760
card in self
8698
05:21:59,760 --> 05:22:02,240
deck right you see what's happening here
8699
05:22:02,240 --> 05:22:05,440
so we take card by card in the deck and
8700
05:22:05,440 --> 05:22:07,280
then we call string on then and then we
8701
05:22:07,280 --> 05:22:08,798
have the list here this is list
8702
05:22:08,798 --> 05:22:10,240
comprehension right
8703
05:22:10,240 --> 05:22:12,080
and then we join that on this one here
8704
05:22:12,080 --> 05:22:13,520
actually we should have a space here and
8705
05:22:13,520 --> 05:22:15,360
then here right i think this is actually
8706
05:22:15,360 --> 05:22:16,958
nice so
8707
05:22:16,958 --> 05:22:18,798
now we can have a hand here and this
8708
05:22:18,798 --> 05:22:21,120
hand here it will take a label and let's
8709
05:22:21,120 --> 05:22:24,638
just call it player here and this hand
8710
05:22:24,638 --> 05:22:27,920
because we are of type deck here we can
8711
05:22:27,920 --> 05:22:30,160
call the methods up here so let's add
8712
05:22:30,160 --> 05:22:31,040
card
8713
05:22:31,040 --> 05:22:32,080
add
8714
05:22:32,080 --> 05:22:34,080
card and we can actually take our deck
8715
05:22:34,080 --> 05:22:36,958
and pop card right
8716
05:22:36,958 --> 05:22:38,958
let's do that and then we actually print
8717
05:22:38,958 --> 05:22:40,638
hand
8718
05:22:40,638 --> 05:22:41,920
boom
8719
05:22:41,920 --> 05:22:44,958
you see here that's it and uh actually
8720
05:22:44,958 --> 05:22:46,718
we can do
8721
05:22:46,718 --> 05:22:49,200
a few here just three just for fun and
8722
05:22:49,200 --> 05:22:52,160
you see we get three cards in there
8723
05:22:52,160 --> 05:22:54,320
okay you see how that worked
8724
05:22:54,320 --> 05:22:56,080
awesome right
8725
05:22:56,080 --> 05:22:57,600
perfect
8726
05:22:57,600 --> 05:22:58,718
uh
8727
05:22:58,718 --> 05:23:00,320
good that was the first step of hand and
8728
05:23:00,320 --> 05:23:02,480
then we needed to do get label round
8729
05:23:02,480 --> 05:23:04,160
winner and get win count that's
8730
05:23:04,160 --> 05:23:06,878
straightforward
8731
05:23:07,440 --> 05:23:08,400
def
8732
05:23:08,400 --> 05:23:10,840
get label
8733
05:23:10,840 --> 05:23:14,878
self and then we just have that return
8734
05:23:14,878 --> 05:23:16,080
self
8735
05:23:16,080 --> 05:23:18,480
let's just call label it just returns a
8736
05:23:18,480 --> 05:23:20,798
label we just need that
8737
05:23:20,798 --> 05:23:22,878
and if you get
8738
05:23:22,878 --> 05:23:24,840
win count
8739
05:23:24,840 --> 05:23:28,878
myself and uh return self
8740
05:23:28,878 --> 05:23:29,760
win
8741
05:23:29,760 --> 05:23:32,160
count
8742
05:23:32,638 --> 05:23:35,200
perfect and then death
8743
05:23:35,200 --> 05:23:37,360
uh
8744
05:23:37,360 --> 05:23:39,520
round winner wasn't that what was called
8745
05:23:39,520 --> 05:23:42,160
round winner itself and what that does
8746
05:23:42,160 --> 05:23:44,080
is just take self
8747
05:23:44,080 --> 05:23:45,040
win
8748
05:23:45,040 --> 05:23:48,160
count equals self
8749
05:23:48,160 --> 05:23:49,520
win
8750
05:23:49,520 --> 05:23:52,798
count plus one right so you win one
8751
05:23:52,798 --> 05:23:56,160
round right so
8752
05:23:56,240 --> 05:23:58,080
yeah basically what this does is
8753
05:23:58,080 --> 05:23:59,760
actually right let's just
8754
05:23:59,760 --> 05:24:01,920
play around with that
8755
05:24:01,920 --> 05:24:03,760
i executed that one above there right so
8756
05:24:03,760 --> 05:24:06,240
i can get for instance i can get
8757
05:24:06,240 --> 05:24:09,680
a label here then i get the label
8758
05:24:09,680 --> 05:24:11,760
i can get the
8759
05:24:11,760 --> 05:24:13,520
hand get
8760
05:24:13,520 --> 05:24:16,160
wind count i get the win count it's zero
8761
05:24:16,160 --> 05:24:18,240
but if i add it
8762
05:24:18,240 --> 05:24:19,600
and
8763
05:24:19,600 --> 05:24:21,280
round winner
8764
05:24:21,280 --> 05:24:23,200
then here in the case i would have won
8765
05:24:23,200 --> 05:24:27,600
one round right in if i added two rounds
8766
05:24:27,600 --> 05:24:29,280
two round winners here i will have two
8767
05:24:29,280 --> 05:24:32,080
rounds here right so this is basically
8768
05:24:32,080 --> 05:24:34,718
it this is amazing right so we created
8769
05:24:34,718 --> 05:24:37,680
this class over here as well and we'll
8770
05:24:37,680 --> 05:24:38,638
learn
8771
05:24:38,638 --> 05:24:40,798
what this deck
8772
05:24:40,798 --> 05:24:42,558
means here that it
8773
05:24:42,558 --> 05:24:46,000
inherits all the methods of this deck
8774
05:24:46,000 --> 05:24:46,958
here
8775
05:24:46,958 --> 05:24:49,360
and so we can access the same method on
8776
05:24:49,360 --> 05:24:50,958
the same object that's that's amazing
8777
05:24:50,958 --> 05:24:53,840
right so we have card deck and hand now
8778
05:24:53,840 --> 05:24:55,840
we are ready to create our first card
8779
05:24:55,840 --> 05:24:58,958
game i am are you i hope so because it's
8780
05:24:58,958 --> 05:25:00,320
going to be amazing
8781
05:25:00,320 --> 05:25:01,520
so
8782
05:25:01,520 --> 05:25:03,280
if you find this a bit confusing don't
8783
05:25:03,280 --> 05:25:06,718
worry i advise you before you start
8784
05:25:06,718 --> 05:25:09,040
play around with these classes
8785
05:25:09,040 --> 05:25:11,440
until you get the aspect of it the key
8786
05:25:11,440 --> 05:25:13,600
thing is to remember is that these
8787
05:25:13,600 --> 05:25:16,878
objects are resembling reality right
8788
05:25:16,878 --> 05:25:18,718
this is why you create them they
8789
05:25:18,718 --> 05:25:21,360
resemble reality so a card is a car that
8790
05:25:21,360 --> 05:25:23,520
deck is a second hand in his hand so it
8791
05:25:23,520 --> 05:25:25,440
comes in handy
8792
05:25:25,440 --> 05:25:27,040
when you do your programming because it
8793
05:25:27,040 --> 05:25:29,360
becomes easier for you to
8794
05:25:29,360 --> 05:25:30,080
to
8795
05:25:30,080 --> 05:25:32,080
to model your program inside there and
8796
05:25:32,080 --> 05:25:34,160
it can be easier to understand okay so
8797
05:25:34,160 --> 05:25:35,440
see you in a moment it's going to be
8798
05:25:35,440 --> 05:25:38,240
exciting see you
8799
05:25:40,558 --> 05:25:42,718
i hope you are excited because this is
8800
05:25:42,718 --> 05:25:44,480
going to be exciting you're going to
8801
05:25:44,480 --> 05:25:47,280
create your first card game using
8802
05:25:47,280 --> 05:25:49,360
object-oriented programming so let's
8803
05:25:49,360 --> 05:25:50,878
jump to jupyter notebook and look at
8804
05:25:50,878 --> 05:25:53,440
that right project object-oriented
8805
05:25:53,440 --> 05:25:56,718
programming create a card game goal
8806
05:25:56,718 --> 05:25:59,040
learn basic object-oriented programming
8807
05:25:59,040 --> 05:26:01,840
create a simple game right so in the
8808
05:26:01,840 --> 05:26:04,558
last one we created these three classes
8809
05:26:04,558 --> 05:26:07,600
here which we are going to use the card
8810
05:26:07,600 --> 05:26:09,840
the deck and the hand
8811
05:26:09,840 --> 05:26:10,798
and
8812
05:26:10,798 --> 05:26:13,760
the card game is simple as this one here
8813
05:26:13,760 --> 05:26:15,840
we start simple right
8814
05:26:15,840 --> 05:26:19,760
so the card game create a deck of cards
8815
05:26:19,760 --> 05:26:23,840
create four players p1 p2 p3 p4
8816
05:26:23,840 --> 05:26:24,718
okay
8817
05:26:24,718 --> 05:26:27,360
divide all cards to the four players
8818
05:26:27,360 --> 05:26:28,400
okay
8819
05:26:28,400 --> 05:26:31,600
assume you are p1 print the hand of p1
8820
05:26:31,600 --> 05:26:34,000
then the game has 13 rounds right this
8821
05:26:34,000 --> 05:26:36,400
sounds like a four low each player plays
8822
05:26:36,400 --> 05:26:37,760
one card
8823
05:26:37,760 --> 05:26:40,958
the player with the highest card wins
8824
05:26:40,958 --> 05:26:43,680
update the score for the winning hand
8825
05:26:43,680 --> 05:26:46,558
print the cards played in round in the
8826
05:26:46,558 --> 05:26:48,320
round and the winner
8827
05:26:48,320 --> 05:26:50,080
with the winning card
8828
05:26:50,080 --> 05:26:52,000
after the 13 rounds print the score of
8829
05:26:52,000 --> 05:26:55,360
all players p1 p2 with p3 p4 so this is
8830
05:26:55,360 --> 05:26:57,200
actually the recipe of what you should
8831
05:26:57,200 --> 05:26:58,878
do and
8832
05:26:58,878 --> 05:27:01,200
while just stepping through these might
8833
05:27:01,200 --> 05:27:02,320
be a bit
8834
05:27:02,320 --> 05:27:05,200
more complex than you think right but i
8835
05:27:05,200 --> 05:27:08,000
hope you manage and the classes are
8836
05:27:08,000 --> 05:27:10,718
available here so you just import them
8837
05:27:10,718 --> 05:27:13,360
and then you just try to follow along uh
8838
05:27:13,360 --> 05:27:15,520
the implementation of the game here and
8839
05:27:15,520 --> 05:27:17,760
see how far you come and if you get
8840
05:27:17,760 --> 05:27:18,718
stuck
8841
05:27:18,718 --> 05:27:20,638
in the next one i'm gonna help you so
8842
05:27:20,638 --> 05:27:21,760
don't worry
8843
05:27:21,760 --> 05:27:24,638
it is a bit confusing at first but every
8844
05:27:24,638 --> 05:27:26,240
time you try something and the more time
8845
05:27:26,240 --> 05:27:29,200
you longer you try then the more you
8846
05:27:29,200 --> 05:27:31,600
learn right it's also okay to get stuck
8847
05:27:31,600 --> 05:27:33,280
see until then and then try it yourself
8848
05:27:33,280 --> 05:27:35,760
again afterwards right remember
8849
05:27:35,760 --> 05:27:37,680
the more time you spend programming the
8850
05:27:37,680 --> 05:27:39,520
more time you start learn the more you
8851
05:27:39,520 --> 05:27:40,558
learn right
8852
05:27:40,558 --> 05:27:43,280
for me i've been spending hours for
8853
05:27:43,280 --> 05:27:45,200
coming nowhere sometimes feeling like
8854
05:27:45,200 --> 05:27:47,280
that but in the end you will succeed
8855
05:27:47,280 --> 05:27:49,200
you'll learn something all the time so
8856
05:27:49,200 --> 05:27:50,160
see you
8857
05:27:50,160 --> 05:27:53,280
enjoy it and then i will help you
8858
05:27:53,280 --> 05:27:57,040
if needed see you in the next one
8859
05:28:00,000 --> 05:28:02,958
this is cool right a card game how far
8860
05:28:02,958 --> 05:28:04,958
did you come please let me know in the
8861
05:28:04,958 --> 05:28:06,958
comments and don't worry if you didn't
8862
05:28:06,958 --> 05:28:09,040
manage all it's
8863
05:28:09,040 --> 05:28:10,878
it is complex to make these things so
8864
05:28:10,878 --> 05:28:13,040
let's jump right
8865
05:28:13,040 --> 05:28:15,360
down to it so
8866
05:28:15,360 --> 05:28:16,958
remember we have all the classes there
8867
05:28:16,958 --> 05:28:18,878
and they are implemented and obviously
8868
05:28:18,878 --> 05:28:21,680
you should use them right so
8869
05:28:21,680 --> 05:28:23,760
i want to use this recipe so i'm just
8870
05:28:23,760 --> 05:28:25,680
going to move it a bit down here and to
8871
05:28:25,680 --> 05:28:27,760
have it where i implement the
8872
05:28:27,760 --> 05:28:30,000
game here okay
8873
05:28:30,000 --> 05:28:32,638
so the way i'm going to do it is
8874
05:28:32,638 --> 05:28:34,240
i'm just gonna implement it straight
8875
05:28:34,240 --> 05:28:36,558
forward here right so
8876
05:28:36,558 --> 05:28:38,878
the first step is uh create a deck of
8877
05:28:38,878 --> 05:28:40,320
cards right
8878
05:28:40,320 --> 05:28:43,360
hmm let's do that deck it's a deck right
8879
05:28:43,360 --> 05:28:45,040
so now we actually have the deck of
8880
05:28:45,040 --> 05:28:46,718
cards here right so this is the first
8881
05:28:46,718 --> 05:28:50,080
step of the description so now we need
8882
05:28:50,080 --> 05:28:54,320
to create four players p1 p2 p3 p4
8883
05:28:54,320 --> 05:28:56,160
how do you want to do that right they
8884
05:28:56,160 --> 05:28:57,840
are hands right
8885
05:28:57,840 --> 05:29:00,798
these are the hand object right
8886
05:29:00,798 --> 05:29:03,360
never created up here right so a player
8887
05:29:03,360 --> 05:29:05,920
has a hand and a label right it's going
8888
05:29:05,920 --> 05:29:08,638
to be called p1 people p2 and so forth
8889
05:29:08,638 --> 05:29:10,798
right so let's make a list of hands
8890
05:29:10,798 --> 05:29:12,718
right so we
8891
05:29:12,718 --> 05:29:15,280
can reference them again right
8892
05:29:15,280 --> 05:29:18,798
hands so four
8893
05:29:19,280 --> 05:29:22,558
let's just call i in range
8894
05:29:22,558 --> 05:29:25,280
four so we have the players p1 p2 p3
8895
05:29:25,280 --> 05:29:27,760
before
8896
05:29:28,240 --> 05:29:31,040
to be strictly we want the column p1 p2
8897
05:29:31,040 --> 05:29:33,680
up to p4 so we need range from one to
8898
05:29:33,680 --> 05:29:36,718
five right that will index i for one two
8899
05:29:36,718 --> 05:29:38,160
three four right
8900
05:29:38,160 --> 05:29:40,240
good and then we take hands and we
8901
05:29:40,240 --> 05:29:44,160
append to that a hand and a hand takes a
8902
05:29:44,160 --> 05:29:45,280
label
8903
05:29:45,280 --> 05:29:46,080
and
8904
05:29:46,080 --> 05:29:48,240
let's make a format label here and put p
8905
05:29:48,240 --> 05:29:51,200
here and then we add the i right
8906
05:29:51,200 --> 05:29:54,160
so what do we have now right we have a
8907
05:29:54,160 --> 05:29:56,320
list of hands
8908
05:29:56,320 --> 05:29:58,958
perfect right
8909
05:29:58,958 --> 05:30:00,798
perfect so we have a deck we have the
8910
05:30:00,798 --> 05:30:03,200
list of hands so
8911
05:30:03,200 --> 05:30:04,638
divide
8912
05:30:04,638 --> 05:30:07,040
all cards to the four players it says
8913
05:30:07,040 --> 05:30:09,200
here let's do that
8914
05:30:09,200 --> 05:30:11,600
so how can we do that right so the deck
8915
05:30:11,600 --> 05:30:12,958
remember
8916
05:30:12,958 --> 05:30:16,000
the deck here has a length method here
8917
05:30:16,000 --> 05:30:18,080
so that means that
8918
05:30:18,080 --> 05:30:20,400
we can we know how many cards are in it
8919
05:30:20,400 --> 05:30:22,718
at any time and then we can pop a card
8920
05:30:22,718 --> 05:30:25,120
that is taking one card off right
8921
05:30:25,120 --> 05:30:26,718
so
8922
05:30:26,718 --> 05:30:29,760
easily said right so as long as we have
8923
05:30:29,760 --> 05:30:32,718
cards left we can pop cards so that's
8924
05:30:32,718 --> 05:30:35,600
how it's done right
8925
05:30:35,600 --> 05:30:37,360
so let's try to do that right so so
8926
05:30:37,360 --> 05:30:38,558
while
8927
05:30:38,558 --> 05:30:40,638
deck
8928
05:30:40,638 --> 05:30:42,718
while the length of
8929
05:30:42,718 --> 05:30:44,400
deck
8930
05:30:44,400 --> 05:30:47,680
is greater than zero right then we can
8931
05:30:47,680 --> 05:30:50,000
for each hand
8932
05:30:50,000 --> 05:30:51,520
forehand
8933
05:30:51,520 --> 05:30:54,400
in hands
8934
05:30:54,400 --> 05:30:57,440
we can take the hand and
8935
05:30:57,440 --> 05:30:59,680
add
8936
05:30:59,680 --> 05:31:01,600
a card
8937
05:31:01,600 --> 05:31:04,718
from deck where we pop
8938
05:31:04,718 --> 05:31:06,080
card right
8939
05:31:06,080 --> 05:31:09,280
so we pop a card and add it to the hand
8940
05:31:09,280 --> 05:31:12,480
this is amazing right so
8941
05:31:12,480 --> 05:31:15,520
let's actually just loop over our
8942
05:31:15,520 --> 05:31:18,480
hands and see how it looks like right so
8943
05:31:18,480 --> 05:31:21,760
forehand in
8944
05:31:21,760 --> 05:31:24,798
print hand right
8945
05:31:24,798 --> 05:31:27,200
and uh we didn't like that this deck is
8946
05:31:27,200 --> 05:31:29,360
not defined oh i forgot to execute these
8947
05:31:29,360 --> 05:31:31,440
things up here
8948
05:31:31,440 --> 05:31:33,200
boom boom right
8949
05:31:33,200 --> 05:31:34,718
and then we can execute this one here
8950
05:31:34,718 --> 05:31:35,760
right
8951
05:31:35,760 --> 05:31:37,200
perfect right
8952
05:31:37,200 --> 05:31:40,000
so now we actually took the deck of
8953
05:31:40,000 --> 05:31:43,120
cards we created a list of hands we
8954
05:31:43,120 --> 05:31:45,360
appended the player name and then we
8955
05:31:45,360 --> 05:31:47,520
took all the cards one by one and added
8956
05:31:47,520 --> 05:31:49,280
to the hands right
8957
05:31:49,280 --> 05:31:51,360
and then we have for instance this
8958
05:31:51,360 --> 05:31:53,120
distribution here if you played it again
8959
05:31:53,120 --> 05:31:54,878
it will be different
8960
05:31:54,878 --> 05:31:56,718
hands right you see here the cards
8961
05:31:56,718 --> 05:31:59,040
change every time i execute it right
8962
05:31:59,040 --> 05:32:01,200
perfect awesome
8963
05:32:01,200 --> 05:32:02,840
awesome perfect
8964
05:32:02,840 --> 05:32:06,480
good so far so good so we created the
8965
05:32:06,480 --> 05:32:08,480
deck we have the four players we divided
8966
05:32:08,480 --> 05:32:10,320
the cards assume your player one and
8967
05:32:10,320 --> 05:32:13,200
print the hands of p1 so now we can just
8968
05:32:13,200 --> 05:32:14,480
delete this
8969
05:32:14,480 --> 05:32:17,040
and we print here
8970
05:32:17,040 --> 05:32:19,840
hand off player one which is zero here
8971
05:32:19,840 --> 05:32:21,760
right so now
8972
05:32:21,760 --> 05:32:24,000
we have it it should be hands here right
8973
05:32:24,000 --> 05:32:28,320
so now we have p1 here perfect right
8974
05:32:28,320 --> 05:32:29,120
okay
8975
05:32:29,120 --> 05:32:31,600
the game has 13 rounds so how do we do
8976
05:32:31,600 --> 05:32:34,240
that right 4i in
8977
05:32:34,240 --> 05:32:35,200
range
8978
05:32:35,200 --> 05:32:36,480
13
8979
05:32:36,480 --> 05:32:39,840
perfect right so now we iterate 13 times
8980
05:32:39,840 --> 05:32:41,040
perfect
8981
05:32:41,040 --> 05:32:43,760
each player plays one card but here's a
8982
05:32:43,760 --> 05:32:46,000
catch right we need to be able to
8983
05:32:46,000 --> 05:32:47,520
remember
8984
05:32:47,520 --> 05:32:48,638
remember
8985
05:32:48,638 --> 05:32:50,878
uh
8986
05:32:50,958 --> 05:32:52,718
how many
8987
05:32:52,718 --> 05:32:55,840
uh the cards they play right so let's do
8988
05:32:55,840 --> 05:32:57,200
call it uh
8989
05:32:57,200 --> 05:32:59,040
played
8990
05:32:59,040 --> 05:33:00,798
cards
8991
05:33:00,798 --> 05:33:02,958
and make a list of that right
8992
05:33:02,958 --> 05:33:07,520
and uh just to make it simulation easier
8993
05:33:07,520 --> 05:33:09,120
no i don't know actually we want to do
8994
05:33:09,120 --> 05:33:12,480
that we just yeah let's do input here so
8995
05:33:12,480 --> 05:33:15,600
we take round by round and take input we
8996
05:33:15,600 --> 05:33:17,840
have to press enter every time right
8997
05:33:17,840 --> 05:33:20,080
and
8998
05:33:20,160 --> 05:33:22,798
then for hand
8999
05:33:22,798 --> 05:33:24,558
in hands
9000
05:33:24,558 --> 05:33:28,480
because each player needs to play a card
9001
05:33:28,480 --> 05:33:29,760
play one card
9002
05:33:29,760 --> 05:33:31,200
then we have
9003
05:33:31,200 --> 05:33:32,958
played cards
9004
05:33:32,958 --> 05:33:35,600
append
9005
05:33:36,718 --> 05:33:37,760
hand
9006
05:33:37,760 --> 05:33:38,878
pop
9007
05:33:38,878 --> 05:33:41,200
card right
9008
05:33:41,200 --> 05:33:43,760
then everybody played a card right so
9009
05:33:43,760 --> 05:33:46,638
the next thing we need to do is uh
9010
05:33:46,638 --> 05:33:48,958
we need to find the winner card right so
9011
05:33:48,958 --> 05:33:50,080
if we
9012
05:33:50,080 --> 05:33:52,480
just look at the cards
9013
05:33:52,480 --> 05:33:55,040
so for
9014
05:33:55,600 --> 05:33:56,718
card
9015
05:33:56,718 --> 05:33:57,920
in
9016
05:33:57,920 --> 05:34:01,120
played cards we can just print a card
9017
05:34:01,120 --> 05:34:03,680
here right so this is basically it so we
9018
05:34:03,680 --> 05:34:05,520
can press enter here and then we have
9019
05:34:05,520 --> 05:34:08,558
the cards which were played you see here
9020
05:34:08,558 --> 05:34:10,080
the first player played this one
9021
05:34:10,080 --> 05:34:11,600
obviously and then the other players
9022
05:34:11,600 --> 05:34:13,440
played these cards and then you see the
9023
05:34:13,440 --> 05:34:15,680
second card i played was this one here
9024
05:34:15,680 --> 05:34:17,600
and so forth down there right
9025
05:34:17,600 --> 05:34:19,600
but we need to find the highest card and
9026
05:34:19,600 --> 05:34:22,000
this is where the card
9027
05:34:22,000 --> 05:34:23,600
class comes in handy because we
9028
05:34:23,600 --> 05:34:25,040
implemented this one here so we can
9029
05:34:25,040 --> 05:34:27,680
actually take the maximum of that list
9030
05:34:27,680 --> 05:34:29,520
right
9031
05:34:29,520 --> 05:34:31,440
so basically what i can do here is
9032
05:34:31,440 --> 05:34:35,040
actually print just to show it print max
9033
05:34:35,040 --> 05:34:37,760
off played cards right
9034
05:34:37,760 --> 05:34:40,638
if i do that
9035
05:34:42,400 --> 05:34:44,638
uh what happened there
9036
05:34:44,638 --> 05:34:48,320
i need to stop first and then play again
9037
05:34:48,320 --> 05:34:49,920
then we see here
9038
05:34:49,920 --> 05:34:53,360
i printed afterwards so seven of hearts
9039
05:34:53,360 --> 05:34:55,360
was the greatest one here that's true
9040
05:34:55,360 --> 05:34:57,760
right and then we can see here again the
9041
05:34:57,760 --> 05:35:00,160
winner card was the ace which is true
9042
05:35:00,160 --> 05:35:00,958
right
9043
05:35:00,958 --> 05:35:03,680
and then we have the nine
9044
05:35:03,680 --> 05:35:05,920
is the highest card and here we actually
9045
05:35:05,920 --> 05:35:08,638
go by the suit instead right so you see
9046
05:35:08,638 --> 05:35:12,080
that it works perfectly and let's just
9047
05:35:12,080 --> 05:35:13,840
stop it so i don't make the same mistake
9048
05:35:13,840 --> 05:35:16,638
again right good so
9049
05:35:16,638 --> 05:35:18,878
winner card we have it right here
9050
05:35:18,878 --> 05:35:21,120
actually and we don't need to print this
9051
05:35:21,120 --> 05:35:24,320
out anymore we just need to say
9052
05:35:24,320 --> 05:35:25,840
winner
9053
05:35:25,840 --> 05:35:28,160
card is equal to maximum right and
9054
05:35:28,160 --> 05:35:30,000
maximum remember that takes the maximum
9055
05:35:30,000 --> 05:35:32,160
of the list right and we define the
9056
05:35:32,160 --> 05:35:33,760
order of them so that's why we can take
9057
05:35:33,760 --> 05:35:37,520
the maximum of the list here right
9058
05:35:37,520 --> 05:35:40,080
okay good so the next thing we need to
9059
05:35:40,080 --> 05:35:42,160
know is uh
9060
05:35:42,160 --> 05:35:45,680
who played the winning card right who
9061
05:35:45,680 --> 05:35:47,280
was a player right
9062
05:35:47,280 --> 05:35:48,480
and
9063
05:35:48,480 --> 05:35:50,320
one way to do that is actually to
9064
05:35:50,320 --> 05:35:53,440
iterate over it and find which one has
9065
05:35:53,440 --> 05:35:54,798
this card right
9066
05:35:54,798 --> 05:35:58,240
uh another thing is to just use some
9067
05:35:58,240 --> 05:35:59,440
methods
9068
05:35:59,440 --> 05:36:02,878
directly on the list and use it directly
9069
05:36:02,878 --> 05:36:05,840
yeah the player that wins the hand needs
9070
05:36:05,840 --> 05:36:08,320
to be a rewarded one point right so
9071
05:36:08,320 --> 05:36:10,160
that's the next step here so we need to
9072
05:36:10,160 --> 05:36:12,798
figure out what index is the player of
9073
05:36:12,798 --> 05:36:15,200
the winning card and we actually have
9074
05:36:15,200 --> 05:36:18,000
the order of the cards in here so the
9075
05:36:18,000 --> 05:36:20,878
one which has winner card is the index
9076
05:36:20,878 --> 05:36:23,760
of that one is actually the player which
9077
05:36:23,760 --> 05:36:26,080
one right so
9078
05:36:26,080 --> 05:36:28,638
winner card is here and
9079
05:36:28,638 --> 05:36:31,040
then we can take winner hand for
9080
05:36:31,040 --> 05:36:34,080
instance it is this one here which we
9081
05:36:34,080 --> 05:36:34,878
say
9082
05:36:34,878 --> 05:36:37,440
hands
9083
05:36:39,860 --> 05:36:43,139
[Music]
9084
05:36:43,760 --> 05:36:46,240
played cards and we just take the index
9085
05:36:46,240 --> 05:36:47,680
of the
9086
05:36:47,680 --> 05:36:49,600
the winner card
9087
05:36:49,600 --> 05:36:50,558
right
9088
05:36:50,558 --> 05:36:52,798
index here
9089
05:36:52,798 --> 05:36:55,680
index on this one here it is uh
9090
05:36:55,680 --> 05:36:58,160
returns the front index of value right
9091
05:36:58,160 --> 05:36:59,840
so this is basically what we want we
9092
05:36:59,840 --> 05:37:01,440
could also make a for loop where we find
9093
05:37:01,440 --> 05:37:03,440
the index uncounted but here we just use
9094
05:37:03,440 --> 05:37:05,600
the index function which returns the
9095
05:37:05,600 --> 05:37:08,320
index of that and that will index it
9096
05:37:08,320 --> 05:37:10,480
into the hands and we'll return the
9097
05:37:10,480 --> 05:37:12,558
winner hand right because on the winner
9098
05:37:12,558 --> 05:37:16,638
hand we need to say
9099
05:37:16,638 --> 05:37:19,200
we need to house a call
9100
05:37:19,200 --> 05:37:21,440
we need to how is that method called i
9101
05:37:21,440 --> 05:37:23,520
forgot again actually the winner hand is
9102
05:37:23,520 --> 05:37:25,520
called round winner right
9103
05:37:25,520 --> 05:37:27,520
round winner
9104
05:37:27,520 --> 05:37:30,080
so now we added one point to that right
9105
05:37:30,080 --> 05:37:31,680
so that was this one the player with the
9106
05:37:31,680 --> 05:37:33,360
highest card wins
9107
05:37:33,360 --> 05:37:35,440
update the score of the winning
9108
05:37:35,440 --> 05:37:38,000
hand print the cards played in round and
9109
05:37:38,000 --> 05:37:40,878
the winner okay let's do that
9110
05:37:40,878 --> 05:37:41,760
so
9111
05:37:41,760 --> 05:37:44,480
now we need to print out a full load of
9112
05:37:44,480 --> 05:37:47,840
things here right so the winner
9113
05:37:47,840 --> 05:37:49,760
now how what should we use to print the
9114
05:37:49,760 --> 05:37:52,160
cards played in round okay so we need to
9115
05:37:52,160 --> 05:37:54,958
print all the cards so maybe we do that
9116
05:37:54,958 --> 05:37:57,680
by a list comprehension so let's say
9117
05:37:57,680 --> 05:37:59,200
cards
9118
05:37:59,200 --> 05:38:01,440
played
9119
05:38:01,440 --> 05:38:03,200
we call the played cards and cards
9120
05:38:03,200 --> 05:38:05,520
played actually we have the cards played
9121
05:38:05,520 --> 05:38:07,280
there already
9122
05:38:07,280 --> 05:38:08,558
in that one
9123
05:38:08,558 --> 05:38:10,470
so can we just say
9124
05:38:10,470 --> 05:38:13,680
[Music]
9125
05:38:13,680 --> 05:38:14,958
let's just
9126
05:38:14,958 --> 05:38:17,440
let's let's let's let's try some things
9127
05:38:17,440 --> 05:38:21,040
here right so here we have
9128
05:38:21,040 --> 05:38:24,638
the round of it it is called round
9129
05:38:24,638 --> 05:38:26,160
i here
9130
05:38:26,160 --> 05:38:27,280
and then
9131
05:38:27,280 --> 05:38:28,400
we
9132
05:38:28,400 --> 05:38:30,718
use a list comprehension
9133
05:38:30,718 --> 05:38:33,120
and a join here
9134
05:38:33,120 --> 05:38:35,600
on this list comprehension on this list
9135
05:38:35,600 --> 05:38:36,958
comprehension
9136
05:38:36,958 --> 05:38:40,958
we will use the played cards
9137
05:38:40,958 --> 05:38:42,958
and we call str
9138
05:38:42,958 --> 05:38:44,958
on the card
9139
05:38:44,958 --> 05:38:48,798
for card in played cards right
9140
05:38:48,798 --> 05:38:52,718
that's correct and then we are going to
9141
05:38:52,718 --> 05:38:54,240
use
9142
05:38:54,240 --> 05:38:55,840
format again
9143
05:38:55,840 --> 05:38:57,680
[Music]
9144
05:38:57,680 --> 05:39:00,080
winner
9145
05:39:00,638 --> 05:39:04,280
and we have here
9146
05:39:07,520 --> 05:39:10,240
winner hand
9147
05:39:14,558 --> 05:39:16,320
get label
9148
05:39:16,320 --> 05:39:17,760
this is going to be a long one i
9149
05:39:17,760 --> 05:39:19,360
apologize for that
9150
05:39:19,360 --> 05:39:21,200
and uh
9151
05:39:21,200 --> 05:39:23,520
then we actually take the winner card
9152
05:39:23,520 --> 05:39:25,360
here right
9153
05:39:25,360 --> 05:39:27,280
we need to take the
9154
05:39:27,280 --> 05:39:31,520
string off winner card i think here
9155
05:39:31,520 --> 05:39:33,920
okay this is a long one right so let's
9156
05:39:33,920 --> 05:39:35,680
try that one
9157
05:39:35,680 --> 05:39:37,980
and then we just press enter
9158
05:39:37,980 --> 05:39:39,280
[Music]
9159
05:39:39,280 --> 05:39:40,958
winner
9160
05:39:40,958 --> 05:39:43,840
bound method hand okay i i did something
9161
05:39:43,840 --> 05:39:45,600
wrong here this one should have a space
9162
05:39:45,600 --> 05:39:46,480
here
9163
05:39:46,480 --> 05:39:49,200
and then we have winner
9164
05:39:49,200 --> 05:39:50,878
winner card get
9165
05:39:50,878 --> 05:39:53,440
a label oh i should have method call
9166
05:39:53,440 --> 05:39:54,798
here right
9167
05:39:54,798 --> 05:39:57,520
here we have it
9168
05:39:58,958 --> 05:40:01,120
and then we execute this one again
9169
05:40:01,120 --> 05:40:03,120
and then we have it here right
9170
05:40:03,120 --> 05:40:04,638
perfect right
9171
05:40:04,638 --> 05:40:06,638
so here we have round one
9172
05:40:06,638 --> 05:40:08,798
hearts of two two of hearts and then we
9173
05:40:08,798 --> 05:40:11,040
they play here and the winner is p4
9174
05:40:11,040 --> 05:40:12,958
which played this one here right and
9175
05:40:12,958 --> 05:40:16,160
then you can see forward like it goes
9176
05:40:16,160 --> 05:40:18,240
here and you go to 13 rounds and then it
9177
05:40:18,240 --> 05:40:19,280
stops
9178
05:40:19,280 --> 05:40:21,440
actually we count round zero two yeah
9179
05:40:21,440 --> 05:40:22,718
that's okay
9180
05:40:22,718 --> 05:40:24,000
and
9181
05:40:24,000 --> 05:40:26,638
in the end we want to play
9182
05:40:26,638 --> 05:40:28,638
we want to yeah what is it it says here
9183
05:40:28,638 --> 05:40:30,320
after the 13 rounds print the score of
9184
05:40:30,320 --> 05:40:33,120
all players p1 to p4 right so again here
9185
05:40:33,120 --> 05:40:35,200
we two four
9186
05:40:35,200 --> 05:40:37,680
hand in hands
9187
05:40:37,680 --> 05:40:38,958
you see
9188
05:40:38,958 --> 05:40:42,680
and then we do print
9189
05:40:43,600 --> 05:40:45,040
what do we do
9190
05:40:45,040 --> 05:40:47,520
score
9191
05:40:47,600 --> 05:40:50,480
we do a formatted string here
9192
05:40:50,480 --> 05:40:53,520
score for
9193
05:40:53,520 --> 05:40:54,878
for
9194
05:40:54,878 --> 05:40:59,600
then we have hand here get a label
9195
05:40:59,600 --> 05:41:02,080
and then we do
9196
05:41:02,080 --> 05:41:04,400
colon here and then we do
9197
05:41:04,400 --> 05:41:07,280
hand here we have
9198
05:41:07,280 --> 05:41:09,200
get
9199
05:41:09,200 --> 05:41:10,558
win count
9200
05:41:10,558 --> 05:41:13,600
would get win count there right
9201
05:41:13,600 --> 05:41:18,000
good perfect so let's try that again
9202
05:41:20,958 --> 05:41:22,320
here we have it right
9203
05:41:22,320 --> 05:41:24,240
so having get the scores at the end
9204
05:41:24,240 --> 05:41:25,280
there
9205
05:41:25,280 --> 05:41:27,280
so p3 you want this one here and you can
9206
05:41:27,280 --> 05:41:29,360
check that this is correct right
9207
05:41:29,360 --> 05:41:31,920
so you see here it's not that complex
9208
05:41:31,920 --> 05:41:32,798
actually
9209
05:41:32,798 --> 05:41:35,280
can i get everything here yes here
9210
05:41:35,280 --> 05:41:37,360
so in the beginning here we create oh
9211
05:41:37,360 --> 05:41:38,878
actually i don't get the deck here we
9212
05:41:38,878 --> 05:41:41,040
get the deck here in the beginning
9213
05:41:41,040 --> 05:41:43,280
so let's get it here we create a deck
9214
05:41:43,280 --> 05:41:46,000
here we take all the hands here and then
9215
05:41:46,000 --> 05:41:48,080
we
9216
05:41:48,080 --> 05:41:50,638
divide the cards we print the first hand
9217
05:41:50,638 --> 05:41:52,958
and then we do the 13 rounds
9218
05:41:52,958 --> 05:41:55,760
and then we play
9219
05:41:55,760 --> 05:41:58,240
a card from all hands we
9220
05:41:58,240 --> 05:42:00,558
remember them all here then we find the
9221
05:42:00,558 --> 05:42:02,958
maximal card then we find the hand that
9222
05:42:02,958 --> 05:42:05,600
one then we add a win around then we do
9223
05:42:05,600 --> 05:42:07,840
this crazy print statement here and then
9224
05:42:07,840 --> 05:42:10,000
after the round we print out the winner
9225
05:42:10,000 --> 05:42:13,440
okay isn't that crazy i think so and
9226
05:42:13,440 --> 05:42:15,040
this is amazing actually this is
9227
05:42:15,040 --> 05:42:16,798
actually object owner programming and
9228
05:42:16,798 --> 05:42:18,798
now you kind of get the idea of how it
9229
05:42:18,798 --> 05:42:20,878
works in the next one it's gonna be
9230
05:42:20,878 --> 05:42:22,718
exciting too we're gonna learn about
9231
05:42:22,718 --> 05:42:25,120
visualization how to visualize data it's
9232
05:42:25,120 --> 05:42:27,600
gonna be amazing i promise you that so
9233
05:42:27,600 --> 05:42:28,638
see you
9234
05:42:28,638 --> 05:42:32,600
in the next one bye
9235
05:42:35,120 --> 05:42:37,520
when it comes to data visualization in
9236
05:42:37,520 --> 05:42:40,240
python you need to master matplotlib
9237
05:42:40,240 --> 05:42:41,840
and remember in the beginning of the
9238
05:42:41,840 --> 05:42:44,000
course we had the list of favorite
9239
05:42:44,000 --> 05:42:47,280
libraries well matplotlib is up amongst
9240
05:42:47,280 --> 05:42:48,480
them
9241
05:42:48,480 --> 05:42:49,520
and
9242
05:42:49,520 --> 05:42:52,080
i do know that some people they are not
9243
05:42:52,080 --> 05:42:54,160
that excited about matt bloodlip but i
9244
05:42:54,160 --> 05:42:56,958
think also some of the confusion is that
9245
05:42:56,958 --> 05:42:59,120
actually matplotlib can be used in two
9246
05:42:59,120 --> 05:43:01,280
different ways and it's not obvious
9247
05:43:01,280 --> 05:43:03,600
first which way you're using it so we're
9248
05:43:03,600 --> 05:43:05,520
gonna explore that so there's a
9249
05:43:05,520 --> 05:43:07,760
functional way and an object-oriented
9250
05:43:07,760 --> 05:43:09,760
way of using matplotlib
9251
05:43:09,760 --> 05:43:11,680
and i think the functional way makes
9252
05:43:11,680 --> 05:43:13,920
more confusion than it actually should
9253
05:43:13,920 --> 05:43:14,878
do
9254
05:43:14,878 --> 05:43:17,200
so that's why i advise people to use it
9255
05:43:17,200 --> 05:43:19,200
in the object-oriented way and the
9256
05:43:19,200 --> 05:43:21,680
overhead is basically only one line of
9257
05:43:21,680 --> 05:43:24,320
code so i don't see any excuses of not
9258
05:43:24,320 --> 05:43:26,798
using it in an object or the way and it
9259
05:43:26,798 --> 05:43:28,718
will save you for
9260
05:43:28,718 --> 05:43:31,280
making mistakes later in your code
9261
05:43:31,280 --> 05:43:33,200
so are you ready to learn about
9262
05:43:33,200 --> 05:43:35,680
matplotlib i hope so because i'm really
9263
05:43:35,680 --> 05:43:38,320
excited about it so and so should you be
9264
05:43:38,320 --> 05:43:40,240
see you in a moment so we are here
9265
05:43:40,240 --> 05:43:41,840
inside our
9266
05:43:41,840 --> 05:43:44,718
juvenile notebook about matplotlib and
9267
05:43:44,718 --> 05:43:47,280
the goal of this one is to learn to
9268
05:43:47,280 --> 05:43:50,480
visualize data charts so
9269
05:43:50,480 --> 05:43:52,878
this introduction this lesson here is
9270
05:43:52,878 --> 05:43:55,040
only about showing you a few
9271
05:43:55,040 --> 05:43:57,920
methods of using matplotlib and then
9272
05:43:57,920 --> 05:43:59,280
we're going to make a project where you
9273
05:43:59,280 --> 05:44:01,520
use it on real data so here we're just
9274
05:44:01,520 --> 05:44:03,520
going to make some fake data and
9275
05:44:03,520 --> 05:44:06,638
in the project we're going to do it on
9276
05:44:06,638 --> 05:44:08,558
actually the cars we know we're going to
9277
05:44:08,558 --> 05:44:10,798
make a scatter chart which is really
9278
05:44:10,798 --> 05:44:13,120
amazing with colors and all and it's
9279
05:44:13,120 --> 05:44:14,958
gonna be amazing so you're gonna love it
9280
05:44:14,958 --> 05:44:17,600
okay so let's get started
9281
05:44:17,600 --> 05:44:21,680
so matplotlib is a library like so many
9282
05:44:21,680 --> 05:44:24,000
other things so let's import it first
9283
05:44:24,000 --> 05:44:25,440
but there's a catch when you import
9284
05:44:25,440 --> 05:44:27,680
matplotlib in jupiter notebook because
9285
05:44:27,680 --> 05:44:30,400
jupiter notebook interacts well with
9286
05:44:30,400 --> 05:44:32,718
matplotlib but can visualize the charts
9287
05:44:32,718 --> 05:44:35,200
immediately for you so you need to
9288
05:44:35,200 --> 05:44:36,958
communicate that so first of all let's
9289
05:44:36,958 --> 05:44:39,840
import it import
9290
05:44:39,840 --> 05:44:43,840
plot lip pipelot is the one using as plt
9291
05:44:43,840 --> 05:44:46,320
and again as plt is just to short name
9292
05:44:46,320 --> 05:44:48,878
it so now to the part where you
9293
05:44:48,878 --> 05:44:51,600
communicate to jupiter notebook how
9294
05:44:51,600 --> 05:44:53,760
should it visualize it so we're going to
9295
05:44:53,760 --> 05:44:55,600
use a matte
9296
05:44:55,600 --> 05:44:59,040
plot lip inline so the inline tells it
9297
05:44:59,040 --> 05:45:01,280
in which way you should do it so there's
9298
05:45:01,280 --> 05:45:04,080
also an inline is static and if you want
9299
05:45:04,080 --> 05:45:05,840
it to be interactive where you can zoom
9300
05:45:05,840 --> 05:45:08,160
in and do lots of stuff you can use the
9301
05:45:08,160 --> 05:45:10,878
notebook for that we're gonna we're not
9302
05:45:10,878 --> 05:45:12,798
gonna explore that one in here but i
9303
05:45:12,798 --> 05:45:14,638
just want to notice that this one one is
9304
05:45:14,638 --> 05:45:17,120
also a great choice
9305
05:45:17,120 --> 05:45:19,600
inline okay imported
9306
05:45:19,600 --> 05:45:22,080
so the first thing we're going to show
9307
05:45:22,080 --> 05:45:23,280
is
9308
05:45:23,280 --> 05:45:25,680
the functional way where you actually
9309
05:45:25,680 --> 05:45:27,440
call and create a
9310
05:45:27,440 --> 05:45:30,320
plot or a chart a figure
9311
05:45:30,320 --> 05:45:32,798
immediately from the functional way and
9312
05:45:32,798 --> 05:45:34,400
i'm just going to show it and then i'm
9313
05:45:34,400 --> 05:45:37,120
going to show the object order way and
9314
05:45:37,120 --> 05:45:40,878
explain what the advantage is okay
9315
05:45:40,878 --> 05:45:42,080
so
9316
05:45:42,080 --> 05:45:44,878
when you call it directly
9317
05:45:44,878 --> 05:45:46,638
you just call it on plt and then you
9318
05:45:46,638 --> 05:45:48,958
could call plot immediately so this is a
9319
05:45:48,958 --> 05:45:50,480
functional way right
9320
05:45:50,480 --> 05:45:52,558
and what we're gonna visualize here is
9321
05:45:52,558 --> 05:45:55,680
just like a line of code here a line of
9322
05:45:55,680 --> 05:45:57,760
a list here so this
9323
05:45:57,760 --> 05:46:00,000
shows it immediately right and you see
9324
05:46:00,000 --> 05:46:02,080
this is easy why would you use anything
9325
05:46:02,080 --> 05:46:04,878
else on this right but that's because if
9326
05:46:04,878 --> 05:46:08,718
you later call on some other data and
9327
05:46:08,718 --> 05:46:10,558
then sometimes it will update on the
9328
05:46:10,558 --> 05:46:12,240
same
9329
05:46:12,240 --> 05:46:14,558
figure here as it's called this figure
9330
05:46:14,558 --> 05:46:16,558
here so you just keep drawing on the
9331
05:46:16,558 --> 05:46:18,798
same figure because you haven't reset it
9332
05:46:18,798 --> 05:46:20,798
and get a new figure and so on so it
9333
05:46:20,798 --> 05:46:23,200
becomes very confusing so in the
9334
05:46:23,200 --> 05:46:26,080
object-only way you create a new figure
9335
05:46:26,080 --> 05:46:28,798
all the time every time you use it right
9336
05:46:28,798 --> 05:46:31,280
okay so let's just do that immediately
9337
05:46:31,280 --> 05:46:34,240
so i write figure and axis and then i
9338
05:46:34,240 --> 05:46:37,360
call plt again to create the subplots
9339
05:46:37,360 --> 05:46:39,840
as it's called so subplots is i think
9340
05:46:39,840 --> 05:46:42,320
the best way to create
9341
05:46:42,320 --> 05:46:45,280
create your own figure and access as is
9342
05:46:45,280 --> 05:46:49,680
called to create to draw on right so
9343
05:46:49,680 --> 05:46:51,840
subplots here as you see it creates a
9344
05:46:51,840 --> 05:46:54,160
figure this is a figure and a set of
9345
05:46:54,160 --> 05:46:56,160
subplots and the setup subplots are
9346
05:46:56,160 --> 05:46:58,480
called axis and we're only going to use
9347
05:46:58,480 --> 05:47:00,638
one axis so we don't put any arguments
9348
05:47:00,638 --> 05:47:03,040
here so so it's all only one x and then
9349
05:47:03,040 --> 05:47:04,878
one x is like you can think of them like
9350
05:47:04,878 --> 05:47:06,638
like the chart right in the figure you
9351
05:47:06,638 --> 05:47:08,240
can put multiple charts on it if you
9352
05:47:08,240 --> 05:47:10,480
want to but we're only going to use one
9353
05:47:10,480 --> 05:47:12,958
but creating this figure here it makes
9354
05:47:12,958 --> 05:47:13,840
it
9355
05:47:13,840 --> 05:47:16,878
transparent to you that where are you
9356
05:47:16,878 --> 05:47:18,400
drawing on
9357
05:47:18,400 --> 05:47:20,000
well in this one here you actually don't
9358
05:47:20,000 --> 05:47:21,360
know which one you're drawing on because
9359
05:47:21,360 --> 05:47:22,798
you use it in a functional way so it's
9360
05:47:22,798 --> 05:47:24,400
hidden all behind the
9361
05:47:24,400 --> 05:47:26,320
the thing
9362
05:47:26,320 --> 05:47:29,600
hidden behind the method right
9363
05:47:29,600 --> 05:47:31,920
so so far so good so how to draw the
9364
05:47:31,920 --> 05:47:33,920
same thing as up there is just call the
9365
05:47:33,920 --> 05:47:36,558
axis and you call plot on it and then
9366
05:47:36,558 --> 05:47:37,840
you
9367
05:47:37,840 --> 05:47:40,000
do the same thing right so you see the
9368
05:47:40,000 --> 05:47:42,480
only difference is you have one more
9369
05:47:42,480 --> 05:47:44,320
line of code above here
9370
05:47:44,320 --> 05:47:47,120
and then you call axis on it and you
9371
05:47:47,120 --> 05:47:49,280
call it an axis instead of the plc right
9372
05:47:49,280 --> 05:47:50,718
because you want to make sure you're
9373
05:47:50,718 --> 05:47:53,360
drawing on this figure here this figure
9374
05:47:53,360 --> 05:47:55,200
and this axis are connected together
9375
05:47:55,200 --> 05:47:56,878
because they came from the same call
9376
05:47:56,878 --> 05:47:58,958
here right so they are connected so when
9377
05:47:58,958 --> 05:47:59,680
you
9378
05:47:59,680 --> 05:48:03,280
call axes and you plot on it you plot on
9379
05:48:03,280 --> 05:48:08,400
this figure here and the figure is the
9380
05:48:08,480 --> 05:48:10,400
canvas down here you could see it right
9381
05:48:10,400 --> 05:48:12,638
the canvas here perfect
9382
05:48:12,638 --> 05:48:14,320
so far so good
9383
05:48:14,320 --> 05:48:16,240
but what we're more interested in is not
9384
05:48:16,240 --> 05:48:18,400
making simple plots like this uh simple
9385
05:48:18,400 --> 05:48:20,958
line we are interested in making
9386
05:48:20,958 --> 05:48:22,878
scatter plots and histograms that's what
9387
05:48:22,878 --> 05:48:24,400
we're going to use in our project
9388
05:48:24,400 --> 05:48:26,320
and scatter plots i find it's a very
9389
05:48:26,320 --> 05:48:28,400
nice way to visualize data when you have
9390
05:48:28,400 --> 05:48:30,240
a data set because it can show you if
9391
05:48:30,240 --> 05:48:31,840
there's some connection between the
9392
05:48:31,840 --> 05:48:34,080
points you're looking at but in there
9393
05:48:34,080 --> 05:48:35,520
in here we're just going to demonstrate
9394
05:48:35,520 --> 05:48:37,200
it in the project we're going to use
9395
05:48:37,200 --> 05:48:39,840
real data
9396
05:48:39,840 --> 05:48:41,040
perfect
9397
05:48:41,040 --> 05:48:42,000
so
9398
05:48:42,000 --> 05:48:44,320
what kind of data could we have right it
9399
05:48:44,320 --> 05:48:47,200
doesn't really matter one two three four
9400
05:48:47,200 --> 05:48:49,280
five six so let's just have six points
9401
05:48:49,280 --> 05:48:52,638
here and then the y-axis can vary a bit
9402
05:48:52,638 --> 05:48:56,638
more so we can have 2 3 2 1
9403
05:48:56,638 --> 05:48:59,280
6 and maybe just 10 here right so we
9404
05:48:59,280 --> 05:49:01,440
have the same number of items there and
9405
05:49:01,440 --> 05:49:03,760
then we have the figure the axis and
9406
05:49:03,760 --> 05:49:06,000
then we take plt
9407
05:49:06,000 --> 05:49:08,638
sub plots
9408
05:49:08,638 --> 05:49:10,080
okay there are a lot of methods there
9409
05:49:10,080 --> 05:49:12,320
subplots here and then we take the axis
9410
05:49:12,320 --> 05:49:15,280
and then we call scatter instead scatter
9411
05:49:15,280 --> 05:49:18,320
and we take the x and y axis on this one
9412
05:49:18,320 --> 05:49:20,958
here boom and then you put it here right
9413
05:49:20,958 --> 05:49:23,440
so here you see we scatter it right and
9414
05:49:23,440 --> 05:49:25,200
you can actually have multiple points on
9415
05:49:25,200 --> 05:49:26,558
the same
9416
05:49:26,558 --> 05:49:28,798
on top of each other here i just put
9417
05:49:28,798 --> 05:49:31,120
them on a nice line here but we can
9418
05:49:31,120 --> 05:49:32,798
actually have the same one here right so
9419
05:49:32,798 --> 05:49:35,440
we could put five i get him or four here
9420
05:49:35,440 --> 05:49:37,840
and on four we put three here right so
9421
05:49:37,840 --> 05:49:40,160
we plot it and we get it again we see we
9422
05:49:40,160 --> 05:49:42,638
have two points here instead so scatter
9423
05:49:42,638 --> 05:49:45,200
plots plots it just the points
9424
05:49:45,200 --> 05:49:47,200
uh point by point right so you see here
9425
05:49:47,200 --> 05:49:49,040
we have one point
9426
05:49:49,040 --> 05:49:52,240
one by two one by two it's this one here
9427
05:49:52,240 --> 05:49:54,080
and then we have two by three two by
9428
05:49:54,080 --> 05:49:56,000
three right here and then three point
9429
05:49:56,000 --> 05:49:58,080
two three by two
9430
05:49:58,080 --> 05:50:00,320
four by one
9431
05:50:00,320 --> 05:50:01,600
five buys
9432
05:50:01,600 --> 05:50:03,600
six
9433
05:50:03,600 --> 05:50:05,920
and uh
9434
05:50:05,920 --> 05:50:08,638
six by ten and then we have this last
9435
05:50:08,638 --> 05:50:10,878
one four by
9436
05:50:10,878 --> 05:50:13,360
three this one here right
9437
05:50:13,360 --> 05:50:16,798
so far so good right uh another thing i
9438
05:50:16,798 --> 05:50:18,638
like with the scatter plot is actually
9439
05:50:18,638 --> 05:50:21,440
you can put colors on it so let's just
9440
05:50:21,440 --> 05:50:23,840
actually add another line here and just
9441
05:50:23,840 --> 05:50:27,280
take one one two two three
9442
05:50:27,280 --> 05:50:29,360
three
9443
05:50:29,360 --> 05:50:31,280
four right
9444
05:50:31,280 --> 05:50:33,600
and then you can actually add the colors
9445
05:50:33,600 --> 05:50:34,958
here as
9446
05:50:34,958 --> 05:50:38,320
as the argument c and it the argument c
9447
05:50:38,320 --> 05:50:40,878
is the colors and it gets the list here
9448
05:50:40,878 --> 05:50:43,360
of the color so each of the
9449
05:50:43,360 --> 05:50:45,680
scatter plots
9450
05:50:45,680 --> 05:50:48,878
each of the dots will get a color right
9451
05:50:48,878 --> 05:50:51,760
and you see it figure out it's a way to
9452
05:50:51,760 --> 05:50:54,958
map these numbers to a color
9453
05:50:54,958 --> 05:50:56,878
so the same numbers obviously have the
9454
05:50:56,878 --> 05:50:59,120
same color and based on the data set
9455
05:50:59,120 --> 05:51:00,638
here you'll just figure it out by itself
9456
05:51:00,638 --> 05:51:01,760
it's really really nice so you don't
9457
05:51:01,760 --> 05:51:03,760
have to think about it unless you want
9458
05:51:03,760 --> 05:51:05,600
specific colors but other than that you
9459
05:51:05,600 --> 05:51:07,680
will find a color mapping for that is
9460
05:51:07,680 --> 05:51:08,958
unique
9461
05:51:08,958 --> 05:51:10,798
another thing you probably wonder about
9462
05:51:10,798 --> 05:51:13,200
what about titles and labels well you
9463
05:51:13,200 --> 05:51:14,638
can do that
9464
05:51:14,638 --> 05:51:17,440
you can say it's called set title and
9465
05:51:17,440 --> 05:51:19,440
you have title
9466
05:51:19,440 --> 05:51:20,638
title here
9467
05:51:20,638 --> 05:51:22,000
and you have x
9468
05:51:22,000 --> 05:51:23,360
set
9469
05:51:23,360 --> 05:51:28,000
x label and you have x label
9470
05:51:28,000 --> 05:51:31,360
and you have obviously said x y label
9471
05:51:31,360 --> 05:51:32,798
[Music]
9472
05:51:32,798 --> 05:51:34,400
and you have y
9473
05:51:34,400 --> 05:51:37,680
label on that one here right so here you
9474
05:51:37,680 --> 05:51:40,160
have it right you have the title i set
9475
05:51:40,160 --> 05:51:43,120
the title the x label and the y label
9476
05:51:43,120 --> 05:51:45,360
here and you still have the same scatter
9477
05:51:45,360 --> 05:51:47,200
plot here right so this is how you make
9478
05:51:47,200 --> 05:51:50,000
a scatter plot just a lists right and
9479
05:51:50,000 --> 05:51:52,080
the coloring like that
9480
05:51:52,080 --> 05:51:53,760
perfect
9481
05:51:53,760 --> 05:51:55,520
now to the last one we want to show
9482
05:51:55,520 --> 05:51:57,440
before we head for the project and
9483
05:51:57,440 --> 05:51:59,840
that's how do you make a histogram
9484
05:51:59,840 --> 05:52:01,840
so histogram is basically also like
9485
05:52:01,840 --> 05:52:04,160
remember the frequency count we had
9486
05:52:04,160 --> 05:52:06,718
right so if you have a list like let's
9487
05:52:06,718 --> 05:52:08,480
call it data and
9488
05:52:08,480 --> 05:52:12,080
let's just take some points
9489
05:52:13,120 --> 05:52:15,360
and let's just have three
9490
05:52:15,360 --> 05:52:16,958
points
9491
05:52:16,958 --> 05:52:19,280
here i don't know how much of each of
9492
05:52:19,280 --> 05:52:21,120
them
9493
05:52:21,120 --> 05:52:23,120
perfect let's just say that and you want
9494
05:52:23,120 --> 05:52:24,000
to
9495
05:52:24,000 --> 05:52:26,160
map that out on a histogram right so how
9496
05:52:26,160 --> 05:52:29,280
do you do that well again figure axis
9497
05:52:29,280 --> 05:52:32,240
and you take plt sub
9498
05:52:32,240 --> 05:52:33,680
plots
9499
05:52:33,680 --> 05:52:35,360
and then you take the axis and then you
9500
05:52:35,360 --> 05:52:37,760
take hist and then you take the data but
9501
05:52:37,760 --> 05:52:40,480
you want to communicate to the histogram
9502
05:52:40,480 --> 05:52:42,798
how many pins should be there and bins
9503
05:52:42,798 --> 05:52:44,798
are the number of
9504
05:52:44,798 --> 05:52:47,920
bars you're gonna put there so bins
9505
05:52:47,920 --> 05:52:49,440
and you put three in this case because
9506
05:52:49,440 --> 05:52:51,920
we have three unique values here and if
9507
05:52:51,920 --> 05:52:54,160
you don't know the data set it will just
9508
05:52:54,160 --> 05:52:56,320
adjust the data set in the number of
9509
05:52:56,320 --> 05:52:58,480
bins out there actually you can put less
9510
05:52:58,480 --> 05:53:00,718
bins here right so let's see that in a
9511
05:53:00,718 --> 05:53:02,958
moment actually so here we have it right
9512
05:53:02,958 --> 05:53:05,040
actually it's quite even out this one
9513
05:53:05,040 --> 05:53:07,440
here right
9514
05:53:07,440 --> 05:53:08,878
i'm actually actually not that good at
9515
05:53:08,878 --> 05:53:10,080
making
9516
05:53:10,080 --> 05:53:11,680
or maybe either i'm good at making
9517
05:53:11,680 --> 05:53:14,160
random things or i'm not good at it so
9518
05:53:14,160 --> 05:53:15,840
three bins
9519
05:53:15,840 --> 05:53:17,920
i promise you you can also have two pins
9520
05:53:17,920 --> 05:53:19,280
and then you see here you get two of
9521
05:53:19,280 --> 05:53:21,520
them instead it shouldn't make sense to
9522
05:53:21,520 --> 05:53:24,080
make four bins because
9523
05:53:24,080 --> 05:53:26,080
and then it just leaves one empty here
9524
05:53:26,080 --> 05:53:27,360
right you see
9525
05:53:27,360 --> 05:53:28,160
but
9526
05:53:28,160 --> 05:53:30,080
if you had more data
9527
05:53:30,080 --> 05:53:32,000
it makes sense to have more bins and so
9528
05:53:32,000 --> 05:53:33,280
on right
9529
05:53:33,280 --> 05:53:35,040
this is actually it and again you could
9530
05:53:35,040 --> 05:53:36,958
put the title
9531
05:53:36,958 --> 05:53:37,840
set
9532
05:53:37,840 --> 05:53:40,480
title here
9533
05:53:40,558 --> 05:53:42,240
to whatever you want
9534
05:53:42,240 --> 05:53:43,520
and uh
9535
05:53:43,520 --> 05:53:45,360
x label set
9536
05:53:45,360 --> 05:53:48,160
x label
9537
05:53:48,160 --> 05:53:55,760
x label and obviously at 6 x set y label
9538
05:53:57,680 --> 05:53:58,558
y
9539
05:53:58,558 --> 05:54:01,600
label right that should be obvious right
9540
05:54:01,600 --> 05:54:03,440
so now you're actually ready for making
9541
05:54:03,440 --> 05:54:06,638
your project now so are you excited i am
9542
05:54:06,638 --> 05:54:08,480
because it's going to be about the cars
9543
05:54:08,480 --> 05:54:09,520
and we're going to see if there's
9544
05:54:09,520 --> 05:54:12,718
connection between or visually see if we
9545
05:54:12,718 --> 05:54:15,120
think there is a connection between the
9546
05:54:15,120 --> 05:54:18,080
the horsepower and the torque
9547
05:54:18,080 --> 05:54:19,680
of the cars
9548
05:54:19,680 --> 05:54:20,638
yeah
9549
05:54:20,638 --> 05:54:22,320
it sounds exciting right we're gonna
9550
05:54:22,320 --> 05:54:24,798
read all the csv files with all the data
9551
05:54:24,798 --> 05:54:26,798
and figure that one out so see you in a
9552
05:54:26,798 --> 05:54:29,798
moment
9553
05:54:31,920 --> 05:54:35,200
so we are ready for our project here so
9554
05:54:35,200 --> 05:54:38,160
the project is named horsepower versus
9555
05:54:38,160 --> 05:54:40,480
torque and roll dies so we're going to
9556
05:54:40,480 --> 05:54:42,480
do two projects the first one is
9557
05:54:42,480 --> 05:54:45,200
horsepower versus torque and then it's
9558
05:54:45,200 --> 05:54:47,520
going to be roll dice so
9559
05:54:47,520 --> 05:54:49,600
the goal of this is obviously to learn
9560
05:54:49,600 --> 05:54:51,760
to make a scatter plot and a histogram
9561
05:54:51,760 --> 05:54:52,558
right
9562
05:54:52,558 --> 05:54:54,638
so the first one is horsepower power
9563
05:54:54,638 --> 05:54:57,440
versus torque so it's described here
9564
05:54:57,440 --> 05:54:59,600
what to do so
9565
05:54:59,600 --> 05:55:01,280
we start by importing matplotlib
9566
05:55:01,280 --> 05:55:03,840
pipeline as plt remember that line and
9567
05:55:03,840 --> 05:55:06,558
then we use matplotlib inline matplotlib
9568
05:55:06,558 --> 05:55:09,200
inline and then we import the csv
9569
05:55:09,200 --> 05:55:11,040
because we need to read csv files and
9570
05:55:11,040 --> 05:55:14,160
then read the files data
9571
05:55:14,160 --> 05:55:17,200
cards csv right remember this long one
9572
05:55:17,200 --> 05:55:19,600
with 5 000 cars yeah we're going to use
9573
05:55:19,600 --> 05:55:21,520
that again exciting
9574
05:55:21,520 --> 05:55:23,360
and then we list we
9575
05:55:23,360 --> 05:55:24,718
will read that into a list of
9576
05:55:24,718 --> 05:55:27,040
dictionaries like we used to
9577
05:55:27,040 --> 05:55:29,280
and then we use a list comprehension to
9578
05:55:29,280 --> 05:55:32,400
get horsepower torque and if you want it
9579
05:55:32,400 --> 05:55:34,080
fuel city
9580
05:55:34,080 --> 05:55:36,798
miles per gallon right because if you
9581
05:55:36,798 --> 05:55:38,320
want it you can use this one for
9582
05:55:38,320 --> 05:55:40,080
coloring i'm going to show you how to do
9583
05:55:40,080 --> 05:55:42,080
it if if you don't want to use this do
9584
05:55:42,080 --> 05:55:44,160
this bonus just do the horsepower and
9585
05:55:44,160 --> 05:55:46,480
torque and remember there's a twist
9586
05:55:46,480 --> 05:55:49,280
right the horsepower and torque are
9587
05:55:49,280 --> 05:55:51,360
are stored inside the dictionaries in
9588
05:55:51,360 --> 05:55:52,558
the beginning when you read it from the
9589
05:55:52,558 --> 05:55:56,718
csv as strings so you need to convert
9590
05:55:56,718 --> 05:55:59,840
them to integers
9591
05:55:59,840 --> 05:56:02,320
and then you use a scatter plot and i
9592
05:56:02,320 --> 05:56:05,920
say optional you can use alpha 0.25 and
9593
05:56:05,920 --> 05:56:08,718
color with a fuel city miles per gallon
9594
05:56:08,718 --> 05:56:09,840
right
9595
05:56:09,840 --> 05:56:13,360
the alpha argument here it is optional
9596
05:56:13,360 --> 05:56:14,400
again
9597
05:56:14,400 --> 05:56:16,400
it's option right you can add that to
9598
05:56:16,400 --> 05:56:18,638
the scatter plot and it will make the
9599
05:56:18,638 --> 05:56:21,520
the plotting a bit transparent
9600
05:56:21,520 --> 05:56:24,080
i actually didn't show you that in the
9601
05:56:24,080 --> 05:56:26,320
lesson but if you don't want to use this
9602
05:56:26,320 --> 05:56:28,558
don't use it or just add it and see for
9603
05:56:28,558 --> 05:56:30,160
yourself what it does
9604
05:56:30,160 --> 05:56:32,840
perfect so that was horsepower versus
9605
05:56:32,840 --> 05:56:36,400
torque now to roll dice
9606
05:56:36,400 --> 05:56:37,200
so
9607
05:56:37,200 --> 05:56:39,280
in order to simulate
9608
05:56:39,280 --> 05:56:41,840
simulate a dice roll
9609
05:56:41,840 --> 05:56:44,400
well we need randomness to do that and
9610
05:56:44,400 --> 05:56:46,558
then we create a function roll dice
9611
05:56:46,558 --> 05:56:50,000
which simulates the role of two dies
9612
05:56:50,000 --> 05:56:51,520
right
9613
05:56:51,520 --> 05:56:53,440
i think we should have done that right
9614
05:56:53,440 --> 05:56:55,280
and then we use a list comprehension to
9615
05:56:55,280 --> 05:56:58,798
create a list of 500 calls to roll dice
9616
05:56:58,798 --> 05:57:00,400
and then we're going to use a histogram
9617
05:57:00,400 --> 05:57:03,840
with 11 pins of the list
9618
05:57:03,840 --> 05:57:05,520
why 11 pins
9619
05:57:05,520 --> 05:57:07,600
well there are 11 different
9620
05:57:07,600 --> 05:57:12,320
scores you can have right 2 3 4 5 6 7 8
9621
05:57:12,320 --> 05:57:16,480
9 10 11 12 right that's 11.
9622
05:57:16,480 --> 05:57:19,120
good so this should be it are you ready
9623
05:57:19,120 --> 05:57:21,440
for that i hope so because i'm really
9624
05:57:21,440 --> 05:57:23,760
excited about doing it but remember try
9625
05:57:23,760 --> 05:57:25,360
to do it yourself on your own before you
9626
05:57:25,360 --> 05:57:27,760
see how i do it when you get stuck watch
9627
05:57:27,760 --> 05:57:30,638
me do it try it yourself again okay it's
9628
05:57:30,638 --> 05:57:34,080
how you learn the best okay so i can't
9629
05:57:34,080 --> 05:57:36,080
wait until to see you again so see you
9630
05:57:36,080 --> 05:57:38,558
in a moment
9631
05:57:41,280 --> 05:57:42,798
so how did it go let me know in the
9632
05:57:42,798 --> 05:57:44,480
comments down below there i would love
9633
05:57:44,480 --> 05:57:45,840
to hear from you
9634
05:57:45,840 --> 05:57:48,638
uh what do you find challenging or is it
9635
05:57:48,638 --> 05:57:50,798
too easy for you please let me know i
9636
05:57:50,798 --> 05:57:52,718
mean i just love to hear get some
9637
05:57:52,718 --> 05:57:54,400
feedback from you guys i love to read
9638
05:57:54,400 --> 05:57:58,400
that okay so let's get started so i
9639
05:57:58,400 --> 05:57:59,920
assume you already know the project
9640
05:57:59,920 --> 05:58:02,320
because i just read it to you or
9641
05:58:02,320 --> 05:58:04,638
maybe you forgot it so should go back to
9642
05:58:04,638 --> 05:58:06,798
the previous lesson right
9643
05:58:06,798 --> 05:58:09,680
okay so first of all of all import
9644
05:58:09,680 --> 05:58:12,240
matplotlib pi plot as plt and use
9645
05:58:12,240 --> 05:58:16,558
matpotlib inline let's do that import
9646
05:58:16,558 --> 05:58:17,520
matte
9647
05:58:17,520 --> 05:58:20,160
plot lip pie
9648
05:58:20,160 --> 05:58:23,680
plot as plt
9649
05:58:24,160 --> 05:58:26,558
matte plot lip
9650
05:58:26,558 --> 05:58:28,958
inline perfect
9651
05:58:28,958 --> 05:58:31,600
import csv okay
9652
05:58:31,600 --> 05:58:34,798
import csv this is pretty easy right and
9653
05:58:34,798 --> 05:58:38,480
then read the file cars
9654
05:58:38,798 --> 05:58:41,040
into a list of dictionary
9655
05:58:41,040 --> 05:58:43,840
perfect let's let's do that
9656
05:58:43,840 --> 05:58:44,638
so
9657
05:58:44,638 --> 05:58:48,080
how do we do that right so remember
9658
05:58:48,080 --> 05:58:49,360
with
9659
05:58:49,360 --> 05:58:51,040
open
9660
05:58:51,040 --> 05:58:54,638
and then we have the files and cars
9661
05:58:54,638 --> 05:58:57,360
and then we have to have in a read mode
9662
05:58:57,360 --> 05:59:00,558
so this is a file pointer and we do s f
9663
05:59:00,558 --> 05:59:04,480
colon and then we do all our data here c
9664
05:59:04,480 --> 05:59:05,920
s v
9665
05:59:05,920 --> 05:59:08,798
reader and then we take the csv and we
9666
05:59:08,798 --> 05:59:11,920
take the dict reader
9667
05:59:11,920 --> 05:59:15,280
and it takes a file and then we have the
9668
05:59:15,280 --> 05:59:17,920
cars we just call them cars here
9669
05:59:17,920 --> 05:59:19,040
and
9670
05:59:19,040 --> 05:59:20,798
we return
9671
05:59:20,798 --> 05:59:23,440
the csv or reconvert the csv reader to a
9672
05:59:23,440 --> 05:59:25,840
list right
9673
05:59:25,840 --> 05:59:28,480
perfect i just add a few more lines here
9674
05:59:28,480 --> 05:59:29,520
perfect
9675
05:59:29,520 --> 05:59:32,558
so so far so good so actually in cars
9676
05:59:32,558 --> 05:59:34,400
now we should have a long list of them
9677
05:59:34,400 --> 05:59:36,000
let's just look at the first one here so
9678
05:59:36,000 --> 05:59:39,440
we remember our audi here
9679
05:59:39,440 --> 05:59:42,558
this is uh audi and the make here
9680
05:59:42,558 --> 05:59:43,360
and
9681
05:59:43,360 --> 05:59:45,040
we have a lot of data but all we are
9682
05:59:45,040 --> 05:59:47,440
interested in is uh
9683
05:59:47,440 --> 05:59:50,480
horsepower and torque right this is what
9684
05:59:50,480 --> 05:59:52,638
they ask for
9685
05:59:52,638 --> 05:59:54,638
use a list comprehension to get
9686
05:59:54,638 --> 05:59:57,520
horsepower and torque bonus fuel city
9687
05:59:57,520 --> 06:00:01,440
mpg miles per gallon okay so let's call
9688
06:00:01,440 --> 06:00:02,800
it horse
9689
06:00:02,800 --> 06:00:04,400
[Music]
9690
06:00:04,400 --> 06:00:05,360
power
9691
06:00:05,360 --> 06:00:07,920
let me do this comprehension
9692
06:00:07,920 --> 06:00:10,240
so we have all the cars and car right so
9693
06:00:10,240 --> 06:00:12,240
what do we need to do we need to take
9694
06:00:12,240 --> 06:00:14,558
car
9695
06:00:15,040 --> 06:00:18,160
horse power and here it's important of
9696
06:00:18,160 --> 06:00:20,240
course that you spell it correctly here
9697
06:00:20,240 --> 06:00:21,840
if you don't do that you'll get a
9698
06:00:21,840 --> 06:00:23,200
mistake right
9699
06:00:23,200 --> 06:00:27,600
and for car in cars right so there's a
9700
06:00:27,600 --> 06:00:30,080
catch right now let's just try to do it
9701
06:00:30,080 --> 06:00:31,600
actually
9702
06:00:31,600 --> 06:00:34,240
what's the cat catch it is
9703
06:00:34,240 --> 06:00:36,320
well you see actually here the catch
9704
06:00:36,320 --> 06:00:37,600
yourself right
9705
06:00:37,600 --> 06:00:38,638
we have
9706
06:00:38,638 --> 06:00:40,558
quotes around it means it's string so we
9707
06:00:40,558 --> 06:00:42,958
need to convert this one to integers
9708
06:00:42,958 --> 06:00:44,480
right
9709
06:00:44,480 --> 06:00:49,120
so how do you do that well int remember
9710
06:00:49,200 --> 06:00:51,760
int so here we have it so let's just
9711
06:00:51,760 --> 06:00:53,840
look at that again
9712
06:00:53,840 --> 06:00:55,280
now it's it's
9713
06:00:55,280 --> 06:00:57,680
perfect
9714
06:00:59,120 --> 06:01:01,680
and clip that and a few more let's just
9715
06:01:01,680 --> 06:01:05,680
do the same here with uh torque
9716
06:01:06,320 --> 06:01:07,680
torque
9717
06:01:07,680 --> 06:01:09,360
like that
9718
06:01:09,360 --> 06:01:11,200
and we took int
9719
06:01:11,200 --> 06:01:14,080
car
9720
06:01:14,080 --> 06:01:16,558
torque
9721
06:01:16,558 --> 06:01:17,440
for
9722
06:01:17,440 --> 06:01:21,280
car in cars and let's just take the
9723
06:01:21,280 --> 06:01:24,400
fuel right so
9724
06:01:24,958 --> 06:01:28,320
miles per gallon i think we just call it
9725
06:01:28,320 --> 06:01:30,798
and we do the same here int
9726
06:01:30,798 --> 06:01:31,840
car
9727
06:01:31,840 --> 06:01:33,920
and this one i need to
9728
06:01:33,920 --> 06:01:37,280
spell out correctly here
9729
06:01:37,840 --> 06:01:40,160
just copy it there
9730
06:01:40,160 --> 06:01:43,360
for car in cars right so now we have all
9731
06:01:43,360 --> 06:01:44,878
three of them right
9732
06:01:44,878 --> 06:01:47,600
as integer lists so now we can actually
9733
06:01:47,600 --> 06:01:49,520
plot them as scatter plots i think
9734
06:01:49,520 --> 06:01:51,040
that's what we need right
9735
06:01:51,040 --> 06:01:54,320
make a scatter plot use alpha and c for
9736
06:01:54,320 --> 06:01:56,878
the color of mileage okay
9737
06:01:56,878 --> 06:02:00,160
so figure axis
9738
06:02:00,160 --> 06:02:01,520
plt
9739
06:02:01,520 --> 06:02:04,320
sub plots right now we have the plot and
9740
06:02:04,320 --> 06:02:07,600
then just take the axis and scatter
9741
06:02:07,600 --> 06:02:09,360
and we can just first take the
9742
06:02:09,360 --> 06:02:10,878
horsepower
9743
06:02:10,878 --> 06:02:13,440
and torque right so
9744
06:02:13,440 --> 06:02:15,200
now we'll just see how it looks like
9745
06:02:15,200 --> 06:02:17,200
right so this is how it looks like as it
9746
06:02:17,200 --> 06:02:18,718
is right
9747
06:02:18,718 --> 06:02:21,600
perfect let's just add some labels ax
9748
06:02:21,600 --> 06:02:23,120
set
9749
06:02:23,120 --> 06:02:25,040
on label
9750
06:02:25,040 --> 06:02:27,120
and this one has horse
9751
06:02:27,120 --> 06:02:28,320
power
9752
06:02:28,320 --> 06:02:29,600
and ax
9753
06:02:29,600 --> 06:02:30,558
set
9754
06:02:30,558 --> 06:02:33,280
y label
9755
06:02:33,440 --> 06:02:36,638
label and this is the torque
9756
06:02:36,638 --> 06:02:40,080
right so now we have the
9757
06:02:40,160 --> 06:02:43,520
uh what did i do wrong there
9758
06:02:44,080 --> 06:02:46,080
oh i've
9759
06:02:46,080 --> 06:02:47,120
labeled
9760
06:02:47,120 --> 06:02:50,400
here we go perfect right let's just miss
9761
06:02:50,400 --> 06:02:53,920
miss tybo a typo mistake
9762
06:02:53,920 --> 06:02:57,200
okay so this is what we want and then i
9763
06:02:57,200 --> 06:03:00,200
said i could put optional alpha
9764
06:03:00,200 --> 06:03:03,280
0.25 and why would i do that maybe i
9765
06:03:03,280 --> 06:03:05,280
would actually put even more because
9766
06:03:05,280 --> 06:03:07,120
what you see here is when they're all on
9767
06:03:07,120 --> 06:03:08,400
top of each other right it becomes
9768
06:03:08,400 --> 06:03:11,360
really dark but when you put alpha then
9769
06:03:11,360 --> 06:03:13,600
you can actually see where it's mostly
9770
06:03:13,600 --> 06:03:15,600
on top of each other and where it's not
9771
06:03:15,600 --> 06:03:19,520
actually if i put even less here
9772
06:03:19,520 --> 06:03:21,360
it becomes less and less right we can
9773
06:03:21,360 --> 06:03:23,440
experiment a bit with that and you can
9774
06:03:23,440 --> 06:03:25,360
see most of them are just on top of each
9775
06:03:25,360 --> 06:03:27,600
other here and you really really need to
9776
06:03:27,600 --> 06:03:29,760
put alpha low in order to see it
9777
06:03:29,760 --> 06:03:30,958
perfectly
9778
06:03:30,958 --> 06:03:33,040
good and the final thing we could do
9779
06:03:33,040 --> 06:03:36,000
here is actually to add color on it
9780
06:03:36,000 --> 06:03:38,400
right so c equals
9781
06:03:38,400 --> 06:03:42,240
not c equals c but mpg
9782
06:03:42,240 --> 06:03:44,798
here and here you see it right then you
9783
06:03:44,798 --> 06:03:46,558
see actually is there also connection
9784
06:03:46,558 --> 06:03:48,878
between now we have three
9785
06:03:48,878 --> 06:03:50,638
dimensions right
9786
06:03:50,638 --> 06:03:52,320
now you can see if there's a connection
9787
06:03:52,320 --> 06:03:54,798
between the miles per
9788
06:03:54,798 --> 06:03:58,878
gallon in city driving and how much
9789
06:03:58,878 --> 06:03:59,920
torque
9790
06:03:59,920 --> 06:04:02,400
and horsepower is it's obviously this
9791
06:04:02,400 --> 06:04:05,040
scenes that horsepower and torque go
9792
06:04:05,040 --> 06:04:06,798
almost hand in hand right it's pretty
9793
06:04:06,798 --> 06:04:09,360
pretty much close to a line the more out
9794
06:04:09,360 --> 06:04:11,040
here you come the more scattered it is
9795
06:04:11,040 --> 06:04:13,200
but it looks pretty much like a line
9796
06:04:13,200 --> 06:04:14,798
another thing is that the more
9797
06:04:14,798 --> 06:04:16,958
horsepower you have
9798
06:04:16,958 --> 06:04:18,000
then
9799
06:04:18,000 --> 06:04:20,160
yeah you don't see that on the coloring
9800
06:04:20,160 --> 06:04:21,920
here because you don't have the color
9801
06:04:21,920 --> 06:04:23,520
scale here but
9802
06:04:23,520 --> 06:04:25,120
the less
9803
06:04:25,120 --> 06:04:29,120
miles per gallon it drives a car right
9804
06:04:29,120 --> 06:04:30,878
it should be obvious right so down here
9805
06:04:30,878 --> 06:04:32,958
you have the best economy
9806
06:04:32,958 --> 06:04:35,200
fuel economy and up here you have worse
9807
06:04:35,200 --> 06:04:36,400
and worse and it seems you can see the
9808
06:04:36,400 --> 06:04:38,000
color becomes darker and darker so
9809
06:04:38,000 --> 06:04:40,160
there's a connection between all three
9810
06:04:40,160 --> 06:04:42,558
of them the more horsepower the more
9811
06:04:42,558 --> 06:04:46,480
torque and the more or the less miles
9812
06:04:46,480 --> 06:04:48,958
per gallon right so there's a clear
9813
06:04:48,958 --> 06:04:50,878
connection between everything right and
9814
06:04:50,878 --> 06:04:53,600
of course there will be some outliers
9815
06:04:53,600 --> 06:04:55,840
that are a bit outside
9816
06:04:55,840 --> 06:04:58,718
but that's how it is okay so that was
9817
06:04:58,718 --> 06:05:00,878
actually this one here right we did
9818
06:05:00,878 --> 06:05:03,280
everything right we imported we imported
9819
06:05:03,280 --> 06:05:05,360
we read the file we took the horse
9820
06:05:05,360 --> 06:05:07,920
horsepower torque and fuel and we made a
9821
06:05:07,920 --> 06:05:10,718
scatter plot with alpha and color with
9822
06:05:10,718 --> 06:05:13,760
this perfect
9823
06:05:13,760 --> 06:05:16,480
for the next one roll dies
9824
06:05:16,480 --> 06:05:19,600
so import random let's do that
9825
06:05:19,600 --> 06:05:22,480
i like that import random it's nothing
9826
06:05:22,480 --> 06:05:24,400
more fun than random
9827
06:05:24,400 --> 06:05:26,558
create a function roll dies which
9828
06:05:26,558 --> 06:05:28,638
simulates a roll of two dies
9829
06:05:28,638 --> 06:05:30,240
interesting dev
9830
06:05:30,240 --> 06:05:31,760
roll
9831
06:05:31,760 --> 06:05:33,600
dies
9832
06:05:33,600 --> 06:05:36,000
what should we return well you return
9833
06:05:36,000 --> 06:05:37,280
random
9834
06:05:37,280 --> 06:05:42,958
randint remember rendon returns
9835
06:05:42,958 --> 06:05:45,440
returns a random integer in the range a
9836
06:05:45,440 --> 06:05:48,480
to b including both endpoints so include
9837
06:05:48,480 --> 06:05:50,558
both so one two six
9838
06:05:50,558 --> 06:05:51,880
and then we add another
9839
06:05:51,880 --> 06:05:53,200
[Music]
9840
06:05:53,200 --> 06:05:55,360
die
9841
06:05:55,360 --> 06:05:56,798
rendent
9842
06:05:56,798 --> 06:05:57,580
1.6
9843
06:05:57,580 --> 06:05:59,120
[Music]
9844
06:05:59,120 --> 06:06:01,200
so roll dice
9845
06:06:01,200 --> 06:06:03,280
we get here right so we get a different
9846
06:06:03,280 --> 06:06:05,440
from time to time and we know the lowest
9847
06:06:05,440 --> 06:06:07,760
is 2 and the highest is 12
9848
06:06:07,760 --> 06:06:09,200
perfect
9849
06:06:09,200 --> 06:06:11,200
use list comprehension to create a list
9850
06:06:11,200 --> 06:06:14,160
of 500 calls to roll dice right now we
9851
06:06:14,160 --> 06:06:15,920
love this right so we just call it data
9852
06:06:15,920 --> 06:06:16,718
now
9853
06:06:16,718 --> 06:06:17,840
data
9854
06:06:17,840 --> 06:06:20,000
and how do you do this right
9855
06:06:20,000 --> 06:06:21,440
well
9856
06:06:21,440 --> 06:06:22,400
we call
9857
06:06:22,400 --> 06:06:24,000
roll
9858
06:06:24,000 --> 06:06:25,760
dice in this one
9859
06:06:25,760 --> 06:06:26,878
for
9860
06:06:26,878 --> 06:06:30,160
i in range 500 right
9861
06:06:30,160 --> 06:06:31,840
you might say okay so why do we need
9862
06:06:31,840 --> 06:06:34,400
this i here we don't you can also use
9863
06:06:34,400 --> 06:06:36,320
underscore but if you're uncomfortable
9864
06:06:36,320 --> 06:06:38,878
about that just use i it doesn't matter
9865
06:06:38,878 --> 06:06:40,878
boom now we have data
9866
06:06:40,878 --> 06:06:43,280
and data should contain 500 rolls here
9867
06:06:43,280 --> 06:06:45,600
we can actually take the length of
9868
06:06:45,600 --> 06:06:47,040
data and just to make sure that they're
9869
06:06:47,040 --> 06:06:50,080
500 right in 500 rolls
9870
06:06:50,080 --> 06:06:52,718
awesome and we can also take a minimum
9871
06:06:52,718 --> 06:06:54,638
of data it should be two
9872
06:06:54,638 --> 06:06:56,400
and maximum
9873
06:06:56,400 --> 06:06:58,878
of data should be 12 right but now we
9874
06:06:58,878 --> 06:07:01,600
want to see how it's distributed is it
9875
06:07:01,600 --> 06:07:05,680
as likely to hit 12 as it is to hit
9876
06:07:05,680 --> 06:07:06,638
7
9877
06:07:06,638 --> 06:07:08,718
i don't know do you know that
9878
06:07:08,718 --> 06:07:10,558
let's figure it out this is why we have
9879
06:07:10,558 --> 06:07:12,718
the histogram right so fig
9880
06:07:12,718 --> 06:07:14,798
axis
9881
06:07:14,798 --> 06:07:15,840
plt
9882
06:07:15,840 --> 06:07:16,840
sub
9883
06:07:16,840 --> 06:07:19,680
plots and then we do axis
9884
06:07:19,680 --> 06:07:21,520
hist
9885
06:07:21,520 --> 06:07:23,920
and we take data and we take bins and we
9886
06:07:23,920 --> 06:07:26,480
take 11 because we have 11 different
9887
06:07:26,480 --> 06:07:27,840
bins here and we can put different
9888
06:07:27,840 --> 06:07:29,760
number but 11 makes sense here right so
9889
06:07:29,760 --> 06:07:31,520
there's one for each one of them
9890
06:07:31,520 --> 06:07:32,558
and
9891
06:07:32,558 --> 06:07:34,958
let's just look at that simple like that
9892
06:07:34,958 --> 06:07:39,360
so what we see here is actually it is
9893
06:07:39,360 --> 06:07:42,400
not perfectly but you can see here that
9894
06:07:42,400 --> 06:07:45,760
it's less likely to hit 2 row 2 and 12
9895
06:07:45,760 --> 06:07:47,760
than it is to hit something around 7
9896
06:07:47,760 --> 06:07:50,480
which seems to be most likely and if you
9897
06:07:50,480 --> 06:07:52,160
actually calculate on it it should
9898
06:07:52,160 --> 06:07:54,080
actually be totally
9899
06:07:54,080 --> 06:07:56,558
triangular here it's not right but this
9900
06:07:56,558 --> 06:07:58,558
is because it's random so we have too
9901
06:07:58,558 --> 06:08:00,798
many of these we have probably too many
9902
06:08:00,798 --> 06:08:02,798
of these right so it should be exactly
9903
06:08:02,798 --> 06:08:05,120
triangular but it's not
9904
06:08:05,120 --> 06:08:08,638
so this is actually uh what we should do
9905
06:08:08,638 --> 06:08:11,280
in this exercise here and uh we came to
9906
06:08:11,280 --> 06:08:13,520
an end wasn't this exciting i think so
9907
06:08:13,520 --> 06:08:15,280
it's always funny to play around with
9908
06:08:15,280 --> 06:08:16,958
things and learn something new
9909
06:08:16,958 --> 06:08:19,760
and uh yeah i hope you enjoyed that one
9910
06:08:19,760 --> 06:08:21,760
in the next one it's gonna be amazing
9911
06:08:21,760 --> 06:08:23,920
now we're gonna the next stage we're
9912
06:08:23,920 --> 06:08:24,958
gonna
9913
06:08:24,958 --> 06:08:27,520
use some machine learning we're going to
9914
06:08:27,520 --> 06:08:29,840
learn a bit about numpy another favorite
9915
06:08:29,840 --> 06:08:33,760
library of python users and
9916
06:08:33,760 --> 06:08:36,240
we're going to use that to create our
9917
06:08:36,240 --> 06:08:37,120
first
9918
06:08:37,120 --> 06:08:39,760
machine learning algorithm isn't that
9919
06:08:39,760 --> 06:08:42,000
exciting i hope so you think so because
9920
06:08:42,000 --> 06:08:42,878
it is
9921
06:08:42,878 --> 06:08:44,080
so
9922
06:08:44,080 --> 06:08:46,558
until then see you it's going to be
9923
06:08:46,558 --> 06:08:49,440
amazing see you
9924
06:08:52,080 --> 06:08:54,240
machine learning are you excited you
9925
06:08:54,240 --> 06:08:56,480
should be that because machine learning
9926
06:08:56,480 --> 06:08:58,638
is the thing everybody's talking about
9927
06:08:58,638 --> 06:09:01,280
right and you want to master that i know
9928
06:09:01,280 --> 06:09:02,718
you do okay
9929
06:09:02,718 --> 06:09:04,320
so what is it we're going to cover in
9930
06:09:04,320 --> 06:09:06,400
this lecture well we're going to build
9931
06:09:06,400 --> 06:09:09,600
our first machine learning model and use
9932
06:09:09,600 --> 06:09:10,798
it right
9933
06:09:10,798 --> 06:09:12,718
so in this lecture we're going to learn
9934
06:09:12,718 --> 06:09:15,040
something about how what is machine
9935
06:09:15,040 --> 06:09:16,400
learning and how does it differ from
9936
06:09:16,400 --> 06:09:19,120
classical computing what power is it
9937
06:09:19,120 --> 06:09:21,520
that it actually gives you what kind of
9938
06:09:21,520 --> 06:09:24,718
problems can it solve right and
9939
06:09:24,718 --> 06:09:26,240
specifically we're going to make a
9940
06:09:26,240 --> 06:09:28,240
linear regression model which is going
9941
06:09:28,240 --> 06:09:30,558
to help us predict something right so
9942
06:09:30,558 --> 06:09:33,120
given some input it will predict some
9943
06:09:33,120 --> 06:09:36,320
expected output or expected decision
9944
06:09:36,320 --> 06:09:40,000
based on that so if you're ready well
9945
06:09:40,000 --> 06:09:42,000
let's get started inside the jupyter
9946
06:09:42,000 --> 06:09:44,240
notebook it's called linear regression
9947
06:09:44,240 --> 06:09:46,958
which is a machine learning model so the
9948
06:09:46,958 --> 06:09:48,878
goal of this lecture is to learn how
9949
06:09:48,878 --> 06:09:51,200
machine learning is different from
9950
06:09:51,200 --> 06:09:53,920
classical computing right
9951
06:09:53,920 --> 06:09:55,840
then understand machine learning on a
9952
06:09:55,840 --> 06:09:57,360
high level
9953
06:09:57,360 --> 06:10:00,638
we need to learn some numpy basics if
9954
06:10:00,638 --> 06:10:02,798
you don't know what numpy is we'll cover
9955
06:10:02,798 --> 06:10:05,440
that don't worry but numpy is basically
9956
06:10:05,440 --> 06:10:07,840
just a different way to represent the
9957
06:10:07,840 --> 06:10:10,240
numbers in a data structure than from
9958
06:10:10,240 --> 06:10:11,200
the
9959
06:10:11,200 --> 06:10:13,280
list we know and the dictionaries we
9960
06:10:13,280 --> 06:10:15,360
know so far right
9961
06:10:15,360 --> 06:10:17,440
so it makes it more efficient because
9962
06:10:17,440 --> 06:10:20,558
our machine learning on libraries wanted
9963
06:10:20,558 --> 06:10:23,600
data in a more efficient way
9964
06:10:23,600 --> 06:10:25,680
so this is basically what numpy does
9965
06:10:25,680 --> 06:10:29,040
it's a scientific computing library
9966
06:10:29,040 --> 06:10:30,638
then we're going to learn some
9967
06:10:30,638 --> 06:10:32,400
foundation with a linear regression
9968
06:10:32,400 --> 06:10:34,400
which is a specific model we're going to
9969
06:10:34,400 --> 06:10:35,840
implement
9970
06:10:35,840 --> 06:10:37,520
and then we're going to get ready to
9971
06:10:37,520 --> 06:10:39,040
apply it on real data because our
9972
06:10:39,040 --> 06:10:41,360
project it's going to be on real data
9973
06:10:41,360 --> 06:10:42,718
right we're going to create our own
9974
06:10:42,718 --> 06:10:44,638
machine learning model which is going to
9975
06:10:44,638 --> 06:10:46,638
predict something
9976
06:10:46,638 --> 06:10:48,958
good so
9977
06:10:48,958 --> 06:10:51,920
what is machine learning and why are we
9978
06:10:51,920 --> 06:10:54,400
all so excited about it right
9979
06:10:54,400 --> 06:10:55,360
well
9980
06:10:55,360 --> 06:10:57,520
first of all remember what is it that
9981
06:10:57,520 --> 06:11:00,080
machine learning does for us right it
9982
06:11:00,080 --> 06:11:02,798
can kind of make decision or prediction
9983
06:11:02,798 --> 06:11:06,160
of something right so given some input
9984
06:11:06,160 --> 06:11:09,040
right it will try to predict something
9985
06:11:09,040 --> 06:11:12,240
expected output or classify something
9986
06:11:12,240 --> 06:11:13,920
so it can make
9987
06:11:13,920 --> 06:11:17,280
more related decision based on like we
9988
06:11:17,280 --> 06:11:20,320
humans we see in an environment we
9989
06:11:20,320 --> 06:11:22,240
interpret it and make a decision based
9990
06:11:22,240 --> 06:11:24,878
on that imagine you you would do this in
9991
06:11:24,878 --> 06:11:27,440
a classical computing environment well
9992
06:11:27,440 --> 06:11:29,200
what do we have at our disposal we have
9993
06:11:29,200 --> 06:11:31,520
some if statements we have some loops as
9994
06:11:31,520 --> 06:11:33,440
well but how is that helping well the
9995
06:11:33,440 --> 06:11:35,520
loop can make us iterate over the
9996
06:11:35,520 --> 06:11:38,240
environment right the if statements can
9997
06:11:38,240 --> 06:11:40,400
kind of say if this and do that right so
9998
06:11:40,400 --> 06:11:42,558
you kind of have to program all the
9999
06:11:42,558 --> 06:11:44,718
logic inside and you need to predict all
10000
06:11:44,718 --> 06:11:47,520
the logic this logical decisions we need
10001
06:11:47,520 --> 06:11:49,840
along the way right so you see
10002
06:11:49,840 --> 06:11:50,878
if you have
10003
06:11:50,878 --> 06:11:53,840
very complex decisions to make it
10004
06:11:53,840 --> 06:11:55,360
becomes very complex to write all these
10005
06:11:55,360 --> 06:11:57,600
if statements you see
10006
06:11:57,600 --> 06:11:58,480
so
10007
06:11:58,480 --> 06:12:00,638
basically in classical computing it's
10008
06:12:00,638 --> 06:12:02,718
like very specific instructions when we
10009
06:12:02,718 --> 06:12:04,958
see this specifically here do this when
10010
06:12:04,958 --> 06:12:07,120
we see this specifically here do that
10011
06:12:07,120 --> 06:12:08,400
right
10012
06:12:08,400 --> 06:12:10,638
modern computing or with machine
10013
06:12:10,638 --> 06:12:13,680
learning as we say we have a more like
10014
06:12:13,680 --> 06:12:16,160
an algorithm we feed data and based on
10015
06:12:16,160 --> 06:12:18,798
this data it creates a model so it's
10016
06:12:18,798 --> 06:12:20,798
more like indirect computing and it can
10017
06:12:20,798 --> 06:12:22,400
predict
10018
06:12:22,400 --> 06:12:24,958
based on that data so it creates a model
10019
06:12:24,958 --> 06:12:26,878
on that data and makes prediction based
10020
06:12:26,878 --> 06:12:29,360
on that so later when we have more data
10021
06:12:29,360 --> 06:12:31,520
we can feed it with more data and make
10022
06:12:31,520 --> 06:12:32,320
better
10023
06:12:32,320 --> 06:12:35,200
prediction in the future right
10024
06:12:35,200 --> 06:12:37,360
so we keep improving
10025
06:12:37,360 --> 06:12:39,920
so set differently in classical
10026
06:12:39,920 --> 06:12:42,558
computing model everything is programmed
10027
06:12:42,558 --> 06:12:45,600
into the algorithm this has a limitation
10028
06:12:45,600 --> 06:12:47,680
that all decision logic need to be
10029
06:12:47,680 --> 06:12:50,160
understood before usage right again we
10030
06:12:50,160 --> 06:12:52,878
need to compute we need to program all
10031
06:12:52,878 --> 06:12:55,840
the if statements basically and if we if
10032
06:12:55,840 --> 06:12:58,000
things change we need to modify the
10033
06:12:58,000 --> 06:13:00,400
program right so imagine you make this
10034
06:13:00,400 --> 06:13:03,040
insanely big decision tree remember the
10035
06:13:03,040 --> 06:13:04,958
decision tree we made with the
10036
06:13:04,958 --> 06:13:06,240
with a
10037
06:13:06,240 --> 06:13:09,280
car insurance company well in this case
10038
06:13:09,280 --> 06:13:11,920
here you have a lot of if statements
10039
06:13:11,920 --> 06:13:13,920
together but if you change that decision
10040
06:13:13,920 --> 06:13:15,520
tree model
10041
06:13:15,520 --> 06:13:17,760
dramatically you need to change a lot of
10042
06:13:17,760 --> 06:13:20,958
code you can probably realize
10043
06:13:20,958 --> 06:13:23,040
with modern computing or machine
10044
06:13:23,040 --> 06:13:26,798
learning right this paradigm is chained
10045
06:13:26,798 --> 06:13:28,000
changed
10046
06:13:28,000 --> 06:13:30,160
we feed the algorithm with data and
10047
06:13:30,160 --> 06:13:32,718
based on that data we do the decision in
10048
06:13:32,718 --> 06:13:35,360
the program so we just re-run the
10049
06:13:35,360 --> 06:13:38,080
program with new data and the algorithm
10050
06:13:38,080 --> 06:13:39,920
improves by itself
10051
06:13:39,920 --> 06:13:40,798
huh
10052
06:13:40,798 --> 06:13:44,000
that that's nice
10053
06:13:44,000 --> 06:13:46,240
so a bit about how machine learning
10054
06:13:46,240 --> 06:13:48,798
works and this is a high level right so
10055
06:13:48,798 --> 06:13:50,798
on a high level you can divide machine
10056
06:13:50,798 --> 06:13:53,120
learning into two phases there's a
10057
06:13:53,120 --> 06:13:55,200
learning phase right that's the phase i
10058
06:13:55,200 --> 06:13:56,958
talk about where you feed the algorithm
10059
06:13:56,958 --> 06:13:59,680
you train it you make it better right
10060
06:13:59,680 --> 06:14:01,600
and then there's the prediction phase
10061
06:14:01,600 --> 06:14:04,320
right where we use the model and say
10062
06:14:04,320 --> 06:14:06,160
what is it that you think now what do
10063
06:14:06,160 --> 06:14:07,840
you predict from this based on this
10064
06:14:07,840 --> 06:14:11,040
input here right this environment here
10065
06:14:11,040 --> 06:14:12,958
so
10066
06:14:12,958 --> 06:14:15,680
a lot of things often focus on the first
10067
06:14:15,680 --> 06:14:17,520
phase because this is where you make the
10068
06:14:17,520 --> 06:14:19,600
magic right are you good at creating a
10069
06:14:19,600 --> 06:14:21,920
model it will predict really well
10070
06:14:21,920 --> 06:14:23,680
because the prediction in itself it's
10071
06:14:23,680 --> 06:14:25,200
not that difficult right so when you
10072
06:14:25,200 --> 06:14:27,440
have a model you just give it a new
10073
06:14:27,440 --> 06:14:29,680
environment or a new context and it will
10074
06:14:29,680 --> 06:14:31,680
make a decision right this there's not
10075
06:14:31,680 --> 06:14:34,080
much programming to it the real key is
10076
06:14:34,080 --> 06:14:36,160
to create a good
10077
06:14:36,160 --> 06:14:39,280
machine learning model so this is this
10078
06:14:39,280 --> 06:14:42,718
process is divided into steps on a high
10079
06:14:42,718 --> 06:14:43,680
level
10080
06:14:43,680 --> 06:14:45,920
so in the first step here we need some
10081
06:14:45,920 --> 06:14:48,000
training data again if you don't have
10082
06:14:48,000 --> 06:14:49,680
any training data how are you going to
10083
06:14:49,680 --> 06:14:51,840
make the model work so basically what
10084
06:14:51,840 --> 06:14:53,280
you need is some data set that
10085
06:14:53,280 --> 06:14:55,840
represents the future data you will base
10086
06:14:55,840 --> 06:14:58,798
your decision or predictions on right so
10087
06:14:58,798 --> 06:15:00,558
this is the data we will build the model
10088
06:15:00,558 --> 06:15:01,520
upon
10089
06:15:01,520 --> 06:15:03,600
then we have the pre-processing
10090
06:15:03,600 --> 06:15:05,760
pre-processing we need to clean the data
10091
06:15:05,760 --> 06:15:07,920
data and format the data that basically
10092
06:15:07,920 --> 06:15:09,920
mean we need to put it in a specific
10093
06:15:09,920 --> 06:15:11,760
format so when you work with a lot of
10094
06:15:11,760 --> 06:15:13,280
data often you will find there will be
10095
06:15:13,280 --> 06:15:15,440
discrepancies in the data there will be
10096
06:15:15,440 --> 06:15:18,000
data we cannot use and so on so and and
10097
06:15:18,000 --> 06:15:20,320
finally we need to format it in correct
10098
06:15:20,320 --> 06:15:22,638
way so the algorithm understands it
10099
06:15:22,638 --> 06:15:24,798
basically said we're going to use this
10100
06:15:24,798 --> 06:15:27,120
not so much on this part in our project
10101
06:15:27,120 --> 06:15:28,480
but we're going to format it in the
10102
06:15:28,480 --> 06:15:30,480
correct way for the algorithm because
10103
06:15:30,480 --> 06:15:32,958
the algorithm needs to be formatted
10104
06:15:32,958 --> 06:15:35,120
correctly
10105
06:15:35,120 --> 06:15:38,320
so the learning phase well
10106
06:15:38,320 --> 06:15:40,080
you actually divided in more categories
10107
06:15:40,080 --> 06:15:41,760
and supervised and unsupervised but
10108
06:15:41,760 --> 06:15:43,840
these are like the high level so you can
10109
06:15:43,840 --> 06:15:46,320
be supervised or unsupervised and
10110
06:15:46,320 --> 06:15:48,480
supervised learning this is where you
10111
06:15:48,480 --> 06:15:50,878
tell the algorithm where you have some
10112
06:15:50,878 --> 06:15:53,120
input where you actually know the exact
10113
06:15:53,120 --> 06:15:55,440
output right so you know that if you see
10114
06:15:55,440 --> 06:15:57,280
this input you need to predict this
10115
06:15:57,280 --> 06:16:00,160
output so you categorize this input is
10116
06:16:00,160 --> 06:16:02,240
predicting this output
10117
06:16:02,240 --> 06:16:04,638
so we can see this input and so forth so
10118
06:16:04,638 --> 06:16:06,638
you have a lot of data like that in
10119
06:16:06,638 --> 06:16:08,958
supervised learning right you supervise
10120
06:16:08,958 --> 06:16:10,958
it when you see this do that see this
10121
06:16:10,958 --> 06:16:12,878
predict that see this predict that right
10122
06:16:12,878 --> 06:16:14,400
you have a long list of all these
10123
06:16:14,400 --> 06:16:16,400
connections together and then in
10124
06:16:16,400 --> 06:16:19,040
unsupervised learning it's different you
10125
06:16:19,040 --> 06:16:20,958
don't know anything so you just say this
10126
06:16:20,958 --> 06:16:23,600
is input this is input figure out some
10127
06:16:23,600 --> 06:16:24,878
kind of
10128
06:16:24,878 --> 06:16:26,798
intelligent thing to say about it right
10129
06:16:26,798 --> 06:16:30,000
so that's unsupervised learning
10130
06:16:30,000 --> 06:16:32,000
and the final stage is where you test
10131
06:16:32,000 --> 06:16:34,240
your algorithm right so now you created
10132
06:16:34,240 --> 06:16:36,320
your model and you need to test how good
10133
06:16:36,320 --> 06:16:39,440
this model is how does it perform right
10134
06:16:39,440 --> 06:16:41,280
so this is where you measure it right so
10135
06:16:41,280 --> 06:16:43,040
often what you do is actually from your
10136
06:16:43,040 --> 06:16:45,840
training data
10137
06:16:45,840 --> 06:16:48,080
you divide it up in training set and
10138
06:16:48,080 --> 06:16:50,080
validation set right and the validation
10139
06:16:50,080 --> 06:16:52,160
set is then used in the far end over
10140
06:16:52,160 --> 06:16:54,798
here to check and validate that it is
10141
06:16:54,798 --> 06:16:58,160
predicting as it's supposed to be or
10142
06:16:58,160 --> 06:16:59,680
often you have a measure since this
10143
06:16:59,680 --> 06:17:03,360
predicts this kind of accuracy okay
10144
06:17:03,360 --> 06:17:07,040
so this is it
10145
06:17:07,040 --> 06:17:08,400
and
10146
06:17:08,400 --> 06:17:09,840
i have a bit more description here and
10147
06:17:09,840 --> 06:17:11,120
here also
10148
06:17:11,120 --> 06:17:12,400
here we have a description of the
10149
06:17:12,400 --> 06:17:15,600
supervised and the unsupervised learning
10150
06:17:15,600 --> 06:17:18,000
i also added actually the reinforcement
10151
06:17:18,000 --> 06:17:20,080
learning here it teaches us a machine to
10152
06:17:20,080 --> 06:17:22,240
think for itself based on past action
10153
06:17:22,240 --> 06:17:24,000
rewards and this one is actually going
10154
06:17:24,000 --> 06:17:26,000
to be in the capstone project where
10155
06:17:26,000 --> 06:17:27,760
we're going to make a reinforcement
10156
06:17:27,760 --> 06:17:30,558
model from scratch that means we're not
10157
06:17:30,558 --> 06:17:32,240
going to use any libraries when we
10158
06:17:32,240 --> 06:17:34,080
create it we're gonna
10159
06:17:34,080 --> 06:17:36,638
programming from
10160
06:17:36,638 --> 06:17:38,878
nothing it's gonna be amazing that one
10161
06:17:38,878 --> 06:17:40,958
this is kind of the key of this why i
10162
06:17:40,958 --> 06:17:42,878
love this reinforcement learning first
10163
06:17:42,878 --> 06:17:45,520
of all it is easy to understand and
10164
06:17:45,520 --> 06:17:48,080
secondly because you can program it from
10165
06:17:48,080 --> 06:17:51,040
scratch you don't need any fancy library
10166
06:17:51,040 --> 06:17:53,120
to do it so it will give you a deep
10167
06:17:53,120 --> 06:17:55,040
understanding on how it actually works
10168
06:17:55,040 --> 06:17:56,638
this reinforcement but don't worry about
10169
06:17:56,638 --> 06:17:58,558
that right now because we're going to
10170
06:17:58,558 --> 06:18:00,480
cover that in the capstone project in
10171
06:18:00,480 --> 06:18:04,480
the final project in this course
10172
06:18:04,718 --> 06:18:06,480
perfect
10173
06:18:06,480 --> 06:18:07,280
so
10174
06:18:07,280 --> 06:18:11,120
we are ready to get started numpy
10175
06:18:11,120 --> 06:18:11,920
so
10176
06:18:11,920 --> 06:18:13,760
remember in the beginning here we needed
10177
06:18:13,760 --> 06:18:16,638
to look into the numpy
10178
06:18:16,638 --> 06:18:18,480
library and we need it because numpy
10179
06:18:18,480 --> 06:18:20,320
library is efficient way to work with
10180
06:18:20,320 --> 06:18:23,520
numbers specifically in these scientific
10181
06:18:23,520 --> 06:18:25,200
libraries that we're going to use for
10182
06:18:25,200 --> 06:18:27,360
machine learning here they love numpy's
10183
06:18:27,360 --> 06:18:28,638
because it's more efficient way to
10184
06:18:28,638 --> 06:18:31,520
represent the data so let's just start
10185
06:18:31,520 --> 06:18:33,280
importing numpy
10186
06:18:33,280 --> 06:18:35,440
import it as np that's just a standard
10187
06:18:35,440 --> 06:18:38,000
you do that and let's create our first
10188
06:18:38,000 --> 06:18:39,840
numpy array so you'll see it's very
10189
06:18:39,840 --> 06:18:42,878
similar to a list but with limitations
10190
06:18:42,878 --> 06:18:45,520
so let's just make a array here we just
10191
06:18:45,520 --> 06:18:46,958
call it a1 because we're going to create
10192
06:18:46,958 --> 06:18:48,878
another one and
10193
06:18:48,878 --> 06:18:52,000
you just access this array with np the
10194
06:18:52,000 --> 06:18:53,920
library numpy and then you say you want
10195
06:18:53,920 --> 06:18:56,000
an array and this array just takes a
10196
06:18:56,000 --> 06:18:57,360
list
10197
06:18:57,360 --> 06:19:00,080
here good so this looks basically like a
10198
06:19:00,080 --> 06:19:02,320
list except you have this array outside
10199
06:19:02,320 --> 06:19:04,320
here so this has some differences right
10200
06:19:04,320 --> 06:19:06,558
so first of all let's inspect actually
10201
06:19:06,558 --> 06:19:08,718
it has something called d type which is
10202
06:19:08,718 --> 06:19:10,000
a data type
10203
06:19:10,000 --> 06:19:11,520
and when you look at that it only has
10204
06:19:11,520 --> 06:19:13,520
one data type what does that mean so the
10205
06:19:13,520 --> 06:19:16,240
entire array here with all the integers
10206
06:19:16,240 --> 06:19:18,638
and it could be longer if you wanted to
10207
06:19:18,638 --> 06:19:21,040
it only has one data type that basically
10208
06:19:21,040 --> 06:19:23,520
mean that all of the entries need to
10209
06:19:23,520 --> 06:19:26,080
have the same data type in this case
10210
06:19:26,080 --> 06:19:28,878
it's an integer and it is 64 because
10211
06:19:28,878 --> 06:19:31,200
it's represented by 64 bits
10212
06:19:31,200 --> 06:19:34,160
and that means that
10213
06:19:34,160 --> 06:19:35,760
the only entries
10214
06:19:35,760 --> 06:19:37,360
that are
10215
06:19:37,360 --> 06:19:40,320
available here has to be integer 64.
10216
06:19:40,320 --> 06:19:42,798
this is a limitation right except in a
10217
06:19:42,798 --> 06:19:45,520
python list you could had have any data
10218
06:19:45,520 --> 06:19:48,478
type in any entry you wanted right so it
10219
06:19:48,478 --> 06:19:50,638
could change but for a numpy array it's
10220
06:19:50,638 --> 06:19:53,600
the same one all along the way
10221
06:19:53,600 --> 06:19:56,000
this is a restriction on it and you if
10222
06:19:56,000 --> 06:19:57,360
you're new to programming you want to
10223
06:19:57,360 --> 06:19:59,840
why make restrictions well it's because
10224
06:19:59,840 --> 06:20:00,958
you can make other things more
10225
06:20:00,958 --> 06:20:04,798
effectively now right imagine you are a
10226
06:20:04,798 --> 06:20:07,200
program and you don't know how the input
10227
06:20:07,200 --> 06:20:08,878
is right and you need to program
10228
06:20:08,878 --> 06:20:10,478
something that takes some kind of input
10229
06:20:10,478 --> 06:20:12,478
you don't know what kind of input well
10230
06:20:12,478 --> 06:20:14,160
you make you need to make a lot of
10231
06:20:14,160 --> 06:20:16,320
special cases because if it's a string
10232
06:20:16,320 --> 06:20:18,320
you do this if it's a float do this if
10233
06:20:18,320 --> 06:20:20,160
it's an integer to this and so forth
10234
06:20:20,160 --> 06:20:21,440
right
10235
06:20:21,440 --> 06:20:23,440
when you know for sure it all the
10236
06:20:23,440 --> 06:20:26,958
entries have the same type of and
10237
06:20:26,958 --> 06:20:29,040
all the entries have the same type well
10238
06:20:29,040 --> 06:20:31,760
you don't need as many if branches right
10239
06:20:31,760 --> 06:20:34,000
it's easier to program it becomes more
10240
06:20:34,000 --> 06:20:35,760
effective as well right because you have
10241
06:20:35,760 --> 06:20:36,400
less
10242
06:20:36,400 --> 06:20:38,478
less special cases because it's just
10243
06:20:38,478 --> 06:20:41,200
like one case
10244
06:20:41,200 --> 06:20:43,440
another thing that is different is that
10245
06:20:43,440 --> 06:20:45,680
if you look at the shape here it can be
10246
06:20:45,680 --> 06:20:47,840
a bit difficult to see here i understand
10247
06:20:47,840 --> 06:20:49,680
here but it says it has four entries and
10248
06:20:49,680 --> 06:20:51,878
there's a comma because you can multi
10249
06:20:51,878 --> 06:20:53,680
multi-dimensional we're not really going
10250
06:20:53,680 --> 06:20:55,760
to dive into that aspect of it but the
10251
06:20:55,760 --> 06:20:57,920
aspect we want to dive into is that the
10252
06:20:57,920 --> 06:21:01,360
shape of a array is fixed
10253
06:21:01,360 --> 06:21:02,160
so
10254
06:21:02,160 --> 06:21:05,360
once you create it you cannot change the
10255
06:21:05,360 --> 06:21:08,958
size the number of entries in it anymore
10256
06:21:08,958 --> 06:21:10,798
and again this is a restriction but
10257
06:21:10,798 --> 06:21:13,520
again a restriction which makes it more
10258
06:21:13,520 --> 06:21:14,958
effective
10259
06:21:14,958 --> 06:21:17,920
good so let's try to make another one a
10260
06:21:17,920 --> 06:21:19,680
2 here
10261
06:21:19,680 --> 06:21:22,478
np array
10262
06:21:22,478 --> 06:21:25,760
and then we take 5 6 7 8 and we execute
10263
06:21:25,760 --> 06:21:29,520
that now we have an a1 and an a2
10264
06:21:29,520 --> 06:21:33,360
right so they are similar as you see
10265
06:21:33,360 --> 06:21:35,920
so what i want to show you is you can
10266
06:21:35,920 --> 06:21:38,478
make computations on it right so
10267
06:21:38,478 --> 06:21:40,558
a1 for instance you can
10268
06:21:40,558 --> 06:21:42,320
multiply it if you multiply it you
10269
06:21:42,320 --> 06:21:45,200
multiply each entry by two but you can
10270
06:21:45,200 --> 06:21:47,840
also multiply two
10271
06:21:47,840 --> 06:21:50,558
numpy arrays and what it does
10272
06:21:50,558 --> 06:21:53,440
now i should have both here yes
10273
06:21:53,440 --> 06:21:55,520
what it does here you see one two three
10274
06:21:55,520 --> 06:21:57,440
four five six seven eight so what it
10275
06:21:57,440 --> 06:22:00,320
does is one times five is 5 as you see
10276
06:22:00,320 --> 06:22:04,718
here 2 times 6 is 12 3 times 7 is 21 and
10277
06:22:04,718 --> 06:22:07,680
4 times 8 is 38 right so you see it
10278
06:22:07,680 --> 06:22:11,040
multiplies entry by entry so this is
10279
06:22:11,040 --> 06:22:12,080
some earth
10280
06:22:12,080 --> 06:22:13,760
this is just some basic computation you
10281
06:22:13,760 --> 06:22:16,160
can do and similarly you can do
10282
06:22:16,160 --> 06:22:17,760
play around with it and see also in
10283
06:22:17,760 --> 06:22:20,320
addition and so on
10284
06:22:20,320 --> 06:22:22,558
these things are very handy when you
10285
06:22:22,558 --> 06:22:25,440
work with them and it's nice to know how
10286
06:22:25,440 --> 06:22:26,400
it works
10287
06:22:26,400 --> 06:22:29,360
good but for our purpose we are going to
10288
06:22:29,360 --> 06:22:31,280
use this numpy array which you have an
10289
06:22:31,280 --> 06:22:33,040
idea about what is now it's just a
10290
06:22:33,040 --> 06:22:34,958
different way of having a list of
10291
06:22:34,958 --> 06:22:36,000
numbers
10292
06:22:36,000 --> 06:22:37,680
and it's more effective we want to use
10293
06:22:37,680 --> 06:22:40,878
it with a library called sklearn which
10294
06:22:40,878 --> 06:22:42,878
has the linear regression model we want
10295
06:22:42,878 --> 06:22:45,520
to use so the next step of this part
10296
06:22:45,520 --> 06:22:47,680
here is to figure out how to use it and
10297
06:22:47,680 --> 06:22:49,040
in the project we're going to use it on
10298
06:22:49,040 --> 06:22:52,478
real data okay so let's try to import it
10299
06:22:52,478 --> 06:22:58,558
from sklearn we want a linear model
10300
06:22:58,558 --> 06:23:00,320
model
10301
06:23:00,320 --> 06:23:01,680
import
10302
06:23:01,680 --> 06:23:03,600
linear regression right so this is a
10303
06:23:03,600 --> 06:23:05,360
model we want to do and i actually want
10304
06:23:05,360 --> 06:23:07,920
to import matplotlib
10305
06:23:07,920 --> 06:23:13,040
as well pi plot as plt and we just do as
10306
06:23:13,040 --> 06:23:16,718
normally matte oh matt matt plot
10307
06:23:16,718 --> 06:23:18,558
lip
10308
06:23:18,558 --> 06:23:21,280
really used inline as well
10309
06:23:21,280 --> 06:23:22,798
and
10310
06:23:22,798 --> 06:23:25,520
i forgot a t here import thank you for
10311
06:23:25,520 --> 06:23:27,840
noticing that small mistake we all do
10312
06:23:27,840 --> 06:23:31,280
typos all the time perfect good so what
10313
06:23:31,280 --> 06:23:33,600
we're going to do now is just to feed it
10314
06:23:33,600 --> 06:23:35,200
some data so you can see how it works
10315
06:23:35,200 --> 06:23:37,680
right so what i import here is the
10316
06:23:37,680 --> 06:23:40,080
linear regression model here this is a
10317
06:23:40,080 --> 06:23:43,440
model we want to work with right so
10318
06:23:43,440 --> 06:23:45,120
this is going to do all the magic and
10319
06:23:45,120 --> 06:23:46,718
the reason why we needed the numpy
10320
06:23:46,718 --> 06:23:49,920
arrays is because this model here uses
10321
06:23:49,920 --> 06:23:51,680
input from a numpy array because it's
10322
06:23:51,680 --> 06:23:53,920
more effect efficient so it makes the
10323
06:23:53,920 --> 06:23:57,280
calculations faster so let's try to make
10324
06:23:57,280 --> 06:24:00,400
some data here so how would
10325
06:24:00,400 --> 06:24:03,200
the model work is like it will have some
10326
06:24:03,200 --> 06:24:05,120
input data and some output data and the
10327
06:24:05,120 --> 06:24:08,000
input data will be the x axis data so in
10328
06:24:08,000 --> 06:24:10,240
this case here we're going to make some
10329
06:24:10,240 --> 06:24:12,798
just some data for i in
10330
06:24:12,798 --> 06:24:13,680
for
10331
06:24:13,680 --> 06:24:16,558
i for i in range let's just take 10
10332
06:24:16,558 --> 06:24:18,718
numbers it's okay and then we have some
10333
06:24:18,718 --> 06:24:21,440
data of the output here so for these
10334
06:24:21,440 --> 06:24:23,280
cases here
10335
06:24:23,280 --> 06:24:25,200
it's not the data itself
10336
06:24:25,200 --> 06:24:27,840
it is just to have some data right so
10337
06:24:27,840 --> 06:24:28,638
here
10338
06:24:28,638 --> 06:24:30,638
we would have some data which we
10339
06:24:30,638 --> 06:24:33,040
spatially basically says well
10340
06:24:33,040 --> 06:24:34,478
let's just look at it
10341
06:24:34,478 --> 06:24:36,718
x and y
10342
06:24:36,718 --> 06:24:38,878
x and y it's just you know numbers so if
10343
06:24:38,878 --> 06:24:41,440
it was a data set it will say for
10344
06:24:41,440 --> 06:24:42,798
input
10345
06:24:42,798 --> 06:24:45,360
0 we have output 0 for input 1 we have
10346
06:24:45,360 --> 06:24:47,440
output 1 right and so forth and these
10347
06:24:47,440 --> 06:24:49,280
could be anything right but these are
10348
06:24:49,280 --> 06:24:52,160
connected together these input output
10349
06:24:52,160 --> 06:24:54,958
things right x input y output
10350
06:24:54,958 --> 06:24:57,200
so this is the input for the algorithm
10351
06:24:57,200 --> 06:24:58,638
the next thing we want to do is actually
10352
06:24:58,638 --> 06:25:02,638
have to in numpy arrays and
10353
06:25:02,638 --> 06:25:04,718
this is where it becomes a bit tricky
10354
06:25:04,718 --> 06:25:06,240
because the
10355
06:25:06,240 --> 06:25:08,320
library needs in specific format as well
10356
06:25:08,320 --> 06:25:09,760
but first let's just convert them to
10357
06:25:09,760 --> 06:25:11,600
numpy array so array
10358
06:25:11,600 --> 06:25:12,638
x here
10359
06:25:12,638 --> 06:25:17,440
and y here equals to np array y here and
10360
06:25:17,440 --> 06:25:19,280
notice that i use capital letters here
10361
06:25:19,280 --> 06:25:21,360
this is just a standard i don't really i
10362
06:25:21,360 --> 06:25:23,840
mean i like python way of doing things
10363
06:25:23,840 --> 06:25:26,638
and apparently
10364
06:25:26,638 --> 06:25:29,200
this is how it's done done
10365
06:25:29,200 --> 06:25:31,040
now in statistic you use these capital
10366
06:25:31,040 --> 06:25:33,360
letters here right and uh yeah so here
10367
06:25:33,360 --> 06:25:35,360
you have it but we need to format it in
10368
06:25:35,360 --> 06:25:37,200
a different way because what it takes
10369
06:25:37,200 --> 06:25:39,520
here is here's like a one-dimensional
10370
06:25:39,520 --> 06:25:42,320
row here and it wants to take it in
10371
06:25:42,320 --> 06:25:44,638
you'll see in a moment reshape
10372
06:25:44,638 --> 06:25:46,878
minus one comma
10373
06:25:46,878 --> 06:25:50,080
comma one here and you reshape a bit
10374
06:25:50,080 --> 06:25:51,360
here in
10375
06:25:51,360 --> 06:25:53,440
minus one comma one here
10376
06:25:53,440 --> 06:25:55,760
and here we have it on a different axis
10377
06:25:55,760 --> 06:25:57,520
right so you see before it was on one
10378
06:25:57,520 --> 06:25:59,680
row here and now you have one column of
10379
06:25:59,680 --> 06:26:01,840
data instead so it's like an array with
10380
06:26:01,840 --> 06:26:03,040
uh
10381
06:26:03,040 --> 06:26:05,680
single entries of
10382
06:26:05,680 --> 06:26:07,520
of lists
10383
06:26:07,520 --> 06:26:10,080
python arrays down here so it it kind of
10384
06:26:10,080 --> 06:26:11,840
changes the dimension right and you see
10385
06:26:11,840 --> 06:26:14,160
here this is like the minus one and one
10386
06:26:14,160 --> 06:26:16,320
so minus one here means that uh just
10387
06:26:16,320 --> 06:26:18,878
like a negative indexing so if we have
10388
06:26:18,878 --> 06:26:21,040
like 10
10389
06:26:21,040 --> 06:26:23,760
10 entries one two three four 10 right
10390
06:26:23,760 --> 06:26:24,718
it means
10391
06:26:24,718 --> 06:26:27,440
it says a 10 here we need 10 rows and
10392
06:26:27,440 --> 06:26:28,400
one
10393
06:26:28,400 --> 06:26:29,200
one
10394
06:26:29,200 --> 06:26:30,878
element on each row right so we have ten
10395
06:26:30,878 --> 06:26:32,798
rows here and one element on means so
10396
06:26:32,798 --> 06:26:34,798
the minus one is like negative indexing
10397
06:26:34,798 --> 06:26:36,958
as we know it
10398
06:26:36,958 --> 06:26:38,080
perfect
10399
06:26:38,080 --> 06:26:40,558
oh now this one i want to delete perfect
10400
06:26:40,558 --> 06:26:44,958
so now we're ready for our algorithm
10401
06:26:44,958 --> 06:26:49,280
so let's just call linear regressor
10402
06:26:49,280 --> 06:26:52,280
regressor
10403
06:26:52,718 --> 06:26:55,280
and we take the linear regression model
10404
06:26:55,280 --> 06:26:57,200
here and
10405
06:26:57,200 --> 06:26:58,878
then we take our linear regression
10406
06:26:58,878 --> 06:27:00,798
grasser and we fit it
10407
06:27:00,798 --> 06:27:03,920
to x and y so this is basically the
10408
06:27:03,920 --> 06:27:05,440
magic it does
10409
06:27:05,440 --> 06:27:07,280
and after we have fitted it we can
10410
06:27:07,280 --> 06:27:09,680
actually get a prediction on it
10411
06:27:09,680 --> 06:27:10,558
so
10412
06:27:10,558 --> 06:27:12,080
why
10413
06:27:12,080 --> 06:27:13,920
prediction
10414
06:27:13,920 --> 06:27:14,798
so
10415
06:27:14,798 --> 06:27:17,840
we take the linear regressor and we say
10416
06:27:17,840 --> 06:27:21,200
predict all the values for x so in this
10417
06:27:21,200 --> 06:27:23,120
case let's just
10418
06:27:23,120 --> 06:27:25,120
look at this one here so the linear
10419
06:27:25,120 --> 06:27:28,000
regressor here it creates a
10420
06:27:28,000 --> 06:27:30,320
a class of this or an object of this
10421
06:27:30,320 --> 06:27:32,638
linear regression model
10422
06:27:32,638 --> 06:27:34,558
on this line here linear regressor we
10423
06:27:34,558 --> 06:27:37,440
make the fit that is it fits the data as
10424
06:27:37,440 --> 06:27:38,958
best as it can
10425
06:27:38,958 --> 06:27:41,600
and then this one here it takes all the
10426
06:27:41,600 --> 06:27:44,320
x inputs and says well what do you
10427
06:27:44,320 --> 06:27:45,520
predict the
10428
06:27:45,520 --> 06:27:46,718
y
10429
06:27:46,718 --> 06:27:49,920
output to be right so let's try to
10430
06:27:49,920 --> 06:27:52,320
visualize this
10431
06:27:52,320 --> 06:27:55,440
so we do that by figure axis
10432
06:27:55,440 --> 06:27:57,360
on plt sub
10433
06:27:57,360 --> 06:27:58,478
plots
10434
06:27:58,478 --> 06:27:59,520
that's
10435
06:27:59,520 --> 06:28:01,120
matplotlib remember
10436
06:28:01,120 --> 06:28:01,840
and
10437
06:28:01,840 --> 06:28:03,040
x
10438
06:28:03,040 --> 06:28:06,320
we make a scatter plot
10439
06:28:06,478 --> 06:28:07,520
scatter
10440
06:28:07,520 --> 06:28:08,400
with
10441
06:28:08,400 --> 06:28:11,600
x and y so this first just scatter the
10442
06:28:11,600 --> 06:28:13,200
points right so these are the points
10443
06:28:13,200 --> 06:28:14,798
we're trying to fit and this looks like
10444
06:28:14,798 --> 06:28:16,240
a perfect line right we know that
10445
06:28:16,240 --> 06:28:19,040
because 0 0 1 1 2 2 and so on so it's a
10446
06:28:19,040 --> 06:28:20,240
perfect line
10447
06:28:20,240 --> 06:28:21,760
the interesting thing is if our
10448
06:28:21,760 --> 06:28:24,718
prediction line here will be perfect as
10449
06:28:24,718 --> 06:28:28,240
well so we can actually add that
10450
06:28:28,320 --> 06:28:32,400
so we make a plot x and y print and
10451
06:28:32,400 --> 06:28:34,558
let's just make the color
10452
06:28:34,558 --> 06:28:36,000
red here
10453
06:28:36,000 --> 06:28:38,160
and you see here this is a prediction
10454
06:28:38,160 --> 06:28:41,520
line so given any input along this line
10455
06:28:41,520 --> 06:28:42,320
here
10456
06:28:42,320 --> 06:28:44,400
this is what the model would predict
10457
06:28:44,400 --> 06:28:46,240
right so it predicts perfectly as you
10458
06:28:46,240 --> 06:28:47,920
see
10459
06:28:47,920 --> 06:28:51,440
you can also set a title here
10460
06:28:51,440 --> 06:28:52,320
set
10461
06:28:52,320 --> 06:28:54,160
title and often what you're interested
10462
06:28:54,160 --> 06:28:56,558
in from this model here is actually the
10463
06:28:56,558 --> 06:29:01,200
alpha and beta value so the alpha is a
10464
06:29:01,200 --> 06:29:04,160
intersection with a
10465
06:29:04,160 --> 06:29:07,200
intersection with a y axis here and the
10466
06:29:07,200 --> 06:29:09,920
beta is the slope of the line so let's
10467
06:29:09,920 --> 06:29:12,718
try to get that
10468
06:29:12,840 --> 06:29:16,718
alpha so the alpha is uh
10469
06:29:16,718 --> 06:29:18,320
given from the
10470
06:29:18,320 --> 06:29:23,638
linear regression model and it's called
10471
06:29:28,478 --> 06:29:29,520
here
10472
06:29:29,520 --> 06:29:30,558
this is
10473
06:29:30,558 --> 06:29:35,040
and beta is linear regressor model
10474
06:29:35,040 --> 06:29:36,000
here
10475
06:29:36,000 --> 06:29:37,520
and uh
10476
06:29:37,520 --> 06:29:38,958
i think it's
10477
06:29:38,958 --> 06:29:41,200
double here let's just try to execute
10478
06:29:41,200 --> 06:29:43,520
this and then see if we have the values
10479
06:29:43,520 --> 06:29:46,000
here alpha
10480
06:29:46,000 --> 06:29:48,000
we have a value here right you see a lot
10481
06:29:48,000 --> 06:29:50,478
of it's actually not 100 accurate
10482
06:29:50,478 --> 06:29:51,920
between zero
10483
06:29:51,920 --> 06:29:54,718
and beta should be close to one right it
10484
06:29:54,718 --> 06:29:57,360
is perfect it's not
10485
06:29:57,360 --> 06:30:00,798
100 accurate okay so in order we want to
10486
06:30:00,798 --> 06:30:02,320
make a title here we just put the alpha
10487
06:30:02,320 --> 06:30:04,160
and beta on there so let's just do that
10488
06:30:04,160 --> 06:30:06,000
so you could do that by putting a string
10489
06:30:06,000 --> 06:30:08,840
on here but let's just round it a bit
10490
06:30:08,840 --> 06:30:11,920
here and let's take five digits so on
10491
06:30:11,920 --> 06:30:13,120
here
10492
06:30:13,120 --> 06:30:14,638
convert to a string here and convert
10493
06:30:14,638 --> 06:30:15,920
this one to a string here because we
10494
06:30:15,920 --> 06:30:17,440
want it in the title
10495
06:30:17,440 --> 06:30:19,680
and how many digits do we take here five
10496
06:30:19,680 --> 06:30:20,718
as well
10497
06:30:20,718 --> 06:30:22,240
let's try that
10498
06:30:22,240 --> 06:30:24,400
and uh
10499
06:30:24,400 --> 06:30:28,000
then we have alpha here
10500
06:30:32,000 --> 06:30:35,200
alpha is not defined
10501
06:30:35,600 --> 06:30:37,360
oh alpha
10502
06:30:37,360 --> 06:30:40,558
alpha here's zero zero right and beta
10503
06:30:40,558 --> 06:30:43,520
is one now because we rounded it so
10504
06:30:43,520 --> 06:30:46,718
let's add it to here
10505
06:30:46,798 --> 06:30:51,558
should we make a formatted string alpha
10506
06:30:52,478 --> 06:30:53,440
and
10507
06:30:53,440 --> 06:30:56,718
comma beta
10508
06:30:58,478 --> 06:31:00,400
perfect so here we have it right so
10509
06:31:00,400 --> 06:31:02,000
alpha and beta
10510
06:31:02,000 --> 06:31:04,558
so this is basically what we need to
10511
06:31:04,558 --> 06:31:07,120
master in order to do the project right
10512
06:31:07,120 --> 06:31:08,878
so again it looks a bit scary but
10513
06:31:08,878 --> 06:31:11,360
actually it's not right so we have to
10514
06:31:11,360 --> 06:31:12,878
understand this is input data and this
10515
06:31:12,878 --> 06:31:14,718
is output data x and y and we need to
10516
06:31:14,718 --> 06:31:17,440
reshape it in this format here for the
10517
06:31:17,440 --> 06:31:19,600
model down here and then we fit it and
10518
06:31:19,600 --> 06:31:21,760
then we have the predictions based on
10519
06:31:21,760 --> 06:31:24,080
the input here and then we just take the
10520
06:31:24,080 --> 06:31:26,080
alpha and beta value and put it on the
10521
06:31:26,080 --> 06:31:28,478
scatter plot the scatter plot are the
10522
06:31:28,478 --> 06:31:30,320
actual points and the
10523
06:31:30,320 --> 06:31:32,000
plot here with the prediction is the
10524
06:31:32,000 --> 06:31:35,680
prediction line of the plot so this is
10525
06:31:35,680 --> 06:31:39,120
it basically it's amazing right so let's
10526
06:31:39,120 --> 06:31:40,958
get started with the project it's going
10527
06:31:40,958 --> 06:31:44,798
to be awesome so see you in a moment
10528
06:31:47,680 --> 06:31:48,638
so
10529
06:31:48,638 --> 06:31:50,400
are you ready for the project and
10530
06:31:50,400 --> 06:31:52,558
remember you don't need to recall all
10531
06:31:52,558 --> 06:31:54,718
the details from the previous lecture
10532
06:31:54,718 --> 06:31:56,798
this is an e-book if you didn't download
10533
06:31:56,798 --> 06:31:58,718
it already and please remember there's
10534
06:31:58,718 --> 06:32:00,400
an e-book there's a link below in the
10535
06:32:00,400 --> 06:32:02,558
description and then you can use that
10536
06:32:02,558 --> 06:32:05,200
ebook to look up how was the syntax and
10537
06:32:05,200 --> 06:32:07,360
so on because honestly especially if you
10538
06:32:07,360 --> 06:32:09,120
don't use it on a daily basis you will
10539
06:32:09,120 --> 06:32:10,958
never remember the syntax but that's
10540
06:32:10,958 --> 06:32:12,878
okay and then you look it up and in the
10541
06:32:12,878 --> 06:32:14,638
e-book it's everything you need to do
10542
06:32:14,638 --> 06:32:16,400
this project so
10543
06:32:16,400 --> 06:32:18,558
project machine learning our first
10544
06:32:18,558 --> 06:32:21,360
machine learning project that's exciting
10545
06:32:21,360 --> 06:32:23,600
so the goal is to implement a linear
10546
06:32:23,600 --> 06:32:25,520
regression model as we were introduced
10547
06:32:25,520 --> 06:32:27,600
in the last one
10548
06:32:27,600 --> 06:32:30,400
so let's look what we have to do well
10549
06:32:30,400 --> 06:32:32,400
it's described in steps down here so it
10550
06:32:32,400 --> 06:32:34,958
should be kind of straightforward but
10551
06:32:34,958 --> 06:32:36,798
you know always
10552
06:32:36,798 --> 06:32:38,958
don't underestimate how difficult it is
10553
06:32:38,958 --> 06:32:41,200
when you do it yourself so what you want
10554
06:32:41,200 --> 06:32:43,920
to do is import numpy as np and import
10555
06:32:43,920 --> 06:32:47,040
csv then you need to import the sklearn
10556
06:32:47,040 --> 06:32:49,120
with a linear regression here this long
10557
06:32:49,120 --> 06:32:51,040
line here and then you want to import
10558
06:32:51,040 --> 06:32:53,600
the matplotlib pi plot as plt and with
10559
06:32:53,600 --> 06:32:55,840
matplot inline okay that was a lot of
10560
06:32:55,840 --> 06:32:58,320
things right and then we read the csv
10561
06:32:58,320 --> 06:33:00,160
file of the data we want to work with
10562
06:33:00,160 --> 06:33:01,760
and we're going to work with the files
10563
06:33:01,760 --> 06:33:03,600
cars again here with the list of
10564
06:33:03,600 --> 06:33:05,680
dictionaries right so you need to import
10565
06:33:05,680 --> 06:33:07,920
it as a list of dictionaries
10566
06:33:07,920 --> 06:33:10,160
then we use a list comprehension to get
10567
06:33:10,160 --> 06:33:12,638
the horsepower and torque from the csv
10568
06:33:12,638 --> 06:33:14,958
data right remember how we did that we
10569
06:33:14,958 --> 06:33:16,958
do it again because practice makes you
10570
06:33:16,958 --> 06:33:18,878
better
10571
06:33:18,878 --> 06:33:21,040
and then we create a list as a numpy
10572
06:33:21,040 --> 06:33:22,400
arrays of
10573
06:33:22,400 --> 06:33:25,040
and reshape them right
10574
06:33:25,040 --> 06:33:27,760
so the data we have here we need to
10575
06:33:27,760 --> 06:33:30,558
transfer that to numpy arrays and then
10576
06:33:30,558 --> 06:33:33,360
we need to reshape it okay
10577
06:33:33,360 --> 06:33:35,520
then we create the linear regression
10578
06:33:35,520 --> 06:33:38,638
model and then we fit it and then we
10579
06:33:38,638 --> 06:33:41,840
predict right
10580
06:33:43,520 --> 06:33:45,760
perfect and then we create a scatter
10581
06:33:45,760 --> 06:33:47,760
plot with the points horsepower and
10582
06:33:47,760 --> 06:33:49,840
torque write the data points from here
10583
06:33:49,840 --> 06:33:52,160
and then we create the line read with
10584
06:33:52,160 --> 06:33:54,080
the prediction right and then we see how
10585
06:33:54,080 --> 06:33:56,320
the prediction looks like and so forth
10586
06:33:56,320 --> 06:33:58,638
so this project will also make it more
10587
06:33:58,638 --> 06:34:01,280
understandable for you what this linear
10588
06:34:01,280 --> 06:34:03,600
regression model can do for you
10589
06:34:03,600 --> 06:34:05,680
so are you ready i hope so because this
10590
06:34:05,680 --> 06:34:07,920
is really exciting and if you find it
10591
06:34:07,920 --> 06:34:09,360
too difficult please let me know also in
10592
06:34:09,360 --> 06:34:11,200
the comments i'd love to get some
10593
06:34:11,200 --> 06:34:13,520
feedback from you guys so let's get
10594
06:34:13,520 --> 06:34:16,240
started with this one see in a moment or
10595
06:34:16,240 --> 06:34:17,760
first work
10596
06:34:17,760 --> 06:34:19,680
then if you get stuck
10597
06:34:19,680 --> 06:34:21,520
see the next one then redo it yourself
10598
06:34:21,520 --> 06:34:24,160
it's highly highly
10599
06:34:24,160 --> 06:34:25,920
encourage that you try to do it yourself
10600
06:34:25,920 --> 06:34:27,520
and even though you don't get it try
10601
06:34:27,520 --> 06:34:29,520
again and try again until you kind of
10602
06:34:29,520 --> 06:34:31,120
get it
10603
06:34:31,120 --> 06:34:35,320
well see you in the next one
10604
06:34:37,280 --> 06:34:39,600
are you ready for this project i hope so
10605
06:34:39,600 --> 06:34:42,320
i hope you managed really far if not let
10606
06:34:42,320 --> 06:34:43,840
me know in the comments maybe there's
10607
06:34:43,840 --> 06:34:45,680
something you find a bit difficult to
10608
06:34:45,680 --> 06:34:47,760
understand don't worry we all been there
10609
06:34:47,760 --> 06:34:49,760
so it's not easy the first time you do
10610
06:34:49,760 --> 06:34:50,478
it
10611
06:34:50,478 --> 06:34:52,638
and let's try to walk through how i
10612
06:34:52,638 --> 06:34:55,120
would try to solve this so basically
10613
06:34:55,120 --> 06:34:57,120
what we need to do is to follow the
10614
06:34:57,120 --> 06:34:59,520
steps all the way down here one by one
10615
06:34:59,520 --> 06:35:01,520
so let's try to do that together
10616
06:35:01,520 --> 06:35:03,600
so the first step here you see we need
10617
06:35:03,600 --> 06:35:06,400
to import numpy as np and import csv
10618
06:35:06,400 --> 06:35:08,000
let's do that
10619
06:35:08,000 --> 06:35:09,280
in
10620
06:35:09,280 --> 06:35:12,558
import numpy snp
10621
06:35:12,558 --> 06:35:15,280
import csv
10622
06:35:15,280 --> 06:35:17,280
that's the first one here then we need
10623
06:35:17,280 --> 06:35:20,478
the sksk learn here and the linear model
10624
06:35:20,478 --> 06:35:23,440
here we need the linear regression
10625
06:35:23,440 --> 06:35:26,878
that's our model right sk learn
10626
06:35:26,878 --> 06:35:29,120
learn
10627
06:35:30,000 --> 06:35:31,440
actually that's missing an
10628
06:35:31,440 --> 06:35:33,840
r there i'll correct that for you
10629
06:35:33,840 --> 06:35:37,280
uh linear model
10630
06:35:38,558 --> 06:35:41,840
and uh we need uh import
10631
06:35:41,840 --> 06:35:44,000
linear regression
10632
06:35:44,000 --> 06:35:44,840
it
10633
06:35:44,840 --> 06:35:47,520
doesn't doesn't recognize it or that
10634
06:35:47,520 --> 06:35:49,040
because it said import here it should be
10635
06:35:49,040 --> 06:35:51,760
from here and import linear regression
10636
06:35:51,760 --> 06:35:53,440
perfect
10637
06:35:53,440 --> 06:35:54,478
and then
10638
06:35:54,478 --> 06:35:58,000
we need the matplotlib pi plot as plt
10639
06:35:58,000 --> 06:35:59,440
import
10640
06:35:59,440 --> 06:36:00,320
mat
10641
06:36:00,320 --> 06:36:01,520
plot lib
10642
06:36:01,520 --> 06:36:05,440
pi plot as plt and then we need the
10643
06:36:05,440 --> 06:36:06,240
matte
10644
06:36:06,240 --> 06:36:07,840
plot lip
10645
06:36:07,840 --> 06:36:09,840
inline right
10646
06:36:09,840 --> 06:36:13,280
and that's basically the library
10647
06:36:13,280 --> 06:36:14,878
so we need that's a lot of things right
10648
06:36:14,878 --> 06:36:16,718
now it looks pretty professional right
10649
06:36:16,718 --> 06:36:20,718
numpy csv sklearn mat.lip and we have
10650
06:36:20,718 --> 06:36:22,160
this line here for
10651
06:36:22,160 --> 06:36:23,360
telling
10652
06:36:23,360 --> 06:36:25,360
jupiter notebook how to
10653
06:36:25,360 --> 06:36:26,478
show it
10654
06:36:26,478 --> 06:36:28,638
then we're in this line areas we need to
10655
06:36:28,638 --> 06:36:30,400
read the csv file
10656
06:36:30,400 --> 06:36:33,840
this one here files cards here with a
10657
06:36:33,840 --> 06:36:36,240
list of dictionaries
10658
06:36:36,240 --> 06:36:38,400
you remember that syntax don't worry if
10659
06:36:38,400 --> 06:36:39,840
you don't you can always look up in the
10660
06:36:39,840 --> 06:36:41,600
ebook i would do the same
10661
06:36:41,600 --> 06:36:44,400
so how is it help me here with
10662
06:36:44,400 --> 06:36:47,200
open so we open the file pointer
10663
06:36:47,200 --> 06:36:48,240
files
10664
06:36:48,240 --> 06:36:50,000
cars
10665
06:36:50,000 --> 06:36:51,440
then we have
10666
06:36:51,440 --> 06:36:53,120
read mode
10667
06:36:53,120 --> 06:36:55,600
as f and then we need the colon there
10668
06:36:55,600 --> 06:36:56,558
right
10669
06:36:56,558 --> 06:36:58,958
then we have the csv reader
10670
06:36:58,958 --> 06:37:01,360
and we take the csv here and we do the
10671
06:37:01,360 --> 06:37:02,478
dict
10672
06:37:02,478 --> 06:37:04,400
reader here and it takes just a file
10673
06:37:04,400 --> 06:37:08,240
pointer and then we make the cars here
10674
06:37:08,240 --> 06:37:10,160
cars list we have called it cars
10675
06:37:10,160 --> 06:37:12,080
previously so just keep that syntax as
10676
06:37:12,080 --> 06:37:14,958
well and uh what we do here is take the
10677
06:37:14,958 --> 06:37:18,160
list or convert the csv reader to a list
10678
06:37:18,160 --> 06:37:20,240
which converts it to a list so let's
10679
06:37:20,240 --> 06:37:22,400
actually just try to execute that and
10680
06:37:22,400 --> 06:37:24,558
look at the cars now so let's just look
10681
06:37:24,558 --> 06:37:26,478
at the first one here
10682
06:37:26,478 --> 06:37:28,638
first one here and we remember the first
10683
06:37:28,638 --> 06:37:31,440
one is an audi and it has horsepower
10684
06:37:31,440 --> 06:37:34,400
here and torque here right
10685
06:37:34,400 --> 06:37:37,280
perfect so far so good
10686
06:37:37,280 --> 06:37:39,440
so then it says use a list comprehension
10687
06:37:39,440 --> 06:37:41,760
to get horsepower and torque from the
10688
06:37:41,760 --> 06:37:43,680
csv data right
10689
06:37:43,680 --> 06:37:44,638
and
10690
06:37:44,638 --> 06:37:47,280
basically there's a catch right remember
10691
06:37:47,280 --> 06:37:49,920
remember when we look at the horsepower
10692
06:37:49,920 --> 06:37:52,878
the horsepower and torque here they are
10693
06:37:52,878 --> 06:37:54,718
strings right they have the quotes here
10694
06:37:54,718 --> 06:37:56,558
so they are actually represented as
10695
06:37:56,558 --> 06:37:58,718
strings so we need to convert that as
10696
06:37:58,718 --> 06:38:00,958
well let's also do that in this process
10697
06:38:00,958 --> 06:38:03,360
here right so horse
10698
06:38:03,360 --> 06:38:06,000
power
10699
06:38:06,000 --> 06:38:07,920
we have a list comparison here so how do
10700
06:38:07,920 --> 06:38:11,120
we get it out well cars or car
10701
06:38:11,120 --> 06:38:14,718
and we take horsepower
10702
06:38:14,718 --> 06:38:16,080
and we take
10703
06:38:16,080 --> 06:38:19,440
four car in cars right
10704
06:38:19,440 --> 06:38:21,200
so this is basically what we need right
10705
06:38:21,200 --> 06:38:23,600
this is a horsepower so if you executed
10706
06:38:23,600 --> 06:38:25,680
this one here you will have a
10707
06:38:25,680 --> 06:38:28,240
list of it but as i told you these are
10708
06:38:28,240 --> 06:38:29,840
strings right so how can you convert
10709
06:38:29,840 --> 06:38:33,040
that well you take an int on that
10710
06:38:33,040 --> 06:38:35,120
here
10711
06:38:35,120 --> 06:38:37,360
execute that and when you see here then
10712
06:38:37,360 --> 06:38:39,440
the type is int which is what we want
10713
06:38:39,440 --> 06:38:40,638
right
10714
06:38:40,638 --> 06:38:42,240
perfect
10715
06:38:42,240 --> 06:38:45,840
and we need to do that for torque
10716
06:38:45,840 --> 06:38:49,440
torque as well so now we need the syntax
10717
06:38:49,440 --> 06:38:50,478
int
10718
06:38:50,478 --> 06:38:52,638
car
10719
06:38:52,638 --> 06:38:55,120
torque
10720
06:38:55,360 --> 06:38:56,878
for
10721
06:38:56,878 --> 06:39:00,160
car in cars right so this is the data we
10722
06:39:00,160 --> 06:39:02,958
are going to work with right and uh just
10723
06:39:02,958 --> 06:39:04,878
remember how much data is there
10724
06:39:04,878 --> 06:39:07,798
horsepower they're like
10725
06:39:07,798 --> 06:39:11,520
5076 right the same with torque that
10726
06:39:11,520 --> 06:39:13,760
should be right so what we're going to
10727
06:39:13,760 --> 06:39:15,600
try to do in this model here is try to
10728
06:39:15,600 --> 06:39:17,280
see that
10729
06:39:17,280 --> 06:39:19,280
uh how to fit the
10730
06:39:19,280 --> 06:39:22,400
dependency between horsepower and torque
10731
06:39:22,400 --> 06:39:24,558
so what you can predict now
10732
06:39:24,558 --> 06:39:26,798
or what's supposed to predict is giving
10733
06:39:26,798 --> 06:39:29,520
a horsepower what is the torque of the
10734
06:39:29,520 --> 06:39:31,600
car right
10735
06:39:31,600 --> 06:39:32,798
interesting
10736
06:39:32,798 --> 06:39:33,920
good
10737
06:39:33,920 --> 06:39:35,040
perfect
10738
06:39:35,040 --> 06:39:37,200
so that was actually
10739
06:39:37,200 --> 06:39:39,040
this step here use a list comprehension
10740
06:39:39,040 --> 06:39:40,958
to get horsepower and torque from the
10741
06:39:40,958 --> 06:39:42,558
csv data
10742
06:39:42,558 --> 06:39:45,360
then we need to create a list as a numpy
10743
06:39:45,360 --> 06:39:47,760
arrays and reshape them remember and
10744
06:39:47,760 --> 06:39:49,360
we're going to use the same syntax here
10745
06:39:49,360 --> 06:39:52,240
so we're going to use x here and
10746
06:39:52,240 --> 06:39:53,280
np
10747
06:39:53,280 --> 06:39:55,440
array
10748
06:39:55,440 --> 06:39:57,120
array
10749
06:39:57,120 --> 06:40:00,240
here and we take the horse power and
10750
06:40:00,240 --> 06:40:02,558
then we reshape it and remember this
10751
06:40:02,558 --> 06:40:04,478
syntax there minus one it's negative
10752
06:40:04,478 --> 06:40:07,680
indexing and one here and then we take y
10753
06:40:07,680 --> 06:40:09,840
here np array
10754
06:40:09,840 --> 06:40:10,840
and we take
10755
06:40:10,840 --> 06:40:14,160
torque and reshape
10756
06:40:14,160 --> 06:40:16,400
minus one comma one here so now we have
10757
06:40:16,400 --> 06:40:17,440
the data
10758
06:40:17,440 --> 06:40:18,558
and
10759
06:40:18,558 --> 06:40:19,440
yeah
10760
06:40:19,440 --> 06:40:21,840
perfect
10761
06:40:21,840 --> 06:40:24,240
so that was it
10762
06:40:24,240 --> 06:40:26,000
and then we need to create a linear
10763
06:40:26,000 --> 06:40:27,600
regression model
10764
06:40:27,600 --> 06:40:30,240
let's do that
10765
06:40:30,240 --> 06:40:31,600
linear
10766
06:40:31,600 --> 06:40:34,600
regressor
10767
06:40:35,120 --> 06:40:37,200
and that's just a linear regression
10768
06:40:37,200 --> 06:40:38,840
model here right
10769
06:40:38,840 --> 06:40:41,440
perfect and
10770
06:40:41,440 --> 06:40:43,120
then we need to
10771
06:40:43,120 --> 06:40:44,638
fit
10772
06:40:44,638 --> 06:40:46,878
with the two reshaped lists right
10773
06:40:46,878 --> 06:40:48,080
perfect
10774
06:40:48,080 --> 06:40:51,360
linear regressor fit
10775
06:40:51,360 --> 06:40:53,840
x comma y so this is where the magic is
10776
06:40:53,840 --> 06:40:55,120
done right
10777
06:40:55,120 --> 06:40:57,520
and then we need to have a prediction
10778
06:40:57,520 --> 06:41:00,798
here predict perfect
10779
06:41:00,798 --> 06:41:04,160
and we predict with x
10780
06:41:04,160 --> 06:41:05,520
so y
10781
06:41:05,520 --> 06:41:07,040
print
10782
06:41:07,040 --> 06:41:08,958
is linear regressor
10783
06:41:08,958 --> 06:41:11,680
and we do predict here
10784
06:41:11,680 --> 06:41:13,280
and we do it on the x data because
10785
06:41:13,280 --> 06:41:14,558
that's the horsepower we're going to
10786
06:41:14,558 --> 06:41:15,600
predict
10787
06:41:15,600 --> 06:41:17,200
the torque
10788
06:41:17,200 --> 06:41:19,040
of each of them right so this is where
10789
06:41:19,040 --> 06:41:20,718
the magic is done perfect it's already
10790
06:41:20,718 --> 06:41:22,478
done awesome right
10791
06:41:22,478 --> 06:41:25,280
so now for the final
10792
06:41:25,280 --> 06:41:27,600
step or final two steps create a scatter
10793
06:41:27,600 --> 06:41:29,520
plot with all the points horsepower and
10794
06:41:29,520 --> 06:41:30,718
torque
10795
06:41:30,718 --> 06:41:32,558
awesome
10796
06:41:32,558 --> 06:41:33,520
so
10797
06:41:33,520 --> 06:41:37,120
thick axis plt sub
10798
06:41:37,120 --> 06:41:39,440
plots here perfect
10799
06:41:39,440 --> 06:41:42,160
and now we need an axis and scatter
10800
06:41:42,160 --> 06:41:43,520
plotted
10801
06:41:43,520 --> 06:41:46,400
x and y so this one we actually seen
10802
06:41:46,400 --> 06:41:48,400
before right so this is all the points
10803
06:41:48,400 --> 06:41:50,400
that we have here right
10804
06:41:50,400 --> 06:41:51,760
pointed over here
10805
06:41:51,760 --> 06:41:52,558
and
10806
06:41:52,558 --> 06:41:54,638
we already kind of saw that there is
10807
06:41:54,638 --> 06:41:57,120
some kind of connection here right
10808
06:41:57,120 --> 06:42:00,080
and we will want this model to predict
10809
06:42:00,080 --> 06:42:01,200
that
10810
06:42:01,200 --> 06:42:05,120
and let's plot that as well plot
10811
06:42:05,120 --> 06:42:06,958
x y print
10812
06:42:06,958 --> 06:42:09,600
here and we take color
10813
06:42:09,600 --> 06:42:10,878
red
10814
06:42:10,878 --> 06:42:13,200
so this is the line it's going to
10815
06:42:13,200 --> 06:42:14,878
predict with right
10816
06:42:14,878 --> 06:42:17,840
so given any horsepower for instance 500
10817
06:42:17,840 --> 06:42:20,798
this is a prediction it would make
10818
06:42:20,798 --> 06:42:23,200
so we can actually get the
10819
06:42:23,200 --> 06:42:25,440
get the coefficient of it it doesn't
10820
06:42:25,440 --> 06:42:27,520
require that in this project but we did
10821
06:42:27,520 --> 06:42:29,600
that in the other one right yes it
10822
06:42:29,600 --> 06:42:31,840
doesn't require it but let's do that
10823
06:42:31,840 --> 06:42:34,000
alpha
10824
06:42:34,000 --> 06:42:37,360
how was it it was a linear regressor
10825
06:42:37,360 --> 06:42:38,878
interceptor
10826
06:42:38,878 --> 06:42:40,478
0 right
10827
06:42:40,478 --> 06:42:41,520
and
10828
06:42:41,520 --> 06:42:43,440
we just want it
10829
06:42:43,440 --> 06:42:45,200
immediately as a string to put it there
10830
06:42:45,200 --> 06:42:48,240
and we used round in the last one
10831
06:42:48,240 --> 06:42:50,958
and we take five and
10832
06:42:50,958 --> 06:42:52,478
end here and here
10833
06:42:52,478 --> 06:42:54,798
and then the beta
10834
06:42:54,798 --> 06:42:56,958
string round
10835
06:42:56,958 --> 06:42:58,558
linear regressor
10836
06:42:58,558 --> 06:43:01,120
coefficient
10837
06:43:01,120 --> 06:43:02,798
zero
10838
06:43:02,798 --> 06:43:05,440
zero right this will sit
10839
06:43:05,440 --> 06:43:09,280
and uh then we can add the title here ax
10840
06:43:09,280 --> 06:43:10,400
set
10841
06:43:10,400 --> 06:43:12,160
title
10842
06:43:12,160 --> 06:43:16,080
let me use the formatted string alpha
10843
06:43:16,080 --> 06:43:18,558
let's just have a colon here oh
10844
06:43:18,558 --> 06:43:19,600
here
10845
06:43:19,600 --> 06:43:22,080
alpha
10846
06:43:22,718 --> 06:43:24,690
beta
10847
06:43:24,690 --> 06:43:27,120
[Music]
10848
06:43:27,120 --> 06:43:28,478
then we can actually see here so
10849
06:43:28,478 --> 06:43:30,400
actually the beta is exactly one that's
10850
06:43:30,400 --> 06:43:32,160
kind of interesting right
10851
06:43:32,160 --> 06:43:35,040
that means basically that uh
10852
06:43:35,040 --> 06:43:37,360
it actually looks like that too right so
10853
06:43:37,360 --> 06:43:40,000
for 100 it's about 100 and for 600 is
10854
06:43:40,000 --> 06:43:42,320
about 600 right so the beta is one and
10855
06:43:42,320 --> 06:43:44,558
the interception is like around six so
10856
06:43:44,558 --> 06:43:47,600
it's like the torque is actually six
10857
06:43:47,600 --> 06:43:51,120
on average six above right so with 100
10858
06:43:51,120 --> 06:43:55,680
it's around 106 and with 600 around 606
10859
06:43:55,680 --> 06:43:57,760
and so forth here so this is a line it
10860
06:43:57,760 --> 06:43:59,840
would predict along right and you see
10861
06:43:59,840 --> 06:44:02,080
that's pretty nice right uh
10862
06:44:02,080 --> 06:44:03,920
with data like this there's always
10863
06:44:03,920 --> 06:44:06,160
points scattered all over right but this
10864
06:44:06,160 --> 06:44:09,600
is the best fit you can find to predict
10865
06:44:09,600 --> 06:44:12,160
so given anything
10866
06:44:12,160 --> 06:44:14,320
any horsepower this is the prediction of
10867
06:44:14,320 --> 06:44:16,080
the torque it would make
10868
06:44:16,080 --> 06:44:18,558
wow that's amazing you did your first
10869
06:44:18,558 --> 06:44:22,400
machine learning model and this one is
10870
06:44:22,400 --> 06:44:25,920
quite simple one and uh but it uses the
10871
06:44:25,920 --> 06:44:28,958
principles of machine learning in order
10872
06:44:28,958 --> 06:44:31,440
to do that prediction right before we
10873
06:44:31,440 --> 06:44:33,040
make the capstone project where we
10874
06:44:33,040 --> 06:44:35,520
actually built our own machine learning
10875
06:44:35,520 --> 06:44:38,080
model from scratch the reinforcement
10876
06:44:38,080 --> 06:44:39,920
model i love that one because in this
10877
06:44:39,920 --> 06:44:42,160
one here we kind of use a library
10878
06:44:42,160 --> 06:44:45,200
already here but in the capstone project
10879
06:44:45,200 --> 06:44:47,440
we're gonna use a
10880
06:44:47,440 --> 06:44:49,440
we're not gonna use any libraries we are
10881
06:44:49,440 --> 06:44:52,478
gonna build it from scratch wow that's
10882
06:44:52,478 --> 06:44:54,240
amazing so we built our own model from
10883
06:44:54,240 --> 06:44:57,200
scratch in this reinforcement model and
10884
06:44:57,200 --> 06:44:58,958
the difference between a reinforcement
10885
06:44:58,958 --> 06:45:00,958
model and this model here is actually
10886
06:45:00,958 --> 06:45:03,600
the reinforcement model actually
10887
06:45:03,600 --> 06:45:04,958
learns
10888
06:45:04,958 --> 06:45:07,680
along the way and keeps continues
10889
06:45:07,680 --> 06:45:09,520
learning along the way it's amazing it's
10890
06:45:09,520 --> 06:45:10,320
like
10891
06:45:10,320 --> 06:45:11,280
uh
10892
06:45:11,280 --> 06:45:13,280
it's like it gets feedback for every
10893
06:45:13,280 --> 06:45:14,958
step it does so it has immediate
10894
06:45:14,958 --> 06:45:16,478
feedback was this a good decision or a
10895
06:45:16,478 --> 06:45:18,400
bad decision right it's going to be
10896
06:45:18,400 --> 06:45:20,320
amazing but before that the capstone
10897
06:45:20,320 --> 06:45:21,840
project we're also going to use learn a
10898
06:45:21,840 --> 06:45:24,000
bit about pandas so in the next lecture
10899
06:45:24,000 --> 06:45:26,558
we're going to learn about pandas and
10900
06:45:26,558 --> 06:45:28,240
we're going to use pandas to represent
10901
06:45:28,240 --> 06:45:31,360
data and export it to excel sheets it's
10902
06:45:31,360 --> 06:45:33,680
it's really fun as well so so i hope
10903
06:45:33,680 --> 06:45:36,000
you're excited i am so see you in the
10904
06:45:36,000 --> 06:45:38,558
next one
10905
06:45:41,200 --> 06:45:42,718
in this lesson we're gonna learn about
10906
06:45:42,718 --> 06:45:46,478
pandas and pandas is an amazing tool for
10907
06:45:46,478 --> 06:45:49,040
working with data which is similar to
10908
06:45:49,040 --> 06:45:50,958
excel sheets and you can do similar
10909
06:45:50,958 --> 06:45:52,240
things with it
10910
06:45:52,240 --> 06:45:54,080
for me it's just easier because you do
10911
06:45:54,080 --> 06:45:57,040
it from python so in this lesson here
10912
06:45:57,040 --> 06:45:58,558
we're going to learn how to read data
10913
06:45:58,558 --> 06:46:01,520
from csv files into a pandas data
10914
06:46:01,520 --> 06:46:04,000
structure the data frame and we're going
10915
06:46:04,000 --> 06:46:05,760
to work a bit with the data inside there
10916
06:46:05,760 --> 06:46:07,120
we're going to group it in different
10917
06:46:07,120 --> 06:46:09,120
ways and then we're going to export it
10918
06:46:09,120 --> 06:46:12,000
to excel and create amazing charts of
10919
06:46:12,000 --> 06:46:14,718
that data so in the project that's what
10920
06:46:14,718 --> 06:46:16,000
we're going gonna do we're gonna read
10921
06:46:16,000 --> 06:46:19,280
data from csv files and work around with
10922
06:46:19,280 --> 06:46:21,760
it and export it to excel and create
10923
06:46:21,760 --> 06:46:25,040
charts in it so this is a subset of what
10924
06:46:25,040 --> 06:46:27,520
pandas can do but i want to demonstrate
10925
06:46:27,520 --> 06:46:30,400
that to you so you do have some advanced
10926
06:46:30,400 --> 06:46:32,478
thing where you can automate some of the
10927
06:46:32,478 --> 06:46:34,320
work you actually do at work
10928
06:46:34,320 --> 06:46:36,240
or i don't know if you do work at work
10929
06:46:36,240 --> 06:46:38,160
but i do and
10930
06:46:38,160 --> 06:46:40,638
then you can automate generating amazing
10931
06:46:40,638 --> 06:46:43,120
excel sheets so are you ready
10932
06:46:43,120 --> 06:46:44,400
let's get started
10933
06:46:44,400 --> 06:46:47,120
so inside here we have the title of our
10934
06:46:47,120 --> 06:46:49,520
lesson to be panned as and
10935
06:46:49,520 --> 06:46:52,080
that's because pandas is so extremely
10936
06:46:52,080 --> 06:46:54,718
powerful so the goal of this lesson here
10937
06:46:54,718 --> 06:46:58,240
is to learn basics of pandas to read csv
10938
06:46:58,240 --> 06:47:00,878
files from pandas to explore the data
10939
06:47:00,878 --> 06:47:02,638
frame and data frame is the data
10940
06:47:02,638 --> 06:47:04,718
structure the main data structure of the
10941
06:47:04,718 --> 06:47:07,440
pandas library and then we're going to
10942
06:47:07,440 --> 06:47:10,958
learn about group by and group by is
10943
06:47:10,958 --> 06:47:13,360
kind of how you if you have similar data
10944
06:47:13,360 --> 06:47:14,718
inside there it's like group by and
10945
06:47:14,718 --> 06:47:16,718
excel actually and then we're going to
10946
06:47:16,718 --> 06:47:19,440
use date time and group by and
10947
06:47:19,440 --> 06:47:21,840
because you can group things in time
10948
06:47:21,840 --> 06:47:24,400
period based on the date so we group the
10949
06:47:24,400 --> 06:47:26,878
data for month for instance group it in
10950
06:47:26,878 --> 06:47:29,360
month and then finally we're going to
10951
06:47:29,360 --> 06:47:31,040
show you how to export it to excel and
10952
06:47:31,040 --> 06:47:33,440
actually create a chart with excel and i
10953
06:47:33,440 --> 06:47:35,360
have a link here because
10954
06:47:35,360 --> 06:47:37,520
when it comes to syntax for
10955
06:47:37,520 --> 06:47:39,920
creating these charts in excel here you
10956
06:47:39,920 --> 06:47:42,160
will see down here well we need to
10957
06:47:42,160 --> 06:47:44,558
master a few things in order to do it
10958
06:47:44,558 --> 06:47:47,440
and basically it's not difficult and we
10959
06:47:47,440 --> 06:47:49,200
will do it in the easy way here like
10960
06:47:49,200 --> 06:47:51,600
this one just writing it out and but
10961
06:47:51,600 --> 06:47:54,638
then you can insert charts like this one
10962
06:47:54,638 --> 06:47:56,400
we're going to do here and on the page
10963
06:47:56,400 --> 06:47:58,558
here you can find multiple examples of
10964
06:47:58,558 --> 06:48:00,558
how to do it and honestly you would
10965
06:48:00,558 --> 06:48:02,478
never remember these by hard you just
10966
06:48:02,478 --> 06:48:04,240
look them up if i say i want a chart
10967
06:48:04,240 --> 06:48:06,320
like this one how do i do that so that's
10968
06:48:06,320 --> 06:48:08,478
what we're going to do in this one
10969
06:48:08,478 --> 06:48:11,200
good are you ready i hope so because now
10970
06:48:11,200 --> 06:48:13,760
we're gonna import our pandas library
10971
06:48:13,760 --> 06:48:16,320
let's do that import
10972
06:48:16,320 --> 06:48:17,840
pandas
10973
06:48:17,840 --> 06:48:20,080
as pd so
10974
06:48:20,080 --> 06:48:22,958
we did it our first pandas import
10975
06:48:22,958 --> 06:48:24,240
amazing right
10976
06:48:24,240 --> 06:48:27,200
so what is pandas
10977
06:48:27,200 --> 06:48:29,040
well
10978
06:48:29,040 --> 06:48:32,080
remember the numpy library right it was
10979
06:48:32,080 --> 06:48:34,798
more like a list of
10980
06:48:34,798 --> 06:48:38,240
a list with some restrictions the pandas
10981
06:48:38,240 --> 06:48:41,520
library is more like a dictionary with
10982
06:48:41,520 --> 06:48:44,320
restrictions i'll see why in a moment so
10983
06:48:44,320 --> 06:48:47,360
let's make a dictionary here
10984
06:48:47,360 --> 06:48:49,200
a dictionary here
10985
06:48:49,200 --> 06:48:51,520
let's just call it d for short here and
10986
06:48:51,520 --> 06:48:53,520
we have the brackets here so
10987
06:48:53,520 --> 06:48:56,638
imagine here we have a scenario where we
10988
06:48:56,638 --> 06:48:57,680
actually
10989
06:48:57,680 --> 06:48:59,840
register cars and the speed they're
10990
06:48:59,840 --> 06:49:01,600
having right so let's just make a list
10991
06:49:01,600 --> 06:49:04,240
here to have a car so this is our key
10992
06:49:04,240 --> 06:49:05,360
the car
10993
06:49:05,360 --> 06:49:06,958
or should it be cars because we have
10994
06:49:06,958 --> 06:49:10,240
multiple and then we have some
10995
06:49:10,240 --> 06:49:13,200
a list of cars here okay so for this
10996
06:49:13,200 --> 06:49:16,160
case here we have a
10997
06:49:16,840 --> 06:49:20,798
porsche we have
10998
06:49:20,958 --> 06:49:23,600
another portion
10999
06:49:23,600 --> 06:49:26,400
and then we have a
11000
06:49:26,400 --> 06:49:29,040
ferrari
11001
06:49:29,200 --> 06:49:32,400
and let's just take another ferrari
11002
06:49:32,400 --> 06:49:33,440
okay
11003
06:49:33,440 --> 06:49:35,680
so we have four cars in this case here
11004
06:49:35,680 --> 06:49:37,520
and let's just say they were registered
11005
06:49:37,520 --> 06:49:39,200
with speed
11006
06:49:39,200 --> 06:49:41,280
with a speed and it doesn't really
11007
06:49:41,280 --> 06:49:43,040
matter what the speeds were
11008
06:49:43,040 --> 06:49:44,440
200
11009
06:49:44,440 --> 06:49:47,680
215 this is kilometers per hour so not
11010
06:49:47,680 --> 06:49:49,120
miles per hours
11011
06:49:49,120 --> 06:49:52,878
and uh ferrari here was crazy 305 and
11012
06:49:52,878 --> 06:49:55,280
195 right
11013
06:49:55,280 --> 06:49:56,080
so
11014
06:49:56,080 --> 06:49:58,160
what we have here is a dictionary as you
11015
06:49:58,160 --> 06:50:02,160
see here and for
11016
06:50:02,240 --> 06:50:03,360
for each
11017
06:50:03,360 --> 06:50:05,200
car we registered we registered the
11018
06:50:05,200 --> 06:50:07,440
speed also so these are
11019
06:50:07,440 --> 06:50:09,920
depending on each other so there's a key
11020
06:50:09,920 --> 06:50:12,080
thing here in this dictionary we have
11021
06:50:12,080 --> 06:50:14,160
when we convert it to a pandas data
11022
06:50:14,160 --> 06:50:16,240
frame we need to have that the list
11023
06:50:16,240 --> 06:50:19,200
representing each key value
11024
06:50:19,200 --> 06:50:21,600
need to be the same length so again we
11025
06:50:21,600 --> 06:50:23,520
have a restriction on it another
11026
06:50:23,520 --> 06:50:25,840
restriction is just like numpy arrays we
11027
06:50:25,840 --> 06:50:28,638
need the data type of the list to be the
11028
06:50:28,638 --> 06:50:30,798
same all the way down there or it will
11029
06:50:30,798 --> 06:50:34,400
generalize it to the same one okay
11030
06:50:34,400 --> 06:50:36,558
so let's do our data frame so let's just
11031
06:50:36,558 --> 06:50:39,680
call it data frame here and pd
11032
06:50:39,680 --> 06:50:41,120
data frame
11033
06:50:41,120 --> 06:50:43,360
here and just takes the dictionary here
11034
06:50:43,360 --> 06:50:44,400
boom
11035
06:50:44,400 --> 06:50:46,240
and then we can actually have print out
11036
06:50:46,240 --> 06:50:48,160
the dictionary here right so you see
11037
06:50:48,160 --> 06:50:49,120
here
11038
06:50:49,120 --> 06:50:51,520
this is actually similar right
11039
06:50:51,520 --> 06:50:53,520
to the data up here and you see why we
11040
06:50:53,520 --> 06:50:55,120
need the same number of entries it's
11041
06:50:55,120 --> 06:50:57,600
because well porsche 200 right porsche
11042
06:50:57,600 --> 06:51:03,400
200 porsche 215 ferrari 305 and ferrari
11043
06:51:03,400 --> 06:51:06,320
195 here right so
11044
06:51:06,320 --> 06:51:08,000
as you also see it kind of looks like a
11045
06:51:08,000 --> 06:51:09,520
spreadsheet as well right so you have a
11046
06:51:09,520 --> 06:51:11,040
column names here
11047
06:51:11,040 --> 06:51:14,000
and then you have the row numbering here
11048
06:51:14,000 --> 06:51:15,040
right
11049
06:51:15,040 --> 06:51:16,478
perfect
11050
06:51:16,478 --> 06:51:18,160
and
11051
06:51:18,160 --> 06:51:20,240
what we can do on these data frames we
11052
06:51:20,240 --> 06:51:21,440
can do a lot of things and we're not
11053
06:51:21,440 --> 06:51:23,840
going to demonstrate everything here but
11054
06:51:23,840 --> 06:51:25,840
as you see here the data frame we can
11055
06:51:25,840 --> 06:51:28,080
actually
11056
06:51:28,080 --> 06:51:30,000
let's for instance take the mean value
11057
06:51:30,000 --> 06:51:32,478
on it and what it does actually it will
11058
06:51:32,478 --> 06:51:34,878
take the columns which makes sense to
11059
06:51:34,878 --> 06:51:36,878
take the mean value on and it's only the
11060
06:51:36,878 --> 06:51:38,558
speed column because you cannot take the
11061
06:51:38,558 --> 06:51:40,320
mean value of the names porsche and
11062
06:51:40,320 --> 06:51:42,320
ferrari but here we actually see that
11063
06:51:42,320 --> 06:51:44,638
the mean value of the speed here the
11064
06:51:44,638 --> 06:51:47,920
average speed here was
11065
06:51:49,080 --> 06:51:51,920
228.75 kilometer kilometers per hour
11066
06:51:51,920 --> 06:51:52,718
right
11067
06:51:52,718 --> 06:51:55,120
so you can do a lot of things directly
11068
06:51:55,120 --> 06:51:56,958
on and it's really really nice another
11069
06:51:56,958 --> 06:51:58,798
thing you can do is for instance if you
11070
06:51:58,798 --> 06:52:00,798
have the data frame here and you want to
11071
06:52:00,798 --> 06:52:03,440
say well we have the cars here and i'm
11072
06:52:03,440 --> 06:52:05,200
only interested in cars which are
11073
06:52:05,200 --> 06:52:08,160
porsche right
11074
06:52:08,160 --> 06:52:10,958
so this one here will only show the
11075
06:52:10,958 --> 06:52:12,798
which one has
11076
06:52:12,798 --> 06:52:14,798
the porsche in it right so true true
11077
06:52:14,798 --> 06:52:17,840
false false true true false fault but if
11078
06:52:17,840 --> 06:52:19,200
you want to show them you can actually
11079
06:52:19,200 --> 06:52:21,360
put it inside the data frame here so the
11080
06:52:21,360 --> 06:52:24,000
syntax here is like this here right
11081
06:52:24,000 --> 06:52:26,400
so now you get all the porsche right so
11082
06:52:26,400 --> 06:52:28,558
you immediately see you can
11083
06:52:28,558 --> 06:52:30,798
mangle around with the data in many ways
11084
06:52:30,798 --> 06:52:33,200
to get the data you want and again i'm
11085
06:52:33,200 --> 06:52:34,558
not going to go through everything here
11086
06:52:34,558 --> 06:52:36,320
i'll recommend that you look into a
11087
06:52:36,320 --> 06:52:38,400
cheat sheet which is available from the
11088
06:52:38,400 --> 06:52:40,718
pandas library and i'll put a link down
11089
06:52:40,718 --> 06:52:43,280
there to it and it's also
11090
06:52:43,280 --> 06:52:46,000
a link in the ebook so you can find it
11091
06:52:46,000 --> 06:52:47,600
from there
11092
06:52:47,600 --> 06:52:49,040
because all these things here is just
11093
06:52:49,040 --> 06:52:51,040
you know you don't need to learn them by
11094
06:52:51,040 --> 06:52:52,478
heart in the beginning you will look
11095
06:52:52,478 --> 06:52:54,718
them up in a cheat sheet okay
11096
06:52:54,718 --> 06:52:56,000
yeah so don't worry about all the
11097
06:52:56,000 --> 06:52:57,920
details about these things so in this
11098
06:52:57,920 --> 06:52:59,440
project we're going to do some specific
11099
06:52:59,440 --> 06:53:00,958
things but one of the things we want to
11100
06:53:00,958 --> 06:53:03,520
master is actually grouping things right
11101
06:53:03,520 --> 06:53:06,478
so imagine we want to group the the cars
11102
06:53:06,478 --> 06:53:09,040
right so how can you do that well
11103
06:53:09,040 --> 06:53:11,600
there's a function called group by and
11104
06:53:11,600 --> 06:53:13,840
what it does it takes the column name
11105
06:53:13,840 --> 06:53:17,520
here and then groups the data into this
11106
06:53:17,520 --> 06:53:18,638
but this
11107
06:53:18,638 --> 06:53:21,680
by itself just represent a group by our
11108
06:53:21,680 --> 06:53:24,080
data frame group by object right so this
11109
06:53:24,080 --> 06:53:26,478
is not useful for us we need to tell it
11110
06:53:26,478 --> 06:53:28,080
what should it do with the data right
11111
06:53:28,080 --> 06:53:30,798
because when it has grouped in porsche
11112
06:53:30,798 --> 06:53:33,760
and ferrari as it will be doing here
11113
06:53:33,760 --> 06:53:35,520
what should it do with the data well one
11114
06:53:35,520 --> 06:53:36,878
thing you could do is say what is the
11115
06:53:36,878 --> 06:53:40,000
average speed by the cars right so you
11116
06:53:40,000 --> 06:53:42,240
can actually just call mean on it and
11117
06:53:42,240 --> 06:53:44,878
you see here then you get the mean value
11118
06:53:44,878 --> 06:53:47,600
of the porsche or the ferrari here which
11119
06:53:47,600 --> 06:53:50,958
is 250
11120
06:53:50,958 --> 06:53:54,878
which is 305 plus 195 divided by two
11121
06:53:54,878 --> 06:53:57,440
it's 250 as you see and then this one
11122
06:53:57,440 --> 06:54:00,200
here the average of this one is uh
11123
06:54:00,200 --> 06:54:02,718
207.5 right so you see then you get the
11124
06:54:02,718 --> 06:54:05,120
average speed of the cars you could also
11125
06:54:05,120 --> 06:54:07,200
add some or whatever right then you get
11126
06:54:07,200 --> 06:54:08,638
the sum of
11127
06:54:08,638 --> 06:54:10,638
each of the cars so you can apply
11128
06:54:10,638 --> 06:54:13,120
functions based on a group so this is
11129
06:54:13,120 --> 06:54:15,120
what we're going to do in the project as
11130
06:54:15,120 --> 06:54:16,400
well right we're going to use these
11131
06:54:16,400 --> 06:54:18,000
features okay
11132
06:54:18,000 --> 06:54:18,718
but
11133
06:54:18,718 --> 06:54:21,760
so far so good let's try to
11134
06:54:21,760 --> 06:54:24,478
read some other data
11135
06:54:24,478 --> 06:54:26,080
in this case we're going to read a new
11136
06:54:26,080 --> 06:54:27,440
data set
11137
06:54:27,440 --> 06:54:31,360
i'll just find it so you can see it
11138
06:54:31,920 --> 06:54:34,320
and if you go to files here you'll see
11139
06:54:34,320 --> 06:54:37,280
here there'll be a speed check here this
11140
06:54:37,280 --> 06:54:39,920
is a small data set for us to play with
11141
06:54:39,920 --> 06:54:41,200
first right
11142
06:54:41,200 --> 06:54:44,478
so this data set becomes uh has a date
11143
06:54:44,478 --> 06:54:46,958
on it and it has a car and a speed just
11144
06:54:46,958 --> 06:54:49,280
like we did in the above there right so
11145
06:54:49,280 --> 06:54:51,840
we have a date time when the porsche
11146
06:54:51,840 --> 06:54:54,400
here was registered to 315 kilometers
11147
06:54:54,400 --> 06:54:56,798
per hour and then we have bmv ferrari
11148
06:54:56,798 --> 06:54:59,280
bmv porsche for ibm bmv right so you
11149
06:54:59,280 --> 06:55:02,320
have the date the car and the speed as
11150
06:55:02,320 --> 06:55:04,000
you see here and there's another
11151
06:55:04,000 --> 06:55:06,558
difference in this comma separated
11152
06:55:06,558 --> 06:55:09,760
value file we use a semi
11153
06:55:09,760 --> 06:55:12,320
colon here instead of the comma right so
11154
06:55:12,320 --> 06:55:14,240
this is just to show you that sometimes
11155
06:55:14,240 --> 06:55:15,840
the data is structured a bit different
11156
06:55:15,840 --> 06:55:18,160
and how to read that
11157
06:55:18,160 --> 06:55:19,920
so you don't get worried about that all
11158
06:55:19,920 --> 06:55:21,920
right so you see how to do that right
11159
06:55:21,920 --> 06:55:25,600
okay good so this csv file is called
11160
06:55:25,600 --> 06:55:28,160
speed check so let's just call
11161
06:55:28,160 --> 06:55:29,840
the data frame we create here speed
11162
06:55:29,840 --> 06:55:30,958
check
11163
06:55:30,958 --> 06:55:33,840
and uh then we need to read that and
11164
06:55:33,840 --> 06:55:36,558
with pandas it's amazingly easy right
11165
06:55:36,558 --> 06:55:37,840
pd
11166
06:55:37,840 --> 06:55:40,080
read csv
11167
06:55:40,080 --> 06:55:42,718
what does read csv do well we could look
11168
06:55:42,718 --> 06:55:46,478
in the manual here or the signature
11169
06:55:46,478 --> 06:55:49,360
docs string as it called
11170
06:55:49,360 --> 06:55:52,558
read a comma separated value file into a
11171
06:55:52,558 --> 06:55:55,120
data frame this is what we need right so
11172
06:55:55,120 --> 06:55:57,440
how do we do that we just put the files
11173
06:55:57,440 --> 06:55:58,958
here
11174
06:55:58,958 --> 06:56:00,160
and
11175
06:56:00,160 --> 06:56:02,160
we call the speed checks so if you read
11176
06:56:02,160 --> 06:56:04,240
it immediately we need to set some
11177
06:56:04,240 --> 06:56:07,440
things as we will see here
11178
06:56:07,440 --> 06:56:10,080
because right now it by default it
11179
06:56:10,080 --> 06:56:13,040
expects a comma to be there right so
11180
06:56:13,040 --> 06:56:14,558
if it doesn't find a comma it'll just
11181
06:56:14,558 --> 06:56:17,200
say well i just read one line right so
11182
06:56:17,200 --> 06:56:19,760
this line has column name date car speed
11183
06:56:19,760 --> 06:56:21,040
right obviously because there was no
11184
06:56:21,040 --> 06:56:23,120
comma so it's just one column and then
11185
06:56:23,120 --> 06:56:24,958
you see it down here so this is not very
11186
06:56:24,958 --> 06:56:27,680
good for us right this is bad
11187
06:56:27,680 --> 06:56:28,558
so
11188
06:56:28,558 --> 06:56:31,600
what can we do right so let's look at
11189
06:56:31,600 --> 06:56:32,478
this
11190
06:56:32,478 --> 06:56:34,798
long list of things here right so it has
11191
06:56:34,798 --> 06:56:38,080
a delimiter right
11192
06:56:39,520 --> 06:56:43,200
and let's put that one
11193
06:56:45,680 --> 06:56:46,558
to be
11194
06:56:46,558 --> 06:56:49,280
semicolon right because if we read now
11195
06:56:49,280 --> 06:56:51,120
we see now it actually structures the
11196
06:56:51,120 --> 06:56:54,000
data correct here right perfectly
11197
06:56:54,000 --> 06:56:56,160
another thing we might be doing is
11198
06:56:56,160 --> 06:56:58,638
actually we want the date here to be the
11199
06:56:58,638 --> 06:57:00,400
index here right so right now we have an
11200
06:57:00,400 --> 06:57:02,240
index here
11201
06:57:02,240 --> 06:57:03,680
as you also remember here we have this
11202
06:57:03,680 --> 06:57:04,878
index here
11203
06:57:04,878 --> 06:57:06,320
and
11204
06:57:06,320 --> 06:57:07,760
we want actually the date to be the
11205
06:57:07,760 --> 06:57:09,360
index because often we'll just say we'll
11206
06:57:09,360 --> 06:57:12,798
look up this date and be the index okay
11207
06:57:12,798 --> 06:57:14,638
how do you see the index is actually
11208
06:57:14,638 --> 06:57:17,280
just put index here
11209
06:57:17,280 --> 06:57:18,558
and execute it then you can see the
11210
06:57:18,558 --> 06:57:20,638
index is a range index from start and
11211
06:57:20,638 --> 06:57:22,558
stop it's just numbering here right and
11212
06:57:22,558 --> 06:57:24,958
that's step one and another thing you
11213
06:57:24,958 --> 06:57:28,638
can look at is like the data type
11214
06:57:28,638 --> 06:57:32,320
speed check d type s with an s remember
11215
06:57:32,320 --> 06:57:34,400
with the numpy without s
11216
06:57:34,400 --> 06:57:36,400
and you see here it has object object
11217
06:57:36,400 --> 06:57:39,120
and integers so you know that actually
11218
06:57:39,120 --> 06:57:41,040
the the date here is
11219
06:57:41,040 --> 06:57:43,600
read as an object and the car is an
11220
06:57:43,600 --> 06:57:45,120
object and that means basically it's a
11221
06:57:45,120 --> 06:57:47,280
string in these cases most of the times
11222
06:57:47,280 --> 06:57:49,360
on this object it's a string
11223
06:57:49,360 --> 06:57:51,120
and then you have the interior which is
11224
06:57:51,120 --> 06:57:53,400
the speed so this one
11225
06:57:53,400 --> 06:57:56,000
is an integer and this is a string and
11226
06:57:56,000 --> 06:57:57,600
this is a string right
11227
06:57:57,600 --> 06:57:59,120
so this is
11228
06:57:59,120 --> 06:58:01,360
saying as something else it says here
11229
06:58:01,360 --> 06:58:04,400
that actually that each column has one
11230
06:58:04,400 --> 06:58:07,280
data type which i also mentioned before
11231
06:58:07,280 --> 06:58:08,160
right
11232
06:58:08,160 --> 06:58:09,280
and
11233
06:58:09,280 --> 06:58:11,680
another thing is that this date here is
11234
06:58:11,680 --> 06:58:14,240
not represented as a date time object so
11235
06:58:14,240 --> 06:58:16,320
the computer doesn't know it's a date
11236
06:58:16,320 --> 06:58:18,958
and we need to tell that to the
11237
06:58:18,958 --> 06:58:21,760
program here but luckily
11238
06:58:21,760 --> 06:58:25,760
luckily there's actually a
11239
06:58:25,760 --> 06:58:28,400
argument we can set there
11240
06:58:28,400 --> 06:58:30,958
and you see here par states is by
11241
06:58:30,958 --> 06:58:34,080
default false if we set parse
11242
06:58:34,080 --> 06:58:37,520
parse dates to true let's try that
11243
06:58:37,520 --> 06:58:39,200
that's actually not the one we wanted to
11244
06:58:39,200 --> 06:58:43,360
look at then we have this one here
11245
06:58:43,360 --> 06:58:44,958
well date is still an object but now
11246
06:58:44,958 --> 06:58:46,400
it's actually we cannot see that here
11247
06:58:46,400 --> 06:58:49,520
but it's a date time object so the next
11248
06:58:49,520 --> 06:58:50,638
the next thing we're going to do is
11249
06:58:50,638 --> 06:58:52,558
actually we're going to change this date
11250
06:58:52,558 --> 06:58:55,600
to be the index
11251
06:58:55,760 --> 06:58:57,600
index call
11252
06:58:57,600 --> 06:58:59,440
to be
11253
06:58:59,440 --> 06:59:01,680
the date column right so now we set that
11254
06:59:01,680 --> 06:59:04,080
the index column this one here out here
11255
06:59:04,080 --> 06:59:05,680
should be the date column so let's try
11256
06:59:05,680 --> 06:59:07,280
to do that
11257
06:59:07,280 --> 06:59:08,958
so now you see here
11258
06:59:08,958 --> 06:59:10,558
and that the date
11259
06:59:10,558 --> 06:59:11,840
became
11260
06:59:11,840 --> 06:59:13,440
the column here
11261
06:59:13,440 --> 06:59:15,360
or the index here and then we actually
11262
06:59:15,360 --> 06:59:17,440
can see that the index now is a date
11263
06:59:17,440 --> 06:59:19,360
time index right you see that
11264
06:59:19,360 --> 06:59:21,360
it is changed to daytime index here
11265
06:59:21,360 --> 06:59:22,798
really really nice
11266
06:59:22,798 --> 06:59:25,760
and the date that types now is
11267
06:59:25,760 --> 06:59:27,760
we have one less column now right
11268
06:59:27,760 --> 06:59:29,200
because now we only have
11269
06:59:29,200 --> 06:59:31,360
car and speed
11270
06:59:31,360 --> 06:59:34,320
perfect so this is actually the data
11271
06:59:34,320 --> 06:59:37,360
that we are going to work with so first
11272
06:59:37,360 --> 06:59:39,760
of all we can obviously group by car
11273
06:59:39,760 --> 06:59:41,760
again here right so
11274
06:59:41,760 --> 06:59:44,080
if we wanted to look at the cars and the
11275
06:59:44,080 --> 06:59:46,320
speeding right so we take this speed
11276
06:59:46,320 --> 06:59:48,878
check and we take group by and then we
11277
06:59:48,878 --> 06:59:50,080
can take
11278
06:59:50,080 --> 06:59:51,360
car
11279
06:59:51,360 --> 06:59:53,200
i'll call it car here
11280
06:59:53,200 --> 06:59:54,798
and then we could take let's just take
11281
06:59:54,798 --> 06:59:56,400
the mean value
11282
06:59:56,400 --> 06:59:59,040
then we can see that on average the
11283
06:59:59,040 --> 07:00:01,600
fur and porsche are just the sinners
11284
07:00:01,600 --> 07:00:04,240
right the bmv is not as sinful as
11285
07:00:04,240 --> 07:00:06,718
as the other one here on average right
11286
07:00:06,718 --> 07:00:07,840
and uh
11287
07:00:07,840 --> 07:00:09,200
the thing i actually want to show you is
11288
07:00:09,200 --> 07:00:10,878
actually now we have the monthly data
11289
07:00:10,878 --> 07:00:13,600
here or the data out here we could also
11290
07:00:13,600 --> 07:00:15,440
group by the monthly
11291
07:00:15,440 --> 07:00:16,558
view right
11292
07:00:16,558 --> 07:00:19,280
so let's try to do that
11293
07:00:19,280 --> 07:00:20,320
so
11294
07:00:20,320 --> 07:00:22,320
speed check
11295
07:00:22,320 --> 07:00:25,600
group by and then we actually use a
11296
07:00:25,600 --> 07:00:28,958
pandas again and we'll have a grouper
11297
07:00:28,958 --> 07:00:31,760
and this grouper here
11298
07:00:31,760 --> 07:00:34,478
it basically says grouper
11299
07:00:34,478 --> 07:00:36,638
allows a user to specify group by
11300
07:00:36,638 --> 07:00:39,040
instruction for an object right
11301
07:00:39,040 --> 07:00:39,840
and
11302
07:00:39,840 --> 07:00:41,600
if you read down here you can read a lot
11303
07:00:41,600 --> 07:00:43,040
of things you can have something called
11304
07:00:43,040 --> 07:00:46,958
frequency and this frequency here is how
11305
07:00:46,958 --> 07:00:49,360
often uh you know what kind of group you
11306
07:00:49,360 --> 07:00:51,440
should put into so we're gonna use that
11307
07:00:51,440 --> 07:00:53,120
freak i will
11308
07:00:53,120 --> 07:00:54,878
say it's a monthly basis and you need to
11309
07:00:54,878 --> 07:00:56,400
look these things up to know that's by
11310
07:00:56,400 --> 07:00:58,638
hard right so this is grouping by
11311
07:00:58,638 --> 07:01:01,040
monthly and then we can again
11312
07:01:01,040 --> 07:01:03,920
apply mean on it and then you see here
11313
07:01:03,920 --> 07:01:06,558
that we have two months
11314
07:01:06,558 --> 07:01:07,520
we have
11315
07:01:07,520 --> 07:01:10,478
we have march and april in 21 and you
11316
07:01:10,478 --> 07:01:12,558
can see actually on the data here that
11317
07:01:12,558 --> 07:01:14,000
this is correct
11318
07:01:14,000 --> 07:01:16,558
we only have data from
11319
07:01:16,558 --> 07:01:19,680
march and april in this data set here
11320
07:01:19,680 --> 07:01:22,160
so this is actually true
11321
07:01:22,160 --> 07:01:22,958
so
11322
07:01:22,958 --> 07:01:25,040
this is nice right so let's just put
11323
07:01:25,040 --> 07:01:27,920
this monthly here
11324
07:01:27,920 --> 07:01:30,718
monthly data here and have it here
11325
07:01:30,718 --> 07:01:31,680
because
11326
07:01:31,680 --> 07:01:33,920
if you look at the data again
11327
07:01:33,920 --> 07:01:36,160
well it indexes by the last day of the
11328
07:01:36,160 --> 07:01:37,760
month here right maybe we just want the
11329
07:01:37,760 --> 07:01:40,558
month to be written like that to write
11330
07:01:40,558 --> 07:01:42,478
the actual month and you can actually do
11331
07:01:42,478 --> 07:01:47,200
that to make it look a little bit nicer
11332
07:01:47,200 --> 07:01:49,600
so remember the index here is this kind
11333
07:01:49,600 --> 07:01:51,520
here right so you can override that by
11334
07:01:51,520 --> 07:01:53,440
just assigning it to something so
11335
07:01:53,440 --> 07:01:56,000
monthly index and
11336
07:01:56,000 --> 07:01:57,840
then you have something called month
11337
07:01:57,840 --> 07:01:58,878
name here
11338
07:01:58,878 --> 07:02:01,040
let me do that
11339
07:02:01,040 --> 07:02:02,558
and then you actually override it and
11340
07:02:02,558 --> 07:02:04,320
you see here it will write
11341
07:02:04,320 --> 07:02:06,718
march and april right so what you take
11342
07:02:06,718 --> 07:02:08,638
is you you overwrite the index here and
11343
07:02:08,638 --> 07:02:10,878
you say we want the month name to be
11344
07:02:10,878 --> 07:02:12,638
written instead right so you all
11345
07:02:12,638 --> 07:02:16,160
reassign the index to be the current
11346
07:02:16,160 --> 07:02:18,718
index but you take the month name and
11347
07:02:18,718 --> 07:02:20,638
put it there you can do that on date
11348
07:02:20,638 --> 07:02:21,680
time
11349
07:02:21,680 --> 07:02:24,400
in objects like that okay
11350
07:02:24,400 --> 07:02:27,360
amazing perfect
11351
07:02:27,360 --> 07:02:28,320
so
11352
07:02:28,320 --> 07:02:30,240
next thing next right now we need to
11353
07:02:30,240 --> 07:02:32,558
export it to excel sheets and this is
11354
07:02:32,558 --> 07:02:35,760
where it becomes interesting right
11355
07:02:35,760 --> 07:02:38,000
so this is actually quite easy again
11356
07:02:38,000 --> 07:02:38,878
with
11357
07:02:38,878 --> 07:02:42,320
pandas so it's just to write to
11358
07:02:42,320 --> 07:02:43,600
excel
11359
07:02:43,600 --> 07:02:44,638
basically
11360
07:02:44,638 --> 07:02:45,780
and then you write the
11361
07:02:45,780 --> 07:02:47,200
[Music]
11362
07:02:47,200 --> 07:02:49,120
excel name that you want to export to so
11363
07:02:49,120 --> 07:02:52,400
let's try to export it naively like this
11364
07:02:52,400 --> 07:02:55,360
and then we need to open the excel sheet
11365
07:02:55,360 --> 07:02:57,680
and you we have it here actually the
11366
07:02:57,680 --> 07:02:59,200
first one is a date here and you see
11367
07:02:59,200 --> 07:03:00,878
here this doesn't look nice but we're
11368
07:03:00,878 --> 07:03:01,920
not going to go into that this is
11369
07:03:01,920 --> 07:03:04,320
because it's a date object and it writes
11370
07:03:04,320 --> 07:03:06,878
like that but in our case we don't care
11371
07:03:06,878 --> 07:03:08,718
but you could actually
11372
07:03:08,718 --> 07:03:10,798
resize this one from python as well so
11373
07:03:10,798 --> 07:03:12,638
when you open it it will be resized or
11374
07:03:12,638 --> 07:03:14,320
you could reformat it so you don't have
11375
07:03:14,320 --> 07:03:17,120
this 0 here but we're not going to play
11376
07:03:17,120 --> 07:03:19,040
around with that in this one here
11377
07:03:19,040 --> 07:03:20,878
because we're not going to use the date
11378
07:03:20,878 --> 07:03:23,040
export the data like that
11379
07:03:23,040 --> 07:03:24,878
but here we have the data right the car
11380
07:03:24,878 --> 07:03:26,478
and the speed
11381
07:03:26,478 --> 07:03:29,520
all done by one line of code right so
11382
07:03:29,520 --> 07:03:31,600
what is the next step here right what we
11383
07:03:31,600 --> 07:03:33,840
actually want to do is write multiple
11384
07:03:33,840 --> 07:03:36,400
sheets here so let's try to do that one
11385
07:03:36,400 --> 07:03:38,798
where we export
11386
07:03:38,798 --> 07:03:40,558
this data here and one where we export
11387
07:03:40,558 --> 07:03:42,320
this data here so let's try to do that
11388
07:03:42,320 --> 07:03:43,280
but
11389
07:03:43,280 --> 07:03:46,080
when you read the excel documentation
11390
07:03:46,080 --> 07:03:48,160
here
11391
07:03:48,160 --> 07:03:49,840
you actually see here
11392
07:03:49,840 --> 07:03:51,200
that
11393
07:03:51,200 --> 07:03:53,680
to write a single object to excel a file
11394
07:03:53,680 --> 07:03:55,600
it's only necessary to specify the
11395
07:03:55,600 --> 07:03:58,080
target file name to write
11396
07:03:58,080 --> 07:04:00,160
to multiple sheets it's necessary to
11397
07:04:00,160 --> 07:04:02,958
create an excel writer object with a
11398
07:04:02,958 --> 07:04:05,600
target file name and specify a sheet in
11399
07:04:05,600 --> 07:04:07,760
which the file to write to
11400
07:04:07,760 --> 07:04:09,040
so that's what we're going to do down
11401
07:04:09,040 --> 07:04:11,520
here actually
11402
07:04:11,520 --> 07:04:12,798
so
11403
07:04:12,798 --> 07:04:15,920
let's just call it workbook
11404
07:04:15,920 --> 07:04:17,600
pd
11405
07:04:17,600 --> 07:04:20,160
and then we create this excel writer
11406
07:04:20,160 --> 07:04:21,280
and
11407
07:04:21,280 --> 07:04:24,320
we're going to use the same
11408
07:04:24,798 --> 07:04:26,080
name here
11409
07:04:26,080 --> 07:04:27,600
perfect
11410
07:04:27,600 --> 07:04:30,160
and then we take the
11411
07:04:30,160 --> 07:04:33,200
speed check and we do group
11412
07:04:33,200 --> 07:04:34,878
by
11413
07:04:34,878 --> 07:04:35,840
car
11414
07:04:35,840 --> 07:04:38,320
and let's just take the mean value here
11415
07:04:38,320 --> 07:04:40,638
and then we do to excel
11416
07:04:40,638 --> 07:04:41,760
oh
11417
07:04:41,760 --> 07:04:42,958
to excel
11418
07:04:42,958 --> 07:04:45,600
and then we take the workbook here
11419
07:04:45,600 --> 07:04:48,798
and then we define the sheet name as
11420
07:04:48,798 --> 07:04:51,760
as it said and we call it
11421
07:04:51,760 --> 07:04:52,878
cars
11422
07:04:52,878 --> 07:04:54,798
right so this is our first sheet and
11423
07:04:54,798 --> 07:04:56,558
then we're gonna do the
11424
07:04:56,558 --> 07:04:58,000
monthly here
11425
07:04:58,000 --> 07:05:00,320
and we're gonna do this is just written
11426
07:05:00,320 --> 07:05:03,360
directly because we saved it to excel
11427
07:05:03,360 --> 07:05:06,120
workbook and um
11428
07:05:06,120 --> 07:05:08,478
sheet name
11429
07:05:08,478 --> 07:05:11,200
we call it um let's just call it
11430
07:05:11,200 --> 07:05:12,400
monthly
11431
07:05:12,400 --> 07:05:14,718
oh monthly here
11432
07:05:14,718 --> 07:05:15,760
perfect
11433
07:05:15,760 --> 07:05:17,920
when we work with a workbook we need to
11434
07:05:17,920 --> 07:05:19,440
close it as well
11435
07:05:19,440 --> 07:05:21,040
because it doesn't know if something
11436
07:05:21,040 --> 07:05:22,958
more is coming right so what do we do we
11437
07:05:22,958 --> 07:05:25,360
create an excel writer as it tells us to
11438
07:05:25,360 --> 07:05:27,680
do so we have a workbook and
11439
07:05:27,680 --> 07:05:29,440
the reason we need that is because when
11440
07:05:29,440 --> 07:05:32,558
we write multiple times to excel
11441
07:05:32,558 --> 07:05:35,200
uh we need to specify that we're working
11442
07:05:35,200 --> 07:05:37,840
with the same excel sheet but then we
11443
07:05:37,840 --> 07:05:40,240
say which sheet name we are creating in
11444
07:05:40,240 --> 07:05:42,558
it right so first here we take the speed
11445
07:05:42,558 --> 07:05:44,958
check group by car and mean that was
11446
07:05:44,958 --> 07:05:48,160
what we did up here
11447
07:05:48,160 --> 07:05:50,478
so we will get this one here
11448
07:05:50,478 --> 07:05:54,160
and uh we write that to the exp
11449
07:05:54,160 --> 07:05:56,558
spreadsheet here and we create the sheet
11450
07:05:56,558 --> 07:05:58,558
name cars and then we take the monthly
11451
07:05:58,558 --> 07:06:00,320
data this one here just directly and
11452
07:06:00,320 --> 07:06:02,400
write it to excel in the workbook
11453
07:06:02,400 --> 07:06:04,320
monthly and then we close it which will
11454
07:06:04,320 --> 07:06:07,200
write it so let's try to execute this
11455
07:06:07,200 --> 07:06:09,840
piece here and
11456
07:06:09,840 --> 07:06:12,798
let's open our spreadsheet here
11457
07:06:12,798 --> 07:06:14,558
and then you see immediately here right
11458
07:06:14,558 --> 07:06:16,400
we have cars and monthly and here in
11459
07:06:16,400 --> 07:06:18,000
cars we have the
11460
07:06:18,000 --> 07:06:20,000
cars listed here with the average speed
11461
07:06:20,000 --> 07:06:21,040
here
11462
07:06:21,040 --> 07:06:23,280
perfect and on the monthly sheet here we
11463
07:06:23,280 --> 07:06:26,160
have the monthly data error wow amazing
11464
07:06:26,160 --> 07:06:27,120
right
11465
07:06:27,120 --> 07:06:28,400
perfect
11466
07:06:28,400 --> 07:06:30,080
so the final thing we
11467
07:06:30,080 --> 07:06:32,400
we want to do here is actually we wanted
11468
07:06:32,400 --> 07:06:34,878
to create a chart right and this is
11469
07:06:34,878 --> 07:06:36,718
where this link comes into the picture
11470
07:06:36,718 --> 07:06:40,320
so let's look at the code here
11471
07:06:40,320 --> 07:06:41,520
so
11472
07:06:41,520 --> 07:06:43,920
so far so good right we did this
11473
07:06:43,920 --> 07:06:46,320
this part here and we what it's doing
11474
07:06:46,320 --> 07:06:47,280
here is
11475
07:06:47,280 --> 07:06:49,600
kind of formatting and
11476
07:06:49,600 --> 07:06:51,200
writing some data we did it a bit
11477
07:06:51,200 --> 07:06:52,878
different here but what we're looking
11478
07:06:52,878 --> 07:06:55,600
for is actually this down here we need
11479
07:06:55,600 --> 07:06:58,160
to create a chart so how do you do that
11480
07:06:58,160 --> 07:07:00,000
right so
11481
07:07:00,000 --> 07:07:02,638
let's try to do that in our case here so
11482
07:07:02,638 --> 07:07:05,440
let's just take the same
11483
07:07:05,440 --> 07:07:08,080
code here and put it down here so i just
11484
07:07:08,080 --> 07:07:10,320
save that one here and then we put some
11485
07:07:10,320 --> 07:07:13,840
code in between here okay
11486
07:07:14,718 --> 07:07:16,478
and this code here is actually going to
11487
07:07:16,478 --> 07:07:17,280
be
11488
07:07:17,280 --> 07:07:18,080
this
11489
07:07:18,080 --> 07:07:22,160
we have here let's just copy this
11490
07:07:23,040 --> 07:07:24,958
and we're going to modify it so it fits
11491
07:07:24,958 --> 07:07:27,520
our things but there's one more line we
11492
07:07:27,520 --> 07:07:29,440
need before
11493
07:07:29,440 --> 07:07:33,760
we need actually to insert the chart
11494
07:07:35,040 --> 07:07:37,760
and they work with
11495
07:07:37,760 --> 07:07:39,520
worksheet here right so we need to
11496
07:07:39,520 --> 07:07:41,120
modify that because we didn't create a
11497
07:07:41,120 --> 07:07:42,718
worksheet here right so we had the
11498
07:07:42,718 --> 07:07:45,040
workbook but we don't have the worksheet
11499
07:07:45,040 --> 07:07:46,000
here
11500
07:07:46,000 --> 07:07:49,200
so so the worksheet is accessed by
11501
07:07:49,200 --> 07:07:51,440
workbook
11502
07:07:51,440 --> 07:07:53,040
dot
11503
07:07:53,040 --> 07:07:54,798
sheets
11504
07:07:54,798 --> 07:07:56,958
and then we take this sheet we want to
11505
07:07:56,958 --> 07:07:59,440
put in this case we're just gonna
11506
07:07:59,440 --> 07:08:03,520
put one sheet in here and it's gonna be
11507
07:08:03,520 --> 07:08:05,360
the car
11508
07:08:05,360 --> 07:08:08,400
sheet or cars it's called and we're
11509
07:08:08,400 --> 07:08:11,040
actually gonna remove this part here
11510
07:08:11,040 --> 07:08:12,400
and
11511
07:08:12,400 --> 07:08:14,638
so what is going to happen here right so
11512
07:08:14,638 --> 07:08:17,120
we create a chart one here and we added
11513
07:08:17,120 --> 07:08:17,840
two
11514
07:08:17,840 --> 07:08:19,120
of type
11515
07:08:19,120 --> 07:08:21,680
column we want the same type as they do
11516
07:08:21,680 --> 07:08:23,600
and then they add the series but we
11517
07:08:23,600 --> 07:08:25,040
don't have
11518
07:08:25,040 --> 07:08:27,440
the same name here but let's just have
11519
07:08:27,440 --> 07:08:29,360
the cars here and then we have the
11520
07:08:29,360 --> 07:08:32,160
categories it's not on sheet1 it's on
11521
07:08:32,160 --> 07:08:33,440
cars
11522
07:08:33,440 --> 07:08:36,000
and the categories are from a2 that is
11523
07:08:36,000 --> 07:08:37,520
correct
11524
07:08:37,520 --> 07:08:39,360
as far as i remember let's open the
11525
07:08:39,360 --> 07:08:42,240
excel sheet again
11526
07:08:42,878 --> 07:08:46,638
so from a2 to a4 right and the speed is
11527
07:08:46,638 --> 07:08:50,878
from b2 to b4 right this is the one
11528
07:08:50,878 --> 07:08:52,840
so a2 to
11529
07:08:52,840 --> 07:08:57,120
a4 and here we have the values cars from
11530
07:08:57,120 --> 07:09:00,160
b2 to b4 right so this is basically what
11531
07:09:00,160 --> 07:09:04,240
we do we're specifying the area of the
11532
07:09:04,240 --> 07:09:06,638
column chart as they call it and then we
11533
07:09:06,638 --> 07:09:09,440
insert it in our sheet cars
11534
07:09:09,440 --> 07:09:13,360
in d2 okay let's try to do that boom
11535
07:09:13,360 --> 07:09:16,958
so i did one mistake here so
11536
07:09:16,958 --> 07:09:20,400
add chart so it was workbook
11537
07:09:20,400 --> 07:09:22,718
actually we need to have the book here
11538
07:09:22,718 --> 07:09:24,478
because we do it a bit different than
11539
07:09:24,478 --> 07:09:26,320
they do because if you look at the code
11540
07:09:26,320 --> 07:09:28,478
here i just forgot about that
11541
07:09:28,478 --> 07:09:31,760
so when they create a
11542
07:09:31,760 --> 07:09:35,440
work or they use the xl
11543
07:09:35,440 --> 07:09:37,600
x writer that's why
11544
07:09:37,600 --> 07:09:39,840
uh so we need to add that one there
11545
07:09:39,840 --> 07:09:41,280
in the book here
11546
07:09:41,280 --> 07:09:43,760
and it's a bit confusing you know i know
11547
07:09:43,760 --> 07:09:46,478
but it's it's a bit different syntax on
11548
07:09:46,478 --> 07:09:48,080
this one here but other than that it's
11549
07:09:48,080 --> 07:09:50,000
totally the same right so now we execute
11550
07:09:50,000 --> 07:09:52,400
it so let's look at the
11551
07:09:52,400 --> 07:09:54,160
spreadsheet here
11552
07:09:54,160 --> 07:09:56,320
and you see here we got the chart here
11553
07:09:56,320 --> 07:09:58,638
right so you can see from bnb
11554
07:09:58,638 --> 07:09:59,600
it is
11555
07:09:59,600 --> 07:10:02,400
average speed here and ferrari and the
11556
07:10:02,400 --> 07:10:04,878
porsche here right so this is how it was
11557
07:10:04,878 --> 07:10:07,440
entered and again it is a live data so
11558
07:10:07,440 --> 07:10:09,600
if you change it it changes here as well
11559
07:10:09,600 --> 07:10:11,280
right
11560
07:10:11,280 --> 07:10:14,160
perfect right
11561
07:10:14,240 --> 07:10:15,920
so see how you can change the values
11562
07:10:15,920 --> 07:10:19,600
there so isn't that amazing so
11563
07:10:19,600 --> 07:10:21,920
that's basically what
11564
07:10:21,920 --> 07:10:23,360
we need for
11565
07:10:23,360 --> 07:10:24,878
our project
11566
07:10:24,878 --> 07:10:27,040
and uh if you find this down here a bit
11567
07:10:27,040 --> 07:10:28,400
confusing don't worry about it you're
11568
07:10:28,400 --> 07:10:31,120
gonna copy paste it and modify it to
11569
07:10:31,120 --> 07:10:33,840
your need as we did here together and
11570
07:10:33,840 --> 07:10:36,000
that's it are you excited i hope so
11571
07:10:36,000 --> 07:10:37,760
because it's going to be amazing see you
11572
07:10:37,760 --> 07:10:40,160
in a moment
11573
07:10:43,120 --> 07:10:45,040
are you ready for this project it's
11574
07:10:45,040 --> 07:10:46,400
going to be amazing
11575
07:10:46,400 --> 07:10:48,400
so let's jump to jupiter notebook and
11576
07:10:48,400 --> 07:10:50,400
read about it so the project is called
11577
07:10:50,400 --> 07:10:53,680
pandas and excel export so the goal is
11578
07:10:53,680 --> 07:10:56,240
to learn how to use pandas data frames
11579
07:10:56,240 --> 07:10:58,718
right the data structure of pandas and
11580
07:10:58,718 --> 07:11:01,920
how to export to an excel sheet okay
11581
07:11:01,920 --> 07:11:03,840
so the description here is what you need
11582
07:11:03,840 --> 07:11:06,400
to do so first we need to import pandas
11583
07:11:06,400 --> 07:11:08,000
as pd
11584
07:11:08,000 --> 07:11:09,760
that should be straightforward then we
11585
07:11:09,760 --> 07:11:11,440
read the csv file
11586
07:11:11,440 --> 07:11:13,920
file sales csv with pandas and let's
11587
07:11:13,920 --> 07:11:16,240
just take a look at that one right so we
11588
07:11:16,240 --> 07:11:18,320
have that under files here and then we
11589
07:11:18,320 --> 07:11:21,440
have the sales data here
11590
07:11:21,440 --> 07:11:23,920
and you see here this data is
11591
07:11:23,920 --> 07:11:27,200
actually pretty long actually
11592
07:11:27,280 --> 07:11:29,520
and it's structured similar to the one
11593
07:11:29,520 --> 07:11:32,080
we looked at right so again here we have
11594
07:11:32,080 --> 07:11:34,400
a delimiter which is different from
11595
07:11:34,400 --> 07:11:37,280
comma it's semicolon right and then we
11596
07:11:37,280 --> 07:11:38,638
have the date we have the sales
11597
07:11:38,638 --> 07:11:41,360
representative the item the price the
11598
07:11:41,360 --> 07:11:44,240
quantity and the sale right so here we
11599
07:11:44,240 --> 07:11:46,958
have the date of the sale and then we
11600
07:11:46,958 --> 07:11:48,958
have the sales rep
11601
07:11:48,958 --> 07:11:51,760
and what did they sell the markers and
11602
07:11:51,760 --> 07:11:53,600
you can see different types here and
11603
07:11:53,600 --> 07:11:57,120
then the quantity and know the price the
11604
07:11:57,120 --> 07:12:00,478
quantity and the sale
11605
07:12:00,478 --> 07:12:02,240
yeah the quant oh yeah so that makes
11606
07:12:02,240 --> 07:12:04,080
sense right so the price the quantity
11607
07:12:04,080 --> 07:12:06,240
and the sale right so you have double
11608
07:12:06,240 --> 07:12:08,400
quantity as here right then the sale is
11609
07:12:08,400 --> 07:12:11,920
the sale the total sale of that perfect
11610
07:12:11,920 --> 07:12:13,040
good
11611
07:12:13,040 --> 07:12:15,440
awesome
11612
07:12:15,440 --> 07:12:17,600
so it actually here remember to set
11613
07:12:17,600 --> 07:12:19,360
index call to date
11614
07:12:19,360 --> 07:12:21,920
delimiter to semicolon and parse states
11615
07:12:21,920 --> 07:12:23,840
to true right otherwise you cannot do
11616
07:12:23,840 --> 07:12:25,520
all the magic below
11617
07:12:25,520 --> 07:12:27,760
so first we need to group by sales rep
11618
07:12:27,760 --> 07:12:30,160
and sum it up right so this is basically
11619
07:12:30,160 --> 07:12:31,360
saying we have these sales
11620
07:12:31,360 --> 07:12:33,760
representatives and we need to figure
11621
07:12:33,760 --> 07:12:36,000
out how much they sell right so this is
11622
07:12:36,000 --> 07:12:36,638
a
11623
07:12:36,638 --> 07:12:38,320
normal way you want normal thing you
11624
07:12:38,320 --> 07:12:40,478
want to do an excel sheet to see well at
11625
07:12:40,478 --> 07:12:42,478
the end of the month who sold the most
11626
07:12:42,478 --> 07:12:44,160
right or the end of the year or whatever
11627
07:12:44,160 --> 07:12:46,240
right you want to see which of the sales
11628
07:12:46,240 --> 07:12:50,798
reps are actually performing well okay
11629
07:12:50,878 --> 07:12:52,958
and uh
11630
07:12:52,958 --> 07:12:55,120
that's the first one and then
11631
07:12:55,120 --> 07:12:57,360
we need to group by month right and in
11632
07:12:57,360 --> 07:12:58,638
this case here
11633
07:12:58,638 --> 07:13:01,600
remember this grouper the frequency here
11634
07:13:01,600 --> 07:13:03,520
right remember that one we can use the
11635
07:13:03,520 --> 07:13:06,320
month here you use that inside the group
11636
07:13:06,320 --> 07:13:09,760
by method right remember okay
11637
07:13:09,760 --> 07:13:10,638
and
11638
07:13:10,638 --> 07:13:12,558
then we also want to change the naming
11639
07:13:12,558 --> 07:13:13,520
of
11640
07:13:13,520 --> 07:13:16,160
the index to use month name and not just
11641
07:13:16,160 --> 07:13:17,360
using
11642
07:13:17,360 --> 07:13:20,160
using the
11643
07:13:20,160 --> 07:13:22,878
end of the month date in there right and
11644
07:13:22,878 --> 07:13:26,000
then we need to export it to excel
11645
07:13:26,000 --> 07:13:27,120
perfect
11646
07:13:27,120 --> 07:13:29,440
we create an excel writer remember when
11647
07:13:29,440 --> 07:13:31,040
you have multiple sheets you need to
11648
07:13:31,040 --> 07:13:33,120
create an excel writer and then you made
11649
07:13:33,120 --> 07:13:36,400
a sheet with a sales rep and
11650
07:13:36,400 --> 07:13:37,920
with the data above here right the sales
11651
07:13:37,920 --> 07:13:40,080
rep data and then you of course need to
11652
07:13:40,080 --> 07:13:41,760
remember to set the sheet name and then
11653
07:13:41,760 --> 07:13:43,920
we create one for the monthly data and
11654
07:13:43,920 --> 07:13:46,478
also set the sheet name and remember
11655
07:13:46,478 --> 07:13:48,000
after this you need to remember the
11656
07:13:48,000 --> 07:13:50,080
close-up workbook
11657
07:13:50,080 --> 07:13:51,840
and if you're up for it i think you
11658
07:13:51,840 --> 07:13:54,240
should create charts uh column charts
11659
07:13:54,240 --> 07:13:56,478
for each sheet right just use the simple
11660
07:13:56,478 --> 07:13:58,638
way we did it and you can always do more
11661
07:13:58,638 --> 07:14:00,080
advanced where i actually figure out how
11662
07:14:00,080 --> 07:14:01,680
many rows and columns are there don't
11663
07:14:01,680 --> 07:14:03,760
worry about that you can do that in more
11664
07:14:03,760 --> 07:14:07,120
advanced later okay so this is a project
11665
07:14:07,120 --> 07:14:09,120
i think it's a great
11666
07:14:09,120 --> 07:14:11,520
resource to learn because
11667
07:14:11,520 --> 07:14:13,920
if you like me been working in an
11668
07:14:13,920 --> 07:14:16,638
industry where people
11669
07:14:16,638 --> 07:14:18,638
actually any industry they use excel
11670
07:14:18,638 --> 07:14:21,280
sheet all the time so if you want see
11671
07:14:21,280 --> 07:14:23,120
somebody doing some manual things every
11672
07:14:23,120 --> 07:14:24,718
month well you say well i can
11673
07:14:24,718 --> 07:14:27,200
automatically automate that for you
11674
07:14:27,200 --> 07:14:29,360
and honestly i've been doing some stuff
11675
07:14:29,360 --> 07:14:30,400
and it's just like
11676
07:14:30,400 --> 07:14:32,638
i helped one guy and it took me like a
11677
07:14:32,638 --> 07:14:34,718
few hours to do and he was just like
11678
07:14:34,718 --> 07:14:36,718
well i do this every single month and it
11679
07:14:36,718 --> 07:14:38,080
takes me
11680
07:14:38,080 --> 07:14:39,840
so long to do it and it's just like now
11681
07:14:39,840 --> 07:14:41,520
you just saved me all that time thank
11682
07:14:41,520 --> 07:14:42,320
you
11683
07:14:42,320 --> 07:14:44,240
you can be that guy the guy that saves
11684
07:14:44,240 --> 07:14:47,360
that guy okay so see you in a moment
11685
07:14:47,360 --> 07:14:49,760
bye-bye
11686
07:14:52,160 --> 07:14:54,798
perfect are you ready did you try it out
11687
07:14:54,798 --> 07:14:56,320
did you figure it out let me know in the
11688
07:14:56,320 --> 07:14:58,320
comments below and again if you don't
11689
07:14:58,320 --> 07:14:59,840
remember all the syntax remember to
11690
07:14:59,840 --> 07:15:01,600
download the ebook because that will
11691
07:15:01,600 --> 07:15:02,878
make you
11692
07:15:02,878 --> 07:15:04,558
that will have all the things you need
11693
07:15:04,558 --> 07:15:05,920
to learn right
11694
07:15:05,920 --> 07:15:09,360
and let's get started so
11695
07:15:09,360 --> 07:15:11,360
let's just jump into it and start at the
11696
07:15:11,360 --> 07:15:13,920
first point here and import pandas
11697
07:15:13,920 --> 07:15:15,440
how do you do that
11698
07:15:15,440 --> 07:15:18,638
import pandas as pd thank you for
11699
07:15:18,638 --> 07:15:20,320
helping me
11700
07:15:20,320 --> 07:15:23,120
then we need to read the csv files and
11701
07:15:23,120 --> 07:15:25,040
remember how it looks like here this is
11702
07:15:25,040 --> 07:15:26,478
this file here
11703
07:15:26,478 --> 07:15:28,638
and we have something to take care of
11704
07:15:28,638 --> 07:15:30,878
but let's just first import it naively
11705
07:15:30,878 --> 07:15:33,280
and see how it looks like so let's just
11706
07:15:33,280 --> 07:15:35,680
call it data here
11707
07:15:35,680 --> 07:15:38,638
pd read csv this is how you read the csv
11708
07:15:38,638 --> 07:15:41,280
file and then you just put the file
11709
07:15:41,280 --> 07:15:43,520
destination here
11710
07:15:43,520 --> 07:15:46,478
sales rep or sales data it's called
11711
07:15:46,478 --> 07:15:48,160
but if you look at this one here right
11712
07:15:48,160 --> 07:15:49,760
we have the same problem we had in the
11713
07:15:49,760 --> 07:15:52,638
lecture right so here
11714
07:15:52,638 --> 07:15:55,120
so here we have everything in one column
11715
07:15:55,120 --> 07:15:56,798
name because it doesn't understand that
11716
07:15:56,798 --> 07:15:59,680
this is a separator or delimiter so
11717
07:15:59,680 --> 07:16:03,440
let's add that there delimiter
11718
07:16:03,440 --> 07:16:04,718
and
11719
07:16:04,718 --> 07:16:07,120
semicolon so if you do that immediately
11720
07:16:07,120 --> 07:16:10,478
it puts it in columns by itself right
11721
07:16:10,478 --> 07:16:12,240
and
11722
07:16:12,240 --> 07:16:14,558
also remember the data types each column
11723
07:16:14,558 --> 07:16:16,798
has a data type here
11724
07:16:16,798 --> 07:16:18,080
date
11725
07:16:18,080 --> 07:16:21,120
sales rep and items are objects and
11726
07:16:21,120 --> 07:16:23,200
price quantity sales are integers so
11727
07:16:23,200 --> 07:16:25,440
it's fine right another thing we wanted
11728
07:16:25,440 --> 07:16:27,360
to look at was uh
11729
07:16:27,360 --> 07:16:30,240
we needed to remember to parse states
11730
07:16:30,240 --> 07:16:32,478
par states to be true and then we need
11731
07:16:32,478 --> 07:16:33,680
to set
11732
07:16:33,680 --> 07:16:36,718
our column index know how is it called
11733
07:16:36,718 --> 07:16:39,200
i actually forgot it for a moment here
11734
07:16:39,200 --> 07:16:40,878
we need to set index call that's how it
11735
07:16:40,878 --> 07:16:42,320
called index
11736
07:16:42,320 --> 07:16:43,360
call
11737
07:16:43,360 --> 07:16:44,240
to be
11738
07:16:44,240 --> 07:16:47,040
date okay
11739
07:16:47,040 --> 07:16:50,320
so now actually we have
11740
07:16:50,320 --> 07:16:52,878
data here and we see it looks like this
11741
07:16:52,878 --> 07:16:54,320
here right
11742
07:16:54,320 --> 07:16:56,240
it's a small trick here so you see here
11743
07:16:56,240 --> 07:16:58,240
now you get a lot of data here but it
11744
07:16:58,240 --> 07:17:00,718
summarizes there often what you're just
11745
07:17:00,718 --> 07:17:02,878
looking for are just the first few lines
11746
07:17:02,878 --> 07:17:04,958
to see if the data is correct you do
11747
07:17:04,958 --> 07:17:07,760
that by hit right it's just a little tip
11748
07:17:07,760 --> 07:17:11,120
for you free free tip for you okay so
11749
07:17:11,120 --> 07:17:12,558
then you can see how the data looks like
11750
07:17:12,558 --> 07:17:15,280
so you don't make this long
11751
07:17:15,280 --> 07:17:18,638
long list of data okay perfect first
11752
07:17:18,638 --> 07:17:20,718
step done
11753
07:17:20,718 --> 07:17:22,798
or actually that was second step so here
11754
07:17:22,798 --> 07:17:25,200
group data by sales rep and summit how
11755
07:17:25,200 --> 07:17:26,638
do you do that
11756
07:17:26,638 --> 07:17:29,040
well we have the data here and then we
11757
07:17:29,040 --> 07:17:30,320
need the group
11758
07:17:30,320 --> 07:17:34,320
by and we just write sales rep and again
11759
07:17:34,320 --> 07:17:36,240
remember you need to spell it correctly
11760
07:17:36,240 --> 07:17:38,398
if you make a mistapping down here it
11761
07:17:38,398 --> 07:17:39,440
won't work
11762
07:17:39,440 --> 07:17:41,280
and then you need the sum of that right
11763
07:17:41,280 --> 07:17:43,600
so here we have it right so this is the
11764
07:17:43,600 --> 07:17:45,280
data so now you can see all the sales
11765
07:17:45,280 --> 07:17:47,760
rep that you see for instance emma here
11766
07:17:47,760 --> 07:17:49,200
c has
11767
07:17:49,200 --> 07:17:50,798
sold this is the one we are actually
11768
07:17:50,798 --> 07:17:53,520
interested in sales down here she has
11769
07:17:53,520 --> 07:17:54,460
sold for
11770
07:17:54,460 --> 07:17:55,680
[Music]
11771
07:17:55,680 --> 07:17:58,240
50 no 65 000
11772
07:17:58,240 --> 07:18:00,240
so actually we have the sofia down here
11773
07:18:00,240 --> 07:18:01,280
is a
11774
07:18:01,280 --> 07:18:03,120
star of this company
11775
07:18:03,120 --> 07:18:05,120
or i mean it depends on how much revenue
11776
07:18:05,120 --> 07:18:06,558
there is in the sales but we don't have
11777
07:18:06,558 --> 07:18:08,398
that kind of data in this data set here
11778
07:18:08,398 --> 07:18:11,120
so we are just assuming naively that the
11779
07:18:11,120 --> 07:18:13,520
revenue is
11780
07:18:13,520 --> 07:18:16,958
equal to the sales here
11781
07:18:16,958 --> 07:18:19,680
or equal connection between it perfect
11782
07:18:19,680 --> 07:18:20,798
awesome
11783
07:18:20,798 --> 07:18:23,040
awesome awesome awesome so we want to
11784
07:18:23,040 --> 07:18:26,398
save this data here so
11785
07:18:26,798 --> 07:18:29,600
so let's just say sales
11786
07:18:29,600 --> 07:18:31,760
and
11787
07:18:32,320 --> 07:18:34,320
actually we want more than that we don't
11788
07:18:34,320 --> 07:18:36,398
want the full data set here because the
11789
07:18:36,398 --> 07:18:39,120
price and quantity doesn't really make
11790
07:18:39,120 --> 07:18:41,040
sense maybe the quantity makes sense but
11791
07:18:41,040 --> 07:18:42,160
we are
11792
07:18:42,160 --> 07:18:44,080
actually only interested in sales here
11793
07:18:44,080 --> 07:18:46,080
right so how can you get that well you
11794
07:18:46,080 --> 07:18:48,558
actually just write sale here and then
11795
07:18:48,558 --> 07:18:51,040
you actually only have it the sale from
11796
07:18:51,040 --> 07:18:52,638
that you also notice that it becomes a
11797
07:18:52,638 --> 07:18:54,398
different data structure here right so
11798
07:18:54,398 --> 07:18:56,878
this is actually not a
11799
07:18:56,878 --> 07:18:59,520
not a what's called a data frame anymore
11800
07:18:59,520 --> 07:19:01,920
it's a series but the series is just a
11801
07:19:01,920 --> 07:19:03,840
one column data frame you could you
11802
07:19:03,840 --> 07:19:05,520
could think of it like that and here it
11803
07:19:05,520 --> 07:19:07,920
also has one data type and then it has
11804
07:19:07,920 --> 07:19:11,680
the still the same index out here okay
11805
07:19:11,680 --> 07:19:15,040
so what should we call
11806
07:19:15,040 --> 07:19:16,798
this one we call it
11807
07:19:16,798 --> 07:19:18,080
rep
11808
07:19:18,080 --> 07:19:21,920
refresh rep cells
11809
07:19:21,920 --> 07:19:24,000
here we have it right so now we save
11810
07:19:24,000 --> 07:19:26,398
that data for our excel sheet that will
11811
07:19:26,398 --> 07:19:28,878
export later
11812
07:19:28,878 --> 07:19:31,200
then the next step here we need to group
11813
07:19:31,200 --> 07:19:33,520
the data by month how was it
11814
07:19:33,520 --> 07:19:35,440
how was it right we had this grouper
11815
07:19:35,440 --> 07:19:37,440
frequency month and we needed to
11816
07:19:37,440 --> 07:19:38,718
remember to
11817
07:19:38,718 --> 07:19:41,200
change the index name so let's try to do
11818
07:19:41,200 --> 07:19:42,478
that
11819
07:19:42,478 --> 07:19:43,520
data
11820
07:19:43,520 --> 07:19:45,280
group
11821
07:19:45,280 --> 07:19:46,478
group by
11822
07:19:46,478 --> 07:19:48,000
and then pd
11823
07:19:48,000 --> 07:19:49,120
grouper
11824
07:19:49,120 --> 07:19:50,798
and frequency
11825
07:19:50,798 --> 07:19:53,040
month
11826
07:19:53,040 --> 07:19:54,718
and if you look at this one it doesn't
11827
07:19:54,718 --> 07:19:56,240
make sense because it's a data frame
11828
07:19:56,240 --> 07:19:58,160
group by object again we need to do
11829
07:19:58,160 --> 07:20:00,638
something so the month here what is it
11830
07:20:00,638 --> 07:20:02,558
we want to do on the monthly daily and
11831
07:20:02,558 --> 07:20:05,760
the basis here we need to sum it again
11832
07:20:05,760 --> 07:20:08,000
and here again as you see here what is
11833
07:20:08,000 --> 07:20:09,920
it we need to sum we only need to we're
11834
07:20:09,920 --> 07:20:11,920
only interested in the sale here so
11835
07:20:11,920 --> 07:20:13,680
again we can just
11836
07:20:13,680 --> 07:20:16,558
isolate it with writing sale here okay
11837
07:20:16,558 --> 07:20:18,558
so now we have the sale by month but
11838
07:20:18,558 --> 07:20:20,638
again you see here now we have the end
11839
07:20:20,638 --> 07:20:24,240
of month date here from 2020
11840
07:20:24,240 --> 07:20:26,798
so if we put it here let's call it
11841
07:20:26,798 --> 07:20:29,360
monthly
11842
07:20:29,760 --> 07:20:30,798
monthly
11843
07:20:30,798 --> 07:20:32,160
sale
11844
07:20:32,160 --> 07:20:33,520
put it here
11845
07:20:33,520 --> 07:20:36,320
then we can actually change the name of
11846
07:20:36,320 --> 07:20:38,958
the index
11847
07:20:38,958 --> 07:20:41,920
monthly sale here index here and then we
11848
07:20:41,920 --> 07:20:45,920
set it to monthly sale index and how is
11849
07:20:45,920 --> 07:20:49,000
it called
11850
07:20:49,280 --> 07:20:50,160
month
11851
07:20:50,160 --> 07:20:52,878
name there we were
11852
07:20:52,878 --> 07:20:55,120
then we change it because now it looks
11853
07:20:55,120 --> 07:20:57,120
nicer as we see here
11854
07:20:57,120 --> 07:20:59,760
then we have for we know it's 2020 so
11855
07:20:59,760 --> 07:21:01,600
it's january until december right so you
11856
07:21:01,600 --> 07:21:03,520
can see which months
11857
07:21:03,520 --> 07:21:06,080
sold the most so as you see here when
11858
07:21:06,080 --> 07:21:07,840
you have it like this
11859
07:21:07,840 --> 07:21:10,958
it's not so easy to interpret or see
11860
07:21:10,958 --> 07:21:12,558
visually we're going to export it to
11861
07:21:12,558 --> 07:21:15,200
excel now here in the next one and in
11862
07:21:15,200 --> 07:21:16,798
the final part we're gonna actually
11863
07:21:16,798 --> 07:21:20,798
insert excel sheets excel charts in it
11864
07:21:20,798 --> 07:21:23,040
so you can see it more visually
11865
07:21:23,040 --> 07:21:25,040
good perfect
11866
07:21:25,040 --> 07:21:26,718
because here's the next one export the
11867
07:21:26,718 --> 07:21:28,558
data to excel right and we need to
11868
07:21:28,558 --> 07:21:31,120
export the sales rep and the monthly
11869
07:21:31,120 --> 07:21:32,478
let's do that
11870
07:21:32,478 --> 07:21:34,558
and we needed to use a excel writer
11871
07:21:34,558 --> 07:21:38,798
right so we called it workbook
11872
07:21:38,878 --> 07:21:40,240
and how do you do that
11873
07:21:40,240 --> 07:21:41,840
you had the pd
11874
07:21:41,840 --> 07:21:45,680
excel writer and did we have a name for
11875
07:21:45,680 --> 07:21:47,840
it i don't know
11876
07:21:47,840 --> 07:21:50,240
sales sales report we call it
11877
07:21:50,240 --> 07:21:51,200
perfect
11878
07:21:51,200 --> 07:21:53,120
works fine for me
11879
07:21:53,120 --> 07:21:55,440
and the first thing we need to do was to
11880
07:21:55,440 --> 07:21:58,958
export the wrap
11881
07:21:58,958 --> 07:22:01,200
reps sales to
11882
07:22:01,200 --> 07:22:02,240
excel
11883
07:22:02,240 --> 07:22:04,000
and we need the workbook and there was
11884
07:22:04,000 --> 07:22:05,520
one thing we needed to remember what was
11885
07:22:05,520 --> 07:22:08,718
that yes that's right the
11886
07:22:08,718 --> 07:22:10,478
sheet name
11887
07:22:10,478 --> 07:22:13,760
and we just call it the
11888
07:22:13,920 --> 07:22:15,280
sales
11889
07:22:15,280 --> 07:22:16,880
per rep
11890
07:22:16,880 --> 07:22:18,638
[Music]
11891
07:22:18,638 --> 07:22:20,878
as a long name
11892
07:22:20,878 --> 07:22:23,200
sales per rep
11893
07:22:23,200 --> 07:22:25,520
sales
11894
07:22:25,520 --> 07:22:27,840
per rep representative
11895
07:22:27,840 --> 07:22:29,280
we call it rep
11896
07:22:29,280 --> 07:22:32,398
i don't know we call it sales per rep
11897
07:22:32,398 --> 07:22:35,360
and then we need the monthly sale and we
11898
07:22:35,360 --> 07:22:38,140
do that to excel again
11899
07:22:38,140 --> 07:22:39,600
[Music]
11900
07:22:39,600 --> 07:22:42,080
and we have the workbook and the sheet
11901
07:22:42,080 --> 07:22:44,080
name
11902
07:22:44,080 --> 07:22:44,878
and
11903
07:22:44,878 --> 07:22:47,120
monthly
11904
07:22:47,120 --> 07:22:48,398
monthly here
11905
07:22:48,398 --> 07:22:50,878
perfect and then we take a workbook here
11906
07:22:50,878 --> 07:22:52,000
and we
11907
07:22:52,000 --> 07:22:53,280
close it
11908
07:22:53,280 --> 07:22:56,878
perfect so let's jump to
11909
07:22:56,878 --> 07:22:58,080
see here
11910
07:22:58,080 --> 07:23:00,240
the excel sheet how it looks like
11911
07:23:00,240 --> 07:23:02,000
so here we have it actually
11912
07:23:02,000 --> 07:23:03,840
we have all the sales rep here and we
11913
07:23:03,840 --> 07:23:06,398
can see the sales down there and here we
11914
07:23:06,398 --> 07:23:09,280
have the monthly data
11915
07:23:09,280 --> 07:23:11,360
and we can see down there so again as i
11916
07:23:11,360 --> 07:23:13,360
told you it's often easier to interpret
11917
07:23:13,360 --> 07:23:15,120
these results you may have a chart it
11918
07:23:15,120 --> 07:23:16,958
will easy to find the months that we're
11919
07:23:16,958 --> 07:23:18,878
doing well and the month they're doing
11920
07:23:18,878 --> 07:23:22,240
less good so actually let's do that and
11921
07:23:22,240 --> 07:23:25,120
we just do it in an extra one here
11922
07:23:25,120 --> 07:23:26,080
so
11923
07:23:26,080 --> 07:23:27,920
let me do that between here and remember
11924
07:23:27,920 --> 07:23:29,440
all the syntax
11925
07:23:29,440 --> 07:23:30,878
actually we wanted to
11926
07:23:30,878 --> 07:23:33,600
do something similar to this so let's
11927
07:23:33,600 --> 07:23:37,200
just try to copy that again
11928
07:23:37,200 --> 07:23:38,958
and we needed to
11929
07:23:38,958 --> 07:23:40,718
insert
11930
07:23:40,718 --> 07:23:42,398
chart
11931
07:23:42,398 --> 07:23:45,120
so let's do that and remember we needed
11932
07:23:45,120 --> 07:23:46,958
the
11933
07:23:46,958 --> 07:23:49,690
book here
11934
07:23:49,690 --> 07:23:51,120
[Music]
11935
07:23:51,120 --> 07:23:52,558
and
11936
07:23:52,558 --> 07:23:53,440
then
11937
07:23:53,440 --> 07:23:55,840
we need
11938
07:23:57,360 --> 07:24:00,398
to add a chart here
11939
07:24:01,200 --> 07:24:03,440
and we need to modify so in the first
11940
07:24:03,440 --> 07:24:05,360
one here we need to take this long name
11941
07:24:05,360 --> 07:24:07,120
here that's why i was
11942
07:24:07,120 --> 07:24:08,638
okay this one we didn't want to change
11943
07:24:08,638 --> 07:24:10,478
queen change this one here and this one
11944
07:24:10,478 --> 07:24:12,798
here here we just write it exactly it's
11945
07:24:12,798 --> 07:24:14,000
just
11946
07:24:14,000 --> 07:24:15,840
sales
11947
07:24:15,840 --> 07:24:17,360
per rep
11948
07:24:17,360 --> 07:24:20,160
right and then we need to look at what
11949
07:24:20,160 --> 07:24:21,200
is the
11950
07:24:21,200 --> 07:24:23,040
first and last i actually don't know how
11951
07:24:23,040 --> 07:24:25,760
many were there
11952
07:24:26,638 --> 07:24:30,840
so we have down here it is a 10
11953
07:24:30,840 --> 07:24:34,320
right a10 and then this one here we have
11954
07:24:34,320 --> 07:24:37,600
down in 13 obviously
11955
07:24:41,520 --> 07:24:43,520
so that's the first one and we also need
11956
07:24:43,520 --> 07:24:47,240
to insert it
11957
07:24:49,280 --> 07:24:51,920
insert it
11958
07:24:56,320 --> 07:24:59,600
we're not using these offsets thing here
11959
07:24:59,600 --> 07:25:02,478
so the work
11960
07:25:02,478 --> 07:25:03,440
book
11961
07:25:03,440 --> 07:25:06,440
sheets
11962
07:25:09,280 --> 07:25:12,320
and we're just inserting the chart here
11963
07:25:12,320 --> 07:25:13,120
and
11964
07:25:13,120 --> 07:25:16,958
we insert it in this one here
11965
07:25:16,958 --> 07:25:18,878
and uh we're going to do the same once
11966
07:25:18,878 --> 07:25:20,320
more here but we're going to do it on
11967
07:25:20,320 --> 07:25:22,080
this
11968
07:25:22,080 --> 07:25:23,760
different
11969
07:25:23,760 --> 07:25:26,000
one here so instead of sales rep we're
11970
07:25:26,000 --> 07:25:29,440
going to take the monthly year
11971
07:25:31,040 --> 07:25:34,398
monthly sales
11972
07:25:35,600 --> 07:25:39,440
and it's going to be 13 instead
11973
07:25:40,398 --> 07:25:42,638
and 13 instead
11974
07:25:42,638 --> 07:25:44,320
and we're going to insert it in monthly
11975
07:25:44,320 --> 07:25:47,200
instead right
11976
07:25:48,080 --> 07:25:51,120
so so far so good so this is actually it
11977
07:25:51,120 --> 07:25:52,638
let's try to execute it and it says
11978
07:25:52,638 --> 07:25:53,600
error
11979
07:25:53,600 --> 07:25:56,958
and it says sheet name
11980
07:25:56,958 --> 07:26:00,958
contains spaces but isn't quoted
11981
07:26:01,760 --> 07:26:03,680
so you cannot have spaces and sheet
11982
07:26:03,680 --> 07:26:06,160
names without having oh we need to quote
11983
07:26:06,160 --> 07:26:07,440
that
11984
07:26:07,440 --> 07:26:08,510
okay
11985
07:26:08,510 --> 07:26:11,720
[Music]
11986
07:26:14,320 --> 07:26:16,000
we learn something along the way all the
11987
07:26:16,000 --> 07:26:18,320
time
11988
07:26:21,120 --> 07:26:23,200
do how many places do we need to quote
11989
07:26:23,200 --> 07:26:24,638
this
11990
07:26:24,638 --> 07:26:26,320
i don't know
11991
07:26:26,320 --> 07:26:28,160
it seems to be fine just to quote it
11992
07:26:28,160 --> 07:26:31,280
there let's look if it went fine it
11993
07:26:31,280 --> 07:26:32,878
actually looks so right
11994
07:26:32,878 --> 07:26:35,680
so now you see it's more way more faster
11995
07:26:35,680 --> 07:26:36,798
to
11996
07:26:36,798 --> 07:26:39,120
see how people are performing like ethan
11997
07:26:39,120 --> 07:26:41,280
here well is that good enough i'm not
11998
07:26:41,280 --> 07:26:42,878
the one to tell if it's good enough or
11999
07:26:42,878 --> 07:26:47,280
not but you see you get a more visual
12000
07:26:47,280 --> 07:26:49,760
faster visual here and this one here you
12001
07:26:49,760 --> 07:26:53,040
see again how the month going so you see
12002
07:26:53,040 --> 07:26:56,160
january is nice february is low and then
12003
07:26:56,160 --> 07:26:57,840
may is not good but actually in the
12004
07:26:57,840 --> 07:27:00,160
summer it does pretty well here and so
12005
07:27:00,160 --> 07:27:02,160
forth here so you see it's
12006
07:27:02,160 --> 07:27:03,440
you have some good monsters and bad
12007
07:27:03,440 --> 07:27:05,280
months
12008
07:27:05,280 --> 07:27:08,000
so far so good so this is basically what
12009
07:27:08,000 --> 07:27:11,280
i wanted to show you with this sheet
12010
07:27:11,280 --> 07:27:13,040
here
12011
07:27:13,040 --> 07:27:15,200
there was a small detail here right but
12012
07:27:15,200 --> 07:27:17,120
as you see that
12013
07:27:17,120 --> 07:27:19,040
it writes back to you what you should
12014
07:27:19,040 --> 07:27:21,120
change and
12015
07:27:21,120 --> 07:27:23,200
you should quote
12016
07:27:23,200 --> 07:27:24,558
these things here
12017
07:27:24,558 --> 07:27:27,120
well i didn't remember that by hard
12018
07:27:27,120 --> 07:27:29,360
could i see it here in the manual here
12019
07:27:29,360 --> 07:27:31,840
they have examples where it's not done
12020
07:27:31,840 --> 07:27:34,558
right so if you encounter a problem like
12021
07:27:34,558 --> 07:27:36,320
that and you don't know what it says to
12022
07:27:36,320 --> 07:27:38,000
you you know sometimes
12023
07:27:38,000 --> 07:27:40,798
return messages error messages are
12024
07:27:40,798 --> 07:27:42,478
difficult to understand so what should
12025
07:27:42,478 --> 07:27:45,040
you do well try to make that exact same
12026
07:27:45,040 --> 07:27:47,840
example like they're doing here and then
12027
07:27:47,840 --> 07:27:50,638
change it step by step until you come to
12028
07:27:50,638 --> 07:27:53,760
your example right and then you'll see
12029
07:27:53,760 --> 07:27:55,360
which step does something wrong and then
12030
07:27:55,360 --> 07:27:57,120
you figure out which
12031
07:27:57,120 --> 07:27:58,878
you know where the error is because
12032
07:27:58,878 --> 07:28:00,478
sometimes i know it can be difficult to
12033
07:28:00,478 --> 07:28:03,360
read oh this is where the error was this
12034
07:28:03,360 --> 07:28:05,840
is what it's saying to you right
12035
07:28:05,840 --> 07:28:08,478
perfect so are you excited about this i
12036
07:28:08,478 --> 07:28:10,878
think so this is a great project so uh
12037
07:28:10,878 --> 07:28:12,320
in the next one we're gonna start with
12038
07:28:12,320 --> 07:28:14,000
the capstone project where we're gonna
12039
07:28:14,000 --> 07:28:15,440
create our own
12040
07:28:15,440 --> 07:28:17,360
our own
12041
07:28:17,360 --> 07:28:21,040
machine learning model and we're gonna
12042
07:28:21,040 --> 07:28:23,600
programming program it from scratch it's
12043
07:28:23,600 --> 07:28:25,840
gonna be amazing i'll promise you that
12044
07:28:25,840 --> 07:28:29,240
see you in a moment
12045
07:28:31,360 --> 07:28:33,840
the capstone project of this course are
12046
07:28:33,840 --> 07:28:36,000
you ready i hope so because this is
12047
07:28:36,000 --> 07:28:38,398
exciting so i promised you we are going
12048
07:28:38,398 --> 07:28:41,520
to create or build our own machine
12049
07:28:41,520 --> 07:28:43,200
learning model from scratch and you know
12050
07:28:43,200 --> 07:28:44,958
what i'm going to keep that promise to
12051
07:28:44,958 --> 07:28:47,520
you and so in this lesson here we're
12052
07:28:47,520 --> 07:28:50,000
going to learn about reinforcement
12053
07:28:50,000 --> 07:28:52,240
learning which is a machine learning
12054
07:28:52,240 --> 07:28:54,558
model we're going to use or build
12055
07:28:54,558 --> 07:28:57,040
so to break it a bit down the structure
12056
07:28:57,040 --> 07:29:00,000
will be first we'll understand what is
12057
07:29:00,000 --> 07:29:02,878
reinforcement learning how does it work
12058
07:29:02,878 --> 07:29:05,200
and the second step is well what is the
12059
07:29:05,200 --> 07:29:07,440
problem we want to solve simply said
12060
07:29:07,440 --> 07:29:08,958
it's a problem of
12061
07:29:08,958 --> 07:29:10,718
if you were let's say you're a cab
12062
07:29:10,718 --> 07:29:13,680
driver you drive around in your cab
12063
07:29:13,680 --> 07:29:15,760
and you need to pick something up and
12064
07:29:15,760 --> 07:29:17,680
you need to drop it off
12065
07:29:17,680 --> 07:29:19,680
you don't know where to pick it up and
12066
07:29:19,680 --> 07:29:22,000
you don't know where to drop it off but
12067
07:29:22,000 --> 07:29:23,440
you will learn along the way right so
12068
07:29:23,440 --> 07:29:25,760
you just do random things and with this
12069
07:29:25,760 --> 07:29:28,398
random behavior you learn
12070
07:29:28,398 --> 07:29:32,160
by reward and punishment it's called but
12071
07:29:32,160 --> 07:29:33,600
basically you do something you get a
12072
07:29:33,600 --> 07:29:35,600
kind of reward it can be positive or
12073
07:29:35,600 --> 07:29:38,798
negative and based on that you learn how
12074
07:29:38,798 --> 07:29:42,080
to behave more smart and we will measure
12075
07:29:42,080 --> 07:29:43,760
that so that's a problem you want to
12076
07:29:43,760 --> 07:29:46,558
solve so how do you model that so we're
12077
07:29:46,558 --> 07:29:48,718
gonna in the second step there we're
12078
07:29:48,718 --> 07:29:51,360
gonna implement the field source a where
12079
07:29:51,360 --> 07:29:54,000
we do the processing so that's the
12080
07:29:54,000 --> 07:29:56,798
second step then on the
12081
07:29:56,798 --> 07:29:58,798
third step we're going to implement the
12082
07:29:58,798 --> 07:30:01,680
naive solution right so if we only did
12083
07:30:01,680 --> 07:30:03,840
random things how would that perform so
12084
07:30:03,840 --> 07:30:05,840
we have some base cases so if you do
12085
07:30:05,840 --> 07:30:07,600
random behavior how does it perform
12086
07:30:07,600 --> 07:30:09,440
right you need that so after we
12087
07:30:09,440 --> 07:30:11,200
implemented the naive solution we need
12088
07:30:11,200 --> 07:30:13,680
to figure out how can we map the world
12089
07:30:13,680 --> 07:30:16,240
we're living in into the model we're
12090
07:30:16,240 --> 07:30:17,920
living in right the model we need to
12091
07:30:17,920 --> 07:30:19,760
create so that's going to be how do you
12092
07:30:19,760 --> 07:30:21,680
map from the world
12093
07:30:21,680 --> 07:30:24,398
to the model so that's kind of like the
12094
07:30:24,398 --> 07:30:26,638
cue table it's called how do you map
12095
07:30:26,638 --> 07:30:29,040
from the world into the queue table the
12096
07:30:29,040 --> 07:30:30,558
states of the queue table don't worry
12097
07:30:30,558 --> 07:30:33,200
about what it is we'll get there and
12098
07:30:33,200 --> 07:30:36,000
then we'll look at how do you do this
12099
07:30:36,000 --> 07:30:38,320
learning process it's called q learning
12100
07:30:38,320 --> 07:30:40,080
the model we're going to implement how
12101
07:30:40,080 --> 07:30:42,320
do you do that so that's just
12102
07:30:42,320 --> 07:30:44,160
another step so finally when we
12103
07:30:44,160 --> 07:30:46,478
implemented that we train the model and
12104
07:30:46,478 --> 07:30:47,520
then we
12105
07:30:47,520 --> 07:30:49,840
will evaluate how it works right so we
12106
07:30:49,840 --> 07:30:51,920
train it and then we evaluate and the
12107
07:30:51,920 --> 07:30:54,638
evaluation is going to compare it to
12108
07:30:54,638 --> 07:30:55,680
the
12109
07:30:55,680 --> 07:30:57,600
the naive solution it will be surprised
12110
07:30:57,600 --> 07:30:59,200
how good it is so it's going to be
12111
07:30:59,200 --> 07:31:01,440
amazing so are you ready for all this i
12112
07:31:01,440 --> 07:31:03,760
hope so so in the next one we're gonna
12113
07:31:03,760 --> 07:31:05,520
learn about what is
12114
07:31:05,520 --> 07:31:07,680
reinforcement learning okay learn about
12115
07:31:07,680 --> 07:31:09,520
reinforcement learning sounds awesome
12116
07:31:09,520 --> 07:31:12,160
see you in a moment
12117
07:31:14,718 --> 07:31:16,638
so here we are in our jupyter notebook
12118
07:31:16,638 --> 07:31:17,840
and you see here there's a lot of
12119
07:31:17,840 --> 07:31:19,840
descriptions so let's walk through that
12120
07:31:19,840 --> 07:31:20,958
and see
12121
07:31:20,958 --> 07:31:23,360
how where we end that okay so the goal
12122
07:31:23,360 --> 07:31:26,160
of this one is to understand what is
12123
07:31:26,160 --> 07:31:29,200
reinforcement learning right
12124
07:31:29,200 --> 07:31:31,120
so
12125
07:31:31,120 --> 07:31:33,040
in the project in general we're going to
12126
07:31:33,040 --> 07:31:35,200
use object-oriented programming but
12127
07:31:35,200 --> 07:31:37,200
we're not going to talk about this quite
12128
07:31:37,200 --> 07:31:39,440
yet what we want to do is to build our
12129
07:31:39,440 --> 07:31:41,360
own machine learning model from scratch
12130
07:31:41,360 --> 07:31:43,840
which is the reinforcement learning
12131
07:31:43,840 --> 07:31:45,760
here
12132
07:31:45,760 --> 07:31:46,638
so
12133
07:31:46,638 --> 07:31:48,160
they will teach how to pick up and
12134
07:31:48,160 --> 07:31:50,478
deliver items just like the cab driver i
12135
07:31:50,478 --> 07:31:53,440
told about but the goal of this part
12136
07:31:53,440 --> 07:31:55,440
here is to learn what is reinforcement
12137
07:31:55,440 --> 07:31:57,040
learning
12138
07:31:57,040 --> 07:31:58,080
so
12139
07:31:58,080 --> 07:31:59,040
i'm a bit
12140
07:31:59,040 --> 07:32:01,120
a bit mixed about this picture actually
12141
07:32:01,120 --> 07:32:03,680
because this kind of uh
12142
07:32:03,680 --> 07:32:06,240
it kind of shows a world where you get
12143
07:32:06,240 --> 07:32:08,398
reward and a punishment but this is
12144
07:32:08,398 --> 07:32:10,240
basically the easiest way to understand
12145
07:32:10,240 --> 07:32:11,760
it right so
12146
07:32:11,760 --> 07:32:14,718
what we want to do is create a reality
12147
07:32:14,718 --> 07:32:15,680
where
12148
07:32:15,680 --> 07:32:18,160
where we have some data learning and
12149
07:32:18,160 --> 07:32:20,240
we'll do an action
12150
07:32:20,240 --> 07:32:22,080
and that action will either give you a
12151
07:32:22,080 --> 07:32:24,160
reward or a punishment and there will be
12152
07:32:24,160 --> 07:32:26,398
the feedback all the time right so how
12153
07:32:26,398 --> 07:32:29,120
they often explain this one is uh
12154
07:32:29,120 --> 07:32:31,200
think of a dog right how do you train a
12155
07:32:31,200 --> 07:32:32,398
dog
12156
07:32:32,398 --> 07:32:33,760
so a dog
12157
07:32:33,760 --> 07:32:34,478
you
12158
07:32:34,478 --> 07:32:37,600
if the dog is making behavior and that
12159
07:32:37,600 --> 07:32:40,160
you appreciate you will reward it right
12160
07:32:40,160 --> 07:32:42,558
but if the dog doesn't do what you want
12161
07:32:42,558 --> 07:32:43,600
you might
12162
07:32:43,600 --> 07:32:45,440
not reward it right so this is where
12163
07:32:45,440 --> 07:32:47,360
like classically you say you will punish
12164
07:32:47,360 --> 07:32:49,440
it right but i don't encourage
12165
07:32:49,440 --> 07:32:51,360
punishment of anything so
12166
07:32:51,360 --> 07:32:53,280
don't don't don't
12167
07:32:53,280 --> 07:32:55,120
don't hear like that but just find it
12168
07:32:55,120 --> 07:32:57,600
easy to understand that yes you can have
12169
07:32:57,600 --> 07:32:59,680
if you do good behavior you get reward
12170
07:32:59,680 --> 07:33:02,160
if you have bad behavior that is not
12171
07:33:02,160 --> 07:33:04,558
appreciated well you don't get a reward
12172
07:33:04,558 --> 07:33:07,040
or you get punishment so this is easy to
12173
07:33:07,040 --> 07:33:09,440
understand right reward good so you get
12174
07:33:09,440 --> 07:33:12,638
a feedback and you will by nature do
12175
07:33:12,638 --> 07:33:15,040
things where you get a reward right it's
12176
07:33:15,040 --> 07:33:16,718
just like in a job market if you get a
12177
07:33:16,718 --> 07:33:18,160
salary for what you're doing you like
12178
07:33:18,160 --> 07:33:19,440
doing it because you like the money
12179
07:33:19,440 --> 07:33:21,040
right you get more money if you do
12180
07:33:21,040 --> 07:33:22,798
something really good you get a bonus so
12181
07:33:22,798 --> 07:33:24,718
you get more money and you
12182
07:33:24,718 --> 07:33:26,398
you would in the future do something
12183
07:33:26,398 --> 07:33:30,558
similar so it reinforces reinforces this
12184
07:33:30,558 --> 07:33:32,160
behavior right
12185
07:33:32,160 --> 07:33:34,798
so this is reinforcement learning right
12186
07:33:34,798 --> 07:33:36,958
it's just a principle of understanding
12187
07:33:36,958 --> 07:33:38,240
if you do something good you get a
12188
07:33:38,240 --> 07:33:40,398
reward if you do something which is not
12189
07:33:40,398 --> 07:33:43,040
accepted or not wanted well you get a
12190
07:33:43,040 --> 07:33:45,680
punishment so say right so this is the
12191
07:33:45,680 --> 07:33:48,478
feedback and often actually they don't
12192
07:33:48,478 --> 07:33:50,638
use the terminology punishment anymore
12193
07:33:50,638 --> 07:33:52,000
just call reward it will just be a
12194
07:33:52,000 --> 07:33:54,398
negative reward right but it's easy to
12195
07:33:54,398 --> 07:33:55,920
understand that something good something
12196
07:33:55,920 --> 07:33:58,878
bad and the reward can also be measured
12197
07:33:58,878 --> 07:34:01,120
in a level so it could be
12198
07:34:01,120 --> 07:34:03,520
just be a number so it's a the feedback
12199
07:34:03,520 --> 07:34:05,120
is just a number
12200
07:34:05,120 --> 07:34:06,878
if it's positive it's rewarded it's
12201
07:34:06,878 --> 07:34:09,120
negative it's a punishment right so this
12202
07:34:09,120 --> 07:34:10,878
is how it works right data learning
12203
07:34:10,878 --> 07:34:14,958
right so you understand the concept now
12204
07:34:14,958 --> 07:34:16,478
so
12205
07:34:16,478 --> 07:34:20,638
if we talk as a dog here right
12206
07:34:20,638 --> 07:34:23,760
it's like training a dog right so
12207
07:34:23,760 --> 07:34:26,000
the dog doesn't talk the same language
12208
07:34:26,000 --> 07:34:27,760
as you just like the
12209
07:34:27,760 --> 07:34:29,440
machine learning model
12210
07:34:29,440 --> 07:34:30,798
so
12211
07:34:30,798 --> 07:34:33,440
how you're training a dog is based on
12212
07:34:33,440 --> 07:34:36,240
this reward and punishment right
12213
07:34:36,240 --> 07:34:37,600
and uh
12214
07:34:37,600 --> 07:34:38,958
this is the same action as i talked
12215
07:34:38,958 --> 07:34:41,760
about in our terminology here we use the
12216
07:34:41,760 --> 07:34:44,080
agent is a dog right so this is the one
12217
07:34:44,080 --> 07:34:45,600
we want to train we want to train the
12218
07:34:45,600 --> 07:34:48,160
agent and it exposed to an environment
12219
07:34:48,160 --> 07:34:50,000
and this agent encounters a state in
12220
07:34:50,000 --> 07:34:52,718
this environment and performs an action
12221
07:34:52,718 --> 07:34:54,558
based on that state to come into a new
12222
07:34:54,558 --> 07:34:58,478
state if you want if you want to go from
12223
07:34:58,478 --> 07:35:00,000
this state to the new state you will
12224
07:35:00,000 --> 07:35:02,240
make a reward if you want don't want to
12225
07:35:02,240 --> 07:35:04,080
go into this new state you'll make a
12226
07:35:04,080 --> 07:35:06,398
penalty or a punishment right
12227
07:35:06,398 --> 07:35:09,120
so this forms a policy and
12228
07:35:09,120 --> 07:35:12,160
to create random to choose action for a
12229
07:35:12,160 --> 07:35:13,920
given state in the future right so this
12230
07:35:13,920 --> 07:35:16,638
is learning right so
12231
07:35:16,638 --> 07:35:18,878
think again like the dog it is exposed
12232
07:35:18,878 --> 07:35:20,718
in an environment the dog is in some
12233
07:35:20,718 --> 07:35:23,120
kind of state so the dog has to make a
12234
07:35:23,120 --> 07:35:24,718
choice should it
12235
07:35:24,718 --> 07:35:27,040
bark or should not bark if it barks you
12236
07:35:27,040 --> 07:35:29,120
don't get happy if it not barks you get
12237
07:35:29,120 --> 07:35:31,140
happy right so you reward it or you
12238
07:35:31,140 --> 07:35:33,440
[Music]
12239
07:35:33,440 --> 07:35:35,440
make a negative reward
12240
07:35:35,440 --> 07:35:36,558
and uh
12241
07:35:36,558 --> 07:35:38,080
based on that right
12242
07:35:38,080 --> 07:35:40,240
perfect so that's that's the idea behind
12243
07:35:40,240 --> 07:35:40,958
it
12244
07:35:40,958 --> 07:35:43,120
so what is a re there are different
12245
07:35:43,120 --> 07:35:44,878
algorithms used for reinforcement
12246
07:35:44,878 --> 07:35:46,160
learning i'm not going to go into all
12247
07:35:46,160 --> 07:35:47,840
these here but these are the three main
12248
07:35:47,840 --> 07:35:49,600
ones and we are only going to focus on q
12249
07:35:49,600 --> 07:35:51,840
learning and it's a model free and
12250
07:35:51,840 --> 07:35:53,920
reinforcement learning model to learn a
12251
07:35:53,920 --> 07:35:56,320
policy telling an agent what action to
12252
07:35:56,320 --> 07:35:58,398
take under what circumstances so this is
12253
07:35:58,398 --> 07:36:00,160
the one we're going to focus on and you
12254
07:36:00,160 --> 07:36:01,520
can read a bit more about the other ones
12255
07:36:01,520 --> 07:36:04,000
if you want to
12256
07:36:04,000 --> 07:36:04,798
so
12257
07:36:04,798 --> 07:36:06,160
this is it
12258
07:36:06,160 --> 07:36:07,040
so
12259
07:36:07,040 --> 07:36:09,680
we have a q learning or a queue table
12260
07:36:09,680 --> 07:36:10,558
here
12261
07:36:10,558 --> 07:36:12,398
and this is basically just a table
12262
07:36:12,398 --> 07:36:14,000
showing you if you're in this state what
12263
07:36:14,000 --> 07:36:15,280
to do right
12264
07:36:15,280 --> 07:36:16,240
so
12265
07:36:16,240 --> 07:36:18,000
what do you do
12266
07:36:18,000 --> 07:36:19,840
what do you do right
12267
07:36:19,840 --> 07:36:21,120
so
12268
07:36:21,120 --> 07:36:23,600
you have two choices in the queue
12269
07:36:23,600 --> 07:36:24,718
learning
12270
07:36:24,718 --> 07:36:27,600
model paradigm and dime either you
12271
07:36:27,600 --> 07:36:29,920
exploit that is you choose the best
12272
07:36:29,920 --> 07:36:32,080
action you know so far and then you
12273
07:36:32,080 --> 07:36:33,760
update the queue table based on the
12274
07:36:33,760 --> 07:36:35,440
feedback right because every time you
12275
07:36:35,440 --> 07:36:37,920
make an action make a choice and then
12276
07:36:37,920 --> 07:36:39,440
you get a feedback then you get
12277
07:36:39,440 --> 07:36:41,200
something back positive or negative
12278
07:36:41,200 --> 07:36:42,878
right that's a feedback then you update
12279
07:36:42,878 --> 07:36:44,638
it based on that action
12280
07:36:44,638 --> 07:36:46,958
so let's exploit but
12281
07:36:46,958 --> 07:36:48,320
as you probably know if you don't do
12282
07:36:48,320 --> 07:36:50,320
anything new once in a while you'll
12283
07:36:50,320 --> 07:36:52,160
you'll get patterns that might not be
12284
07:36:52,160 --> 07:36:54,398
optimal so there's something called
12285
07:36:54,398 --> 07:36:56,558
explore and then you make a random
12286
07:36:56,558 --> 07:36:58,718
action and based on that random action
12287
07:36:58,718 --> 07:37:00,160
you also get feedback and you update the
12288
07:37:00,160 --> 07:37:02,080
queue table right
12289
07:37:02,080 --> 07:37:04,638
so imagine you always only done one type
12290
07:37:04,638 --> 07:37:06,840
of action in a specific
12291
07:37:06,840 --> 07:37:11,600
state for instance let's say that
12292
07:37:11,600 --> 07:37:13,920
so let's let's assume you're a dog right
12293
07:37:13,920 --> 07:37:15,680
and in the case you
12294
07:37:15,680 --> 07:37:19,200
when a visitor comes to your home you do
12295
07:37:19,200 --> 07:37:21,680
either you only try to do two things
12296
07:37:21,680 --> 07:37:24,320
right either you bark then your owner
12297
07:37:24,320 --> 07:37:26,798
doesn't get happy so you don't get a
12298
07:37:26,798 --> 07:37:29,200
positive reward or then you learn that
12299
07:37:29,200 --> 07:37:31,040
you jump up on people and lick them in
12300
07:37:31,040 --> 07:37:34,878
their face and then the dog owner did
12301
07:37:34,878 --> 07:37:37,360
nothing right it was just a
12302
07:37:37,360 --> 07:37:39,520
neutral reward right so it's better than
12303
07:37:39,520 --> 07:37:41,360
the other reward right so what you'll
12304
07:37:41,360 --> 07:37:43,440
learn from this is well you should jump
12305
07:37:43,440 --> 07:37:45,280
up of people and dick them in their head
12306
07:37:45,280 --> 07:37:46,958
all right it's kind of awkward but
12307
07:37:46,958 --> 07:37:48,558
that's what dog deals right
12308
07:37:48,558 --> 07:37:49,520
and
12309
07:37:49,520 --> 07:37:51,200
if you never did anything random that
12310
07:37:51,200 --> 07:37:52,958
will be the conclusion you had because
12311
07:37:52,958 --> 07:37:55,200
you only tried these two things so by
12312
07:37:55,200 --> 07:37:56,958
doing something random it could be not
12313
07:37:56,958 --> 07:37:59,440
jump up just stay passive and in this
12314
07:37:59,440 --> 07:38:01,040
case maybe the owner was like wow that
12315
07:38:01,040 --> 07:38:02,638
was really nice i really appreciate you
12316
07:38:02,638 --> 07:38:04,398
don't jump up of people
12317
07:38:04,398 --> 07:38:05,360
when
12318
07:38:05,360 --> 07:38:07,280
people come into my house and then you
12319
07:38:07,280 --> 07:38:10,080
would reward it even more right so that
12320
07:38:10,080 --> 07:38:13,120
action actually creates a more positive
12321
07:38:13,120 --> 07:38:15,280
feedback loop than
12322
07:38:15,280 --> 07:38:17,040
jumping up of people licking them even
12323
07:38:17,040 --> 07:38:18,478
though
12324
07:38:18,478 --> 07:38:20,240
that was better than barking when people
12325
07:38:20,240 --> 07:38:22,320
came right so in this sense if you do
12326
07:38:22,320 --> 07:38:25,200
something random you find new patterns
12327
07:38:25,200 --> 07:38:27,520
that are even more appreciated in the
12328
07:38:27,520 --> 07:38:29,360
circumstances right so this is why you
12329
07:38:29,360 --> 07:38:31,200
need this random action do something
12330
07:38:31,200 --> 07:38:32,398
random right
12331
07:38:32,398 --> 07:38:33,440
okay
12332
07:38:33,440 --> 07:38:35,040
so let's just
12333
07:38:35,040 --> 07:38:37,120
see what it says here q algorithm is
12334
07:38:37,120 --> 07:38:39,760
basically a q table so it's a big table
12335
07:38:39,760 --> 07:38:41,120
it's a matrix if you don't know what it
12336
07:38:41,120 --> 07:38:43,600
is it's just a big table of entries
12337
07:38:43,600 --> 07:38:45,360
and don't worry if you don't know what
12338
07:38:45,360 --> 07:38:48,558
it is and the agent the q learning
12339
07:38:48,558 --> 07:38:50,798
algorithm will be in a state right and
12340
07:38:50,798 --> 07:38:53,120
then in each iteration agent needs to
12341
07:38:53,120 --> 07:38:54,958
take an action right so that means you
12342
07:38:54,958 --> 07:38:56,798
need to do something right you come in a
12343
07:38:56,798 --> 07:38:58,878
state you need to take an action and the
12344
07:38:58,878 --> 07:39:00,398
agent will continuously update the
12345
07:39:00,398 --> 07:39:02,558
reward in the queue table right the
12346
07:39:02,558 --> 07:39:04,798
learning can come from either exploring
12347
07:39:04,798 --> 07:39:06,638
exploiting or exploring that's what we
12348
07:39:06,638 --> 07:39:08,718
talked about this translated into the
12349
07:39:08,718 --> 07:39:10,638
following pseudo algorithm and eq
12350
07:39:10,638 --> 07:39:12,160
learning the agent is giving in the
12351
07:39:12,160 --> 07:39:13,520
state and needs to choose an action
12352
07:39:13,520 --> 07:39:15,120
right
12353
07:39:15,120 --> 07:39:16,558
so this is actually the algorithm and it
12354
07:39:16,558 --> 07:39:18,638
can be a bit tricky to see here but this
12355
07:39:18,638 --> 07:39:20,160
is what we're going to implement a bit
12356
07:39:20,160 --> 07:39:21,520
later don't worry about this now because
12357
07:39:21,520 --> 07:39:22,638
we're going to do a lot of things that
12358
07:39:22,638 --> 07:39:24,958
are way easier than this first
12359
07:39:24,958 --> 07:39:27,760
but we initialize the q table to all
12360
07:39:27,760 --> 07:39:28,878
zeros
12361
07:39:28,878 --> 07:39:30,478
and
12362
07:39:30,478 --> 07:39:33,040
then we iterate in each
12363
07:39:33,040 --> 07:39:34,558
this is a description of the algorithm
12364
07:39:34,558 --> 07:39:36,558
above right then we iterate
12365
07:39:36,558 --> 07:39:41,798
so this q table here means just
12366
07:39:42,160 --> 07:39:44,798
a entry for each state
12367
07:39:44,798 --> 07:39:49,040
and uh for each possible action right
12368
07:39:49,040 --> 07:39:50,958
so the agent is in the state with
12369
07:39:50,958 --> 07:39:53,840
probability epsilon we will explore
12370
07:39:53,840 --> 07:39:55,520
else exploit right so we take some
12371
07:39:55,520 --> 07:39:57,440
probability we explore
12372
07:39:57,440 --> 07:40:00,398
that means we take if we explore we take
12373
07:40:00,398 --> 07:40:02,478
random if we exploit we take best action
12374
07:40:02,478 --> 07:40:04,558
right
12375
07:40:04,558 --> 07:40:06,718
and that's what it says down here and uh
12376
07:40:06,718 --> 07:40:08,320
if you take explore we take a random
12377
07:40:08,320 --> 07:40:10,558
action of the action possible and then
12378
07:40:10,558 --> 07:40:12,878
we exploit we take the best action based
12379
07:40:12,878 --> 07:40:14,878
on the current queue table
12380
07:40:14,878 --> 07:40:16,558
then afterwards we update the queue
12381
07:40:16,558 --> 07:40:18,398
table based on the new reward from the
12382
07:40:18,398 --> 07:40:20,160
previous state and this is the formula
12383
07:40:20,160 --> 07:40:22,000
for that right so the queue state we
12384
07:40:22,000 --> 07:40:24,558
took this action then we calculate a new
12385
07:40:24,558 --> 07:40:26,478
value based on this formula don't worry
12386
07:40:26,478 --> 07:40:28,398
about it we'll implement it and you'll
12387
07:40:28,398 --> 07:40:29,920
see how it works
12388
07:40:29,920 --> 07:40:31,760
so you see here in the above here
12389
07:40:31,760 --> 07:40:33,280
there's some new variables right we have
12390
07:40:33,280 --> 07:40:35,040
epsilon which is the probability of the
12391
07:40:35,040 --> 07:40:37,120
random action
12392
07:40:37,120 --> 07:40:39,360
to explore new territory as we talked
12393
07:40:39,360 --> 07:40:41,840
about then the alpha is a learning rate
12394
07:40:41,840 --> 07:40:43,840
of the algorithm this is this alpha here
12395
07:40:43,840 --> 07:40:45,760
and this is how much we learned from
12396
07:40:45,760 --> 07:40:48,240
previous action so this is a parameter
12397
07:40:48,240 --> 07:40:50,478
you can turn right and then the gamma is
12398
07:40:50,478 --> 07:40:52,320
this discount factor of used to balance
12399
07:40:52,320 --> 07:40:54,398
the intermediate and future reward right
12400
07:40:54,398 --> 07:40:56,478
and then the reward is a feedback action
12401
07:40:56,478 --> 07:40:57,280
of
12402
07:40:57,280 --> 07:40:58,718
any number
12403
07:40:58,718 --> 07:41:00,320
it can be negative as penalty or
12404
07:41:00,320 --> 07:41:02,478
positive as reward right
12405
07:41:02,478 --> 07:41:04,798
perfect so far so good so that was
12406
07:41:04,798 --> 07:41:08,478
actually the formula for this cycle here
12407
07:41:08,478 --> 07:41:10,398
right so we have the q table here with
12408
07:41:10,398 --> 07:41:13,040
all zeros if we take exploit we take the
12409
07:41:13,040 --> 07:41:16,958
best possible action from this state
12410
07:41:16,958 --> 07:41:18,718
and then we update the table based on
12411
07:41:18,718 --> 07:41:20,798
the formula below if we take explore we
12412
07:41:20,798 --> 07:41:22,718
take a random action and we update it
12413
07:41:22,718 --> 07:41:23,680
again
12414
07:41:23,680 --> 07:41:24,798
based on
12415
07:41:24,798 --> 07:41:28,478
this formula down here
12416
07:41:28,798 --> 07:41:31,200
okay so now to the description of the
12417
07:41:31,200 --> 07:41:34,000
task we need to solve right so now we
12418
07:41:34,000 --> 07:41:35,440
have the algorithm
12419
07:41:35,440 --> 07:41:37,920
now we need to describe what is we need
12420
07:41:37,920 --> 07:41:41,280
to solve so this is our universe right
12421
07:41:41,280 --> 07:41:43,280
we want to keep it simple so we create a
12422
07:41:43,280 --> 07:41:45,920
field of 10 times 10 positions right so
12423
07:41:45,920 --> 07:41:47,840
we have this board here it's like a ch
12424
07:41:47,840 --> 07:41:48,718
chess
12425
07:41:48,718 --> 07:41:50,478
board except we have
12426
07:41:50,478 --> 07:41:53,760
10 by 10 and not 8x8 right
12427
07:41:53,760 --> 07:41:55,280
in this field there is an item that
12428
07:41:55,280 --> 07:41:57,040
needs to be picked up and moved to the
12429
07:41:57,040 --> 07:41:58,878
drop-off point so
12430
07:41:58,878 --> 07:42:00,958
you are the carrier in this picture
12431
07:42:00,958 --> 07:42:02,718
right so you start here
12432
07:42:02,718 --> 07:42:07,520
in 0.9 right 0.9
12433
07:42:07,520 --> 07:42:08,958
then there's an item to be picked up
12434
07:42:08,958 --> 07:42:11,360
this is this item and you need to drop
12435
07:42:11,360 --> 07:42:13,680
it off down here right so
12436
07:42:13,680 --> 07:42:14,798
if you were
12437
07:42:14,798 --> 07:42:16,558
intelligent and you could see this field
12438
07:42:16,558 --> 07:42:18,478
here you would go over here pick this up
12439
07:42:18,478 --> 07:42:20,320
and drive down here
12440
07:42:20,320 --> 07:42:22,240
so the moves you can do is you can go
12441
07:42:22,240 --> 07:42:23,120
south
12442
07:42:23,120 --> 07:42:25,360
you can go north okay so south is down
12443
07:42:25,360 --> 07:42:26,558
north is up
12444
07:42:26,558 --> 07:42:29,280
you can go east
12445
07:42:29,280 --> 07:42:31,200
and you can go west and then you can
12446
07:42:31,200 --> 07:42:32,718
pick up item
12447
07:42:32,718 --> 07:42:35,280
and you can drop off item right so this
12448
07:42:35,280 --> 07:42:37,280
is a
12449
07:42:37,280 --> 07:42:38,798
this is like six
12450
07:42:38,798 --> 07:42:40,080
moves right
12451
07:42:40,080 --> 07:42:42,000
and uh of course there are some rules
12452
07:42:42,000 --> 07:42:43,840
about it you cannot go over the field
12453
07:42:43,840 --> 07:42:46,320
and if you pick up where this
12454
07:42:46,320 --> 07:42:48,160
where the item is not for instance if
12455
07:42:48,160 --> 07:42:50,240
you say here i want to pick up well you
12456
07:42:50,240 --> 07:42:51,920
can't pick it up because there's nothing
12457
07:42:51,920 --> 07:42:53,760
or if you drop it you picked it up
12458
07:42:53,760 --> 07:42:55,440
correctly and you drop it off
12459
07:42:55,440 --> 07:42:58,398
incorrectly you you can do everything in
12460
07:42:58,398 --> 07:43:01,200
every state right so you have these
12461
07:43:01,200 --> 07:43:02,320
six
12462
07:43:02,320 --> 07:43:04,878
actions here action zero go
12463
07:43:04,878 --> 07:43:07,200
south north east west pick up and drop
12464
07:43:07,200 --> 07:43:08,958
off
12465
07:43:08,958 --> 07:43:10,798
but we want to make some rules based on
12466
07:43:10,798 --> 07:43:12,160
that right and this is what we're going
12467
07:43:12,160 --> 07:43:15,040
to implement down below right so if the
12468
07:43:15,040 --> 07:43:17,360
agent tries to go off the field punished
12469
07:43:17,360 --> 07:43:20,080
by -10 in reward right so if for
12470
07:43:20,080 --> 07:43:23,280
instance we are here and we go
12471
07:43:23,280 --> 07:43:25,520
north that's up we're going outside the
12472
07:43:25,520 --> 07:43:27,760
field we get a punishment and we're not
12473
07:43:27,760 --> 07:43:29,760
going to let it go outside but we will
12474
07:43:29,760 --> 07:43:32,558
punish it by -10 right that's what it
12475
07:43:32,558 --> 07:43:34,320
says here
12476
07:43:34,320 --> 07:43:37,600
if the agent made a legal
12477
07:43:37,600 --> 07:43:40,160
move punished with -1 and reward as we
12478
07:43:40,160 --> 07:43:42,080
do not want to encourage endless walking
12479
07:43:42,080 --> 07:43:43,920
around right so this is it so even
12480
07:43:43,920 --> 07:43:46,798
though we move let's say we move
12481
07:43:46,798 --> 07:43:48,160
east here
12482
07:43:48,160 --> 07:43:50,558
in this direction it is punished by one
12483
07:43:50,558 --> 07:43:52,478
and the reason why we want to do that is
12484
07:43:52,478 --> 07:43:54,160
we want to minimize the steps we do
12485
07:43:54,160 --> 07:43:55,680
because if we
12486
07:43:55,680 --> 07:43:58,718
may positively reward it would find out
12487
07:43:58,718 --> 07:44:00,240
just walking around and makes a lot of
12488
07:44:00,240 --> 07:44:01,680
sense so we'll just walk around doing
12489
07:44:01,680 --> 07:44:03,600
nothing right so we want to minimize the
12490
07:44:03,600 --> 07:44:07,520
steps we're doing and we do that by -1
12491
07:44:07,520 --> 07:44:09,200
if the agent tries to pick up the item
12492
07:44:09,200 --> 07:44:10,638
and it's not there
12493
07:44:10,638 --> 07:44:13,120
or it already has the item it is
12494
07:44:13,120 --> 07:44:15,280
punished by -10 right so again you can
12495
07:44:15,280 --> 07:44:16,878
pick up you can try to pick up whenever
12496
07:44:16,878 --> 07:44:18,798
you want you can do
12497
07:44:18,798 --> 07:44:20,080
either of these
12498
07:44:20,080 --> 07:44:20,958
six
12499
07:44:20,958 --> 07:44:22,878
actions here so you can try to pick up
12500
07:44:22,878 --> 07:44:24,320
in the first year but the item's not
12501
07:44:24,320 --> 07:44:27,040
there it's really punished right so
12502
07:44:27,040 --> 07:44:28,320
in every
12503
07:44:28,320 --> 07:44:31,360
encounter we have the items will be
12504
07:44:31,360 --> 07:44:32,958
picked up the same place and dropped up
12505
07:44:32,958 --> 07:44:35,600
to the same place right so you will
12506
07:44:35,600 --> 07:44:36,398
learn
12507
07:44:36,398 --> 07:44:37,920
that when i am in this state this is
12508
07:44:37,920 --> 07:44:39,920
where i want to pick up and you will
12509
07:44:39,920 --> 07:44:40,958
learn
12510
07:44:40,958 --> 07:44:42,240
this is where it would drop off so you
12511
07:44:42,240 --> 07:44:43,440
want to
12512
07:44:43,440 --> 07:44:45,760
reward if you try to pick up when you
12513
07:44:45,760 --> 07:44:47,840
are here and punish if you try to pick
12514
07:44:47,840 --> 07:44:48,840
up anywhere
12515
07:44:48,840 --> 07:44:51,120
else and
12516
07:44:51,120 --> 07:44:52,478
if the agent picks up the item correct
12517
07:44:52,478 --> 07:44:54,958
place reward with 20 right if the agent
12518
07:44:54,958 --> 07:44:56,958
tries to drop off the item wrong place
12519
07:44:56,958 --> 07:44:58,798
or does not have the item if tries to
12520
07:44:58,798 --> 07:45:00,398
drop it off and doesn't have the item
12521
07:45:00,398 --> 07:45:02,478
obviously it should be punished
12522
07:45:02,478 --> 07:45:04,080
and if the agent drops off the item
12523
07:45:04,080 --> 07:45:05,840
correct place reward with 20 right and
12524
07:45:05,840 --> 07:45:07,760
then the game is over
12525
07:45:07,760 --> 07:45:10,558
that translates into the following code
12526
07:45:10,558 --> 07:45:12,478
or that's the code we need to implement
12527
07:45:12,478 --> 07:45:13,600
right so
12528
07:45:13,600 --> 07:45:14,958
in the next one we're going to try to
12529
07:45:14,958 --> 07:45:16,798
implement this field here so we can
12530
07:45:16,798 --> 07:45:18,478
implement it and then we're going to try
12531
07:45:18,478 --> 07:45:20,638
to make a naive solution where we just
12532
07:45:20,638 --> 07:45:22,080
do random actions and see how that
12533
07:45:22,080 --> 07:45:23,600
performs because it because it will
12534
07:45:23,600 --> 07:45:25,280
succeed if you just do random things
12535
07:45:25,280 --> 07:45:27,680
that's kind of funny but it will okay
12536
07:45:27,680 --> 07:45:29,360
are you ready to try to implement this
12537
07:45:29,360 --> 07:45:30,878
we're going to use object order
12538
07:45:30,878 --> 07:45:32,958
programming obviously are you excited i
12539
07:45:32,958 --> 07:45:34,798
hope so because it is
12540
07:45:34,798 --> 07:45:37,920
perfect see you in a moment
12541
07:45:40,398 --> 07:45:43,360
so are you ready to implement the field
12542
07:45:43,360 --> 07:45:45,600
that we are playing on let's get started
12543
07:45:45,600 --> 07:45:46,398
right
12544
07:45:46,398 --> 07:45:48,478
so we are in this reinforcement learning
12545
07:45:48,478 --> 07:45:49,520
here and we learned about the
12546
07:45:49,520 --> 07:45:51,520
reinforcement but the step we're looking
12547
07:45:51,520 --> 07:45:54,878
at right now is implement this field and
12548
07:45:54,878 --> 07:45:57,280
be able to make these actions down here
12549
07:45:57,280 --> 07:45:58,080
and
12550
07:45:58,080 --> 07:46:00,478
based on these actions to return the
12551
07:46:00,478 --> 07:46:01,680
reward
12552
07:46:01,680 --> 07:46:05,440
back to the user of that so let's get
12553
07:46:05,440 --> 07:46:08,160
started and as i said we're going to use
12554
07:46:08,160 --> 07:46:10,160
object-oriented programming so we're
12555
07:46:10,160 --> 07:46:12,478
going to make a class here called the
12556
07:46:12,478 --> 07:46:14,718
field which is the field we're playing
12557
07:46:14,718 --> 07:46:15,360
in
12558
07:46:15,360 --> 07:46:17,440
and remember we need to make this init
12559
07:46:17,440 --> 07:46:20,360
function if you have some in is in
12560
07:46:20,360 --> 07:46:22,958
initialize if you need to
12561
07:46:22,958 --> 07:46:25,520
initialize something right and we do
12562
07:46:25,520 --> 07:46:27,920
because what is it that our program
12563
07:46:27,920 --> 07:46:30,160
needs to know well first of all it needs
12564
07:46:30,160 --> 07:46:32,878
to know how big is a field because we
12565
07:46:32,878 --> 07:46:34,718
need that you can either hard code that
12566
07:46:34,718 --> 07:46:36,798
or you can implement it by
12567
07:46:36,798 --> 07:46:39,360
size setting a size so we're always
12568
07:46:39,360 --> 07:46:42,160
going to assume it's square so we put
12569
07:46:42,160 --> 07:46:44,520
the size here and then we just say
12570
07:46:44,520 --> 07:46:48,638
self.size is equal to size
12571
07:46:48,638 --> 07:46:50,638
size here
12572
07:46:50,638 --> 07:46:53,120
and in this way we will remember how big
12573
07:46:53,120 --> 07:46:54,478
it is right
12574
07:46:54,478 --> 07:46:57,200
and then there's an item to be picked up
12575
07:46:57,200 --> 07:47:00,240
item to be drop off and a carrier start
12576
07:47:00,240 --> 07:47:01,760
position right
12577
07:47:01,760 --> 07:47:04,730
so we can have that in those positions
12578
07:47:04,730 --> 07:47:06,558
[Music]
12579
07:47:06,558 --> 07:47:07,600
item
12580
07:47:07,600 --> 07:47:09,760
pick oh item
12581
07:47:09,760 --> 07:47:11,200
pickup
12582
07:47:11,200 --> 07:47:12,398
item
12583
07:47:12,398 --> 07:47:15,040
drop off
12584
07:47:15,440 --> 07:47:19,600
and start position right
12585
07:47:19,600 --> 07:47:22,718
and we need to save those self
12586
07:47:22,718 --> 07:47:24,718
all right then
12587
07:47:24,718 --> 07:47:26,160
pick up
12588
07:47:26,160 --> 07:47:27,600
item
12589
07:47:27,600 --> 07:47:28,878
pickup
12590
07:47:28,878 --> 07:47:30,080
self
12591
07:47:30,080 --> 07:47:32,000
item
12592
07:47:32,000 --> 07:47:34,320
drop off
12593
07:47:34,320 --> 07:47:35,680
i turn
12594
07:47:35,680 --> 07:47:37,360
drop off
12595
07:47:37,360 --> 07:47:38,798
self
12596
07:47:38,798 --> 07:47:41,040
and then we have position we just add
12597
07:47:41,040 --> 07:47:42,958
this as a position and we add the start
12598
07:47:42,958 --> 07:47:44,798
position for that one so this is the
12599
07:47:44,798 --> 07:47:47,840
position we are in right
12600
07:47:47,840 --> 07:47:49,280
and then there's one more thing we need
12601
07:47:49,280 --> 07:47:51,440
to know right so when we are driving
12602
07:47:51,440 --> 07:47:53,040
around here we need to know if we have
12603
07:47:53,040 --> 07:47:55,600
the item in the carrier or not right
12604
07:47:55,600 --> 07:47:57,760
because remember we need to reward if
12605
07:47:57,760 --> 07:47:59,520
you try to pick up
12606
07:47:59,520 --> 07:48:00,398
uh
12607
07:48:00,398 --> 07:48:01,840
and you don't have the item but if you
12608
07:48:01,840 --> 07:48:03,360
pick up if you do have the item you
12609
07:48:03,360 --> 07:48:05,040
should be punished and if you drop off
12610
07:48:05,040 --> 07:48:06,160
and you don't have the item you should
12611
07:48:06,160 --> 07:48:08,478
be punished as well with negative right
12612
07:48:08,478 --> 07:48:12,638
so self we can call it
12613
07:48:12,718 --> 07:48:17,200
item in car to be false by default right
12614
07:48:17,200 --> 07:48:18,000
so
12615
07:48:18,000 --> 07:48:18,958
this is
12616
07:48:18,958 --> 07:48:21,600
initialization of our class field but
12617
07:48:21,600 --> 07:48:23,280
right now we cannot do anything and the
12618
07:48:23,280 --> 07:48:24,958
next step we want to do is actually
12619
07:48:24,958 --> 07:48:27,600
based on that we want to
12620
07:48:27,600 --> 07:48:29,280
make an action right
12621
07:48:29,280 --> 07:48:32,000
make an action
12622
07:48:32,840 --> 07:48:36,080
so we call it make action
12623
07:48:36,080 --> 07:48:38,958
and this action here should take uh the
12624
07:48:38,958 --> 07:48:41,280
action right
12625
07:48:41,280 --> 07:48:43,600
and this action can be one of these here
12626
07:48:43,600 --> 07:48:46,840
zero one two three four five right
12627
07:48:46,840 --> 07:48:49,520
so on the first place here let's just
12628
07:48:49,520 --> 07:48:53,200
say if action equals equals zero right
12629
07:48:53,200 --> 07:48:55,840
then we just write pass and pass just
12630
07:48:55,840 --> 07:48:57,600
means that we haven't implemented yet so
12631
07:48:57,600 --> 07:48:59,360
do nothing right else
12632
07:48:59,360 --> 07:49:01,680
alif action
12633
07:49:01,680 --> 07:49:04,000
one we just write what it is so we
12634
07:49:04,000 --> 07:49:06,558
remember it here actually
12635
07:49:06,558 --> 07:49:08,000
we can do that by comment right so
12636
07:49:08,000 --> 07:49:09,600
action one
12637
07:49:09,600 --> 07:49:11,920
go south
12638
07:49:11,920 --> 07:49:14,080
action two
12639
07:49:14,080 --> 07:49:14,840
go
12640
07:49:14,840 --> 07:49:17,520
north pass
12641
07:49:17,520 --> 07:49:19,520
lf
12642
07:49:19,520 --> 07:49:21,680
action
12643
07:49:21,680 --> 07:49:22,110
2
12644
07:49:22,110 --> 07:49:23,760
[Music]
12645
07:49:23,760 --> 07:49:25,760
go was it east
12646
07:49:25,760 --> 07:49:27,840
i think it's capital actually in
12647
07:49:27,840 --> 07:49:29,680
america in
12648
07:49:29,680 --> 07:49:31,200
english right you have to write like
12649
07:49:31,200 --> 07:49:33,040
that i think so
12650
07:49:33,040 --> 07:49:37,280
i didn't do that up there and go vest
12651
07:49:37,680 --> 07:49:38,958
pass
12652
07:49:38,958 --> 07:49:40,080
alif
12653
07:49:40,080 --> 07:49:41,520
action
12654
07:49:41,520 --> 07:49:43,680
three
12655
07:49:43,680 --> 07:49:44,398
go
12656
07:49:44,398 --> 07:49:45,920
west
12657
07:49:45,920 --> 07:49:47,120
pass
12658
07:49:47,120 --> 07:49:48,398
alif
12659
07:49:48,398 --> 07:49:50,558
action
12660
07:49:50,558 --> 07:49:52,878
4
12661
07:49:53,840 --> 07:49:56,160
pick up item
12662
07:49:56,160 --> 07:49:57,280
pass
12663
07:49:57,280 --> 07:49:59,040
alif
12664
07:49:59,040 --> 07:50:00,240
action
12665
07:50:00,240 --> 07:50:01,280
equals
12666
07:50:01,280 --> 07:50:03,680
five
12667
07:50:04,718 --> 07:50:06,240
drop-off
12668
07:50:06,240 --> 07:50:08,160
item
12669
07:50:08,160 --> 07:50:12,160
pass right so this is the five actions
12670
07:50:12,160 --> 07:50:13,760
that we have right
12671
07:50:13,760 --> 07:50:15,840
and then we need to implement the reward
12672
07:50:15,840 --> 07:50:17,760
and
12673
07:50:17,760 --> 07:50:19,200
and
12674
07:50:19,200 --> 07:50:20,558
the reward
12675
07:50:20,558 --> 07:50:22,240
yeah the positive or negative reward
12676
07:50:22,240 --> 07:50:23,360
right
12677
07:50:23,360 --> 07:50:25,120
so what we need to know is in the
12678
07:50:25,120 --> 07:50:26,798
beginning here we need to get the
12679
07:50:26,798 --> 07:50:29,360
position of where we are so we start in
12680
07:50:29,360 --> 07:50:31,840
start position and position is a
12681
07:50:31,840 --> 07:50:34,558
tuple of two items right
12682
07:50:34,558 --> 07:50:36,398
so based on that
12683
07:50:36,398 --> 07:50:38,000
we just put x
12684
07:50:38,000 --> 07:50:40,958
and y here and we take self
12685
07:50:40,958 --> 07:50:43,520
position
12686
07:50:44,478 --> 07:50:47,600
so let's try to do that
12687
07:50:47,600 --> 07:50:49,200
so the first one here if the agent tries
12688
07:50:49,200 --> 07:50:51,840
to go with the field punish with -10
12689
07:50:51,840 --> 07:50:55,040
right so if we go south that's down
12690
07:50:55,040 --> 07:50:57,280
right so that means basically if we're
12691
07:50:57,280 --> 07:50:59,680
down so we go south here we go down here
12692
07:50:59,680 --> 07:51:02,320
we are outside the field so that means
12693
07:51:02,320 --> 07:51:04,080
that
12694
07:51:04,080 --> 07:51:06,160
if we are in position nine here that
12695
07:51:06,160 --> 07:51:08,478
it's a size minus one and we go down we
12696
07:51:08,478 --> 07:51:11,200
get punished right so if
12697
07:51:11,200 --> 07:51:13,120
y
12698
07:51:13,120 --> 07:51:15,280
equals equals self
12699
07:51:15,280 --> 07:51:18,798
size minus one
12700
07:51:18,798 --> 07:51:20,840
and what do we do we
12701
07:51:20,840 --> 07:51:24,878
return -10 but we also want to return if
12702
07:51:24,878 --> 07:51:27,200
we are done or not so we return actually
12703
07:51:27,200 --> 07:51:29,520
comma false we'll come back to that
12704
07:51:29,520 --> 07:51:30,398
later
12705
07:51:30,398 --> 07:51:33,200
so basically when we succeed in the end
12706
07:51:33,200 --> 07:51:35,120
here we want to
12707
07:51:35,120 --> 07:51:37,680
say true right
12708
07:51:37,680 --> 07:51:38,718
good
12709
07:51:38,718 --> 07:51:40,558
else
12710
07:51:40,558 --> 07:51:41,840
is there anything else we need to do
12711
07:51:41,840 --> 07:51:44,080
here well else we need to update the
12712
07:51:44,080 --> 07:51:47,520
position right so self position
12713
07:51:47,520 --> 07:51:49,440
and we take
12714
07:51:49,440 --> 07:51:50,558
x
12715
07:51:50,558 --> 07:51:52,240
comma
12716
07:51:52,240 --> 07:51:52,690
y
12717
07:51:52,690 --> 07:51:55,600
[Music]
12718
07:51:55,600 --> 07:51:58,558
plus one right because we go down and we
12719
07:51:58,558 --> 07:52:01,200
have created our field like this that we
12720
07:52:01,200 --> 07:52:03,360
go down it will go
12721
07:52:03,360 --> 07:52:06,320
adding to the y-axis we keep this y-axis
12722
07:52:06,320 --> 07:52:09,040
and this x-axis right perfect
12723
07:52:09,040 --> 07:52:09,920
good
12724
07:52:09,920 --> 07:52:12,878
and then we return -1 because we don't
12725
07:52:12,878 --> 07:52:15,440
want to encourage that and we still keep
12726
07:52:15,440 --> 07:52:17,760
false here okay
12727
07:52:17,760 --> 07:52:21,120
north is quite similar so if y equals
12728
07:52:21,120 --> 07:52:22,718
equals zero
12729
07:52:22,718 --> 07:52:26,718
then we are returned minus 10 and false
12730
07:52:26,718 --> 07:52:30,000
right and else what we do is actually we
12731
07:52:30,000 --> 07:52:32,958
want to move the position of our self
12732
07:52:32,958 --> 07:52:35,040
and it is
12733
07:52:35,040 --> 07:52:37,280
y
12734
07:52:37,280 --> 07:52:38,958
minus 1 now
12735
07:52:38,958 --> 07:52:42,718
and then we take return -1 false right
12736
07:52:42,718 --> 07:52:45,360
so in this case we can move up
12737
07:52:45,360 --> 07:52:48,240
north with one that means the y axis the
12738
07:52:48,240 --> 07:52:51,200
y number is going one up and
12739
07:52:51,200 --> 07:52:52,080
and
12740
07:52:52,080 --> 07:52:54,320
we're still not done perfect
12741
07:52:54,320 --> 07:52:55,520
action
12742
07:52:55,520 --> 07:52:56,718
east right
12743
07:52:56,718 --> 07:52:59,040
so east is
12744
07:52:59,040 --> 07:53:01,520
left so if we are here we go this way so
12745
07:53:01,520 --> 07:53:04,080
if we are in zero we need to punish
12746
07:53:04,080 --> 07:53:06,320
right
12747
07:53:06,878 --> 07:53:10,160
so if x equals equals zero
12748
07:53:10,160 --> 07:53:12,398
return
12749
07:53:12,398 --> 07:53:13,760
minus
12750
07:53:13,760 --> 07:53:15,680
comma
12751
07:53:15,680 --> 07:53:17,360
false still
12752
07:53:17,360 --> 07:53:19,680
else
12753
07:53:19,680 --> 07:53:20,798
we do
12754
07:53:20,798 --> 07:53:22,160
x no
12755
07:53:22,160 --> 07:53:23,120
self
12756
07:53:23,120 --> 07:53:24,958
position
12757
07:53:24,958 --> 07:53:26,638
actually i did this wrong here we needed
12758
07:53:26,638 --> 07:53:29,440
to have equal signs here
12759
07:53:29,440 --> 07:53:32,160
equal signs
12760
07:53:32,478 --> 07:53:33,920
pull
12761
07:53:33,920 --> 07:53:35,760
session
12762
07:53:35,760 --> 07:53:37,440
let me take x
12763
07:53:37,440 --> 07:53:40,478
minus 1 comma y
12764
07:53:40,478 --> 07:53:42,398
return minus one
12765
07:53:42,398 --> 07:53:43,680
false
12766
07:53:43,680 --> 07:53:46,320
and then we'll go west here
12767
07:53:46,320 --> 07:53:48,160
and if
12768
07:53:48,160 --> 07:53:50,080
x equals
12769
07:53:50,080 --> 07:53:52,000
equals
12770
07:53:52,000 --> 07:53:53,520
self
12771
07:53:53,520 --> 07:53:59,040
size minus one and then we do
12772
07:53:59,040 --> 07:54:00,798
return
12773
07:54:00,798 --> 07:54:03,840
-10 comma false
12774
07:54:03,840 --> 07:54:05,040
else
12775
07:54:05,040 --> 07:54:06,638
return
12776
07:54:06,638 --> 07:54:11,680
oh we need to update first self position
12777
07:54:11,680 --> 07:54:14,080
equals to x
12778
07:54:14,080 --> 07:54:16,638
plus one comma y
12779
07:54:16,638 --> 07:54:18,398
and we
12780
07:54:18,398 --> 07:54:21,440
are still punishing by one right so this
12781
07:54:21,440 --> 07:54:23,360
is actually the movement we can do right
12782
07:54:23,360 --> 07:54:25,840
so again
12783
07:54:30,000 --> 07:54:32,080
again this
12784
07:54:32,080 --> 07:54:34,320
these are coordinates right so we have
12785
07:54:34,320 --> 07:54:36,558
that the position here is x comma y this
12786
07:54:36,558 --> 07:54:38,798
is a start position we start with so in
12787
07:54:38,798 --> 07:54:40,320
the beginning it will be
12788
07:54:40,320 --> 07:54:42,080
0.9
12789
07:54:42,080 --> 07:54:44,240
0.19 or
12790
07:54:44,240 --> 07:54:47,120
9.0 actually
12791
07:54:47,120 --> 07:54:49,200
and then we update it accordingly into
12792
07:54:49,200 --> 07:54:50,878
that position right so we overwrite if
12793
07:54:50,878 --> 07:54:54,798
we go south we go the y-axis down
12794
07:54:54,798 --> 07:54:56,798
no up one and
12795
07:54:56,798 --> 07:54:59,040
north down one right so this is how it's
12796
07:54:59,040 --> 07:55:01,520
updated okay so
12797
07:55:01,520 --> 07:55:03,120
now this one is a bit more tricky right
12798
07:55:03,120 --> 07:55:05,920
remember if we try to pick up somewhere
12799
07:55:05,920 --> 07:55:07,440
where it's not
12800
07:55:07,440 --> 07:55:10,798
if we pick up ice and if we can't uh
12801
07:55:10,798 --> 07:55:11,920
if the agent
12802
07:55:11,920 --> 07:55:13,600
picks up the item
12803
07:55:13,600 --> 07:55:14,558
and
12804
07:55:14,558 --> 07:55:16,798
it says here if the agent picks tries to
12805
07:55:16,798 --> 07:55:19,120
pick up the item but it's not there or
12806
07:55:19,120 --> 07:55:23,040
it has it already punched by 10 right
12807
07:55:23,040 --> 07:55:25,600
so if
12808
07:55:25,600 --> 07:55:27,680
if
12809
07:55:27,680 --> 07:55:29,440
self
12810
07:55:29,440 --> 07:55:31,200
item
12811
07:55:31,200 --> 07:55:33,280
in car
12812
07:55:33,280 --> 07:55:35,440
so that is true
12813
07:55:35,440 --> 07:55:37,520
let's just do that return
12814
07:55:37,520 --> 07:55:38,878
-10
12815
07:55:38,878 --> 07:55:40,000
false
12816
07:55:40,000 --> 07:55:41,600
l if
12817
07:55:41,600 --> 07:55:44,558
item is not there so this is this case
12818
07:55:44,558 --> 07:55:45,920
is
12819
07:55:45,920 --> 07:55:48,718
we know it's not in the car but the item
12820
07:55:48,718 --> 07:55:50,718
is not there right so how do you check
12821
07:55:50,718 --> 07:55:54,160
that well you say that
12822
07:55:54,160 --> 07:55:58,320
self item position
12823
07:56:01,600 --> 07:56:04,080
item pickup actually
12824
07:56:04,080 --> 07:56:04,878
yeah
12825
07:56:04,878 --> 07:56:08,160
it is equal to x comma y or not equals
12826
07:56:08,160 --> 07:56:09,920
2.
12827
07:56:09,920 --> 07:56:12,798
and then we have
12828
07:56:13,760 --> 07:56:17,920
return minus 10 false
12829
07:56:17,920 --> 07:56:19,280
and else we're actually in the good
12830
07:56:19,280 --> 07:56:22,718
place right so then we have self
12831
07:56:22,718 --> 07:56:25,120
item in car
12832
07:56:25,120 --> 07:56:27,280
to be true now
12833
07:56:27,280 --> 07:56:29,680
and then we return
12834
07:56:29,680 --> 07:56:32,320
20 and false right we want to reward
12835
07:56:32,320 --> 07:56:33,760
this
12836
07:56:33,760 --> 07:56:35,440
by 20 right
12837
07:56:35,440 --> 07:56:37,440
if the agent tries to pick up the item
12838
07:56:37,440 --> 07:56:40,558
correct place reward with 20.
12839
07:56:40,558 --> 07:56:41,600
good
12840
07:56:41,600 --> 07:56:43,440
and then the final here
12841
07:56:43,440 --> 07:56:45,920
so again if
12842
07:56:45,920 --> 07:56:48,320
you want to drop off and if
12843
07:56:48,320 --> 07:56:49,200
not
12844
07:56:49,200 --> 07:56:51,280
self item in car
12845
07:56:51,280 --> 07:56:55,600
right if it's not in the car return -10
12846
07:56:55,600 --> 07:56:57,280
false
12847
07:56:57,280 --> 07:56:59,520
if
12848
07:56:59,520 --> 07:57:03,280
we try to then it is in the car and uh
12849
07:57:03,280 --> 07:57:04,638
self
12850
07:57:04,638 --> 07:57:05,840
item
12851
07:57:05,840 --> 07:57:07,680
drop off
12852
07:57:07,680 --> 07:57:11,040
is not equal to x comma y so it's not
12853
07:57:11,040 --> 07:57:14,320
equal to the position we are
12854
07:57:16,240 --> 07:57:18,798
and then return minus
12855
07:57:18,798 --> 07:57:21,760
10 comma false what it is there so we
12856
07:57:21,760 --> 07:57:23,920
need to drop it off right
12857
07:57:23,920 --> 07:57:26,958
so here we need to self
12858
07:57:26,958 --> 07:57:28,240
item
12859
07:57:28,240 --> 07:57:30,398
we use the pickup place so now we
12860
07:57:30,398 --> 07:57:33,200
overwrite the pickup place here to be x
12861
07:57:33,200 --> 07:57:35,760
comma y because we need to
12862
07:57:35,760 --> 07:57:37,120
even though it's
12863
07:57:37,120 --> 07:57:41,920
here right and then self item in car
12864
07:57:41,920 --> 07:57:44,160
is false now right
12865
07:57:44,160 --> 07:57:46,320
so we try to drop it off we drop it off
12866
07:57:46,320 --> 07:57:47,600
here then we have to pick it up again
12867
07:57:47,600 --> 07:57:48,958
here later right so this is a bit
12868
07:57:48,958 --> 07:57:52,000
confusing right and uh
12869
07:57:52,000 --> 07:57:55,040
finally else here we do this is a
12870
07:57:55,040 --> 07:57:57,280
correct place now we are in the correct
12871
07:57:57,280 --> 07:58:00,798
place so return
12872
07:58:00,798 --> 07:58:03,200
20 and true right
12873
07:58:03,200 --> 07:58:06,478
because now we're done okay so so far so
12874
07:58:06,478 --> 07:58:08,638
good is this all correct it's it's a lot
12875
07:58:08,638 --> 07:58:09,780
of code right remember
12876
07:58:09,780 --> 07:58:11,920
[Laughter]
12877
07:58:11,920 --> 07:58:14,160
so how can we test this well we're going
12878
07:58:14,160 --> 07:58:16,478
to test it in the next one we're going
12879
07:58:16,478 --> 07:58:18,478
to make a naive solution and see how it
12880
07:58:18,478 --> 07:58:20,558
works right but let's just for the fun
12881
07:58:20,558 --> 07:58:23,360
of it let's just hard code a trip in our
12882
07:58:23,360 --> 07:58:24,878
field
12883
07:58:24,878 --> 07:58:27,120
so
12884
07:58:27,520 --> 07:58:28,878
field
12885
07:58:28,878 --> 07:58:32,160
here we make a field and what does it
12886
07:58:32,160 --> 07:58:34,958
take it takes the size of it
12887
07:58:34,958 --> 07:58:36,798
and
12888
07:58:36,798 --> 07:58:39,040
pickup item
12889
07:58:39,040 --> 07:58:41,840
item pickup it is in
12890
07:58:41,840 --> 07:58:44,160
0 by 0
12891
07:58:44,160 --> 07:58:46,080
and then we have
12892
07:58:46,080 --> 07:58:47,760
item drop-off
12893
07:58:47,760 --> 07:58:49,280
9x9
12894
07:58:49,280 --> 07:58:52,958
and we start in
12895
07:58:53,680 --> 07:58:56,398
nine by zero right that's where we start
12896
07:58:56,398 --> 07:58:59,440
right nine by zero yeah perfect this is
12897
07:58:59,440 --> 07:59:01,440
our field
12898
07:59:01,440 --> 07:59:02,558
perfect
12899
07:59:02,558 --> 07:59:04,958
and now we can make actions right but we
12900
07:59:04,958 --> 07:59:06,558
actually know what how to get there
12901
07:59:06,558 --> 07:59:09,120
should we try to pick it up
12902
07:59:09,120 --> 07:59:11,520
and uh
12903
07:59:11,520 --> 07:59:14,160
so what we want to do is go east right
12904
07:59:14,160 --> 07:59:18,240
so go east is 2.
12905
07:59:18,240 --> 07:59:19,440
oh
12906
07:59:19,440 --> 07:59:21,040
make action
12907
07:59:21,040 --> 07:59:22,718
two right
12908
07:59:22,718 --> 07:59:24,798
then we get one minus here right and
12909
07:59:24,798 --> 07:59:26,878
then we can actually see in the field
12910
07:59:26,878 --> 07:59:28,798
position where we are right so now we're
12911
07:59:28,798 --> 07:59:32,398
in eight right and we can again just
12912
07:59:32,398 --> 07:59:34,878
for the fun of it let's just
12913
07:59:34,878 --> 07:59:37,440
let's just keep it in the same here so
12914
07:59:37,440 --> 07:59:40,080
we create a new one and then we can see
12915
07:59:40,080 --> 07:59:42,798
how we're moving around right
12916
07:59:42,798 --> 07:59:45,040
and let's just delete this and this
12917
07:59:45,040 --> 07:59:46,878
because we need to go
12918
07:59:46,878 --> 07:59:50,478
how many times one two three four five
12919
07:59:50,478 --> 07:59:52,080
six
12920
07:59:52,080 --> 07:59:55,040
seven eight did i correct here now we're
12921
07:59:55,040 --> 07:59:56,638
in zero zero right
12922
07:59:56,638 --> 07:59:59,760
so one two three four five six seven
12923
07:59:59,760 --> 08:00:03,200
eight nine so we moved
12924
08:00:04,958 --> 08:00:07,840
we moved one two three four five six
12925
08:00:07,840 --> 08:00:09,440
seven eight nine times and then we need
12926
08:00:09,440 --> 08:00:14,680
to pick up item and pick up item was
12927
08:00:15,120 --> 08:00:17,440
was
12928
08:00:18,000 --> 08:00:20,878
action four
12929
08:00:23,760 --> 08:00:25,120
action four
12930
08:00:25,120 --> 08:00:27,360
and then we need to walk
12931
08:00:27,360 --> 08:00:29,040
so here we have it
12932
08:00:29,040 --> 08:00:31,120
we're still in the same position here
12933
08:00:31,120 --> 08:00:32,958
and then we need to
12934
08:00:32,958 --> 08:00:34,798
basically we can
12935
08:00:34,798 --> 08:00:36,718
we can walk
12936
08:00:36,718 --> 08:00:38,958
left right left right left right so it's
12937
08:00:38,958 --> 08:00:40,878
like
12938
08:00:40,878 --> 08:00:44,320
south down it's zero and let's just go
12939
08:00:44,320 --> 08:00:46,958
south of the way and then we go
12940
08:00:46,958 --> 08:00:50,478
west afterwards so west is
12941
08:00:50,478 --> 08:00:52,718
three
12942
08:00:52,718 --> 08:00:57,200
so let's just take one like this
12943
08:00:57,200 --> 08:00:59,600
zero
12944
08:01:07,520 --> 08:01:08,840
now i need one more
12945
08:01:08,840 --> 08:01:11,760
run no it's right
12946
08:01:11,760 --> 08:01:14,080
is it
12947
08:01:15,200 --> 08:01:18,730
no i need one more yeah that's right
12948
08:01:18,730 --> 08:01:20,000
[Music]
12949
08:01:20,000 --> 08:01:22,240
and then we're down to nine and then we
12950
08:01:22,240 --> 08:01:25,558
need to
12951
08:01:28,558 --> 08:01:30,798
then we need to go
12952
08:01:30,798 --> 08:01:33,798
three
12953
08:01:42,798 --> 08:01:44,798
here now we're 99 and then we need to
12954
08:01:44,798 --> 08:01:46,638
drop it off right so this is our
12955
08:01:46,638 --> 08:01:48,000
superior
12956
08:01:48,000 --> 08:01:50,398
intelligence or overview of the
12957
08:01:50,398 --> 08:01:52,638
situation right that would make the
12958
08:01:52,638 --> 08:01:54,398
perfect match but we're not going to do
12959
08:01:54,398 --> 08:01:57,040
that when we do randomness so in the
12960
08:01:57,040 --> 08:01:58,958
next one we're actually
12961
08:01:58,958 --> 08:02:01,360
it seems like it's working right
12962
08:02:01,360 --> 08:02:03,200
we are traveling so what we did here
12963
08:02:03,200 --> 08:02:04,878
kind of testing if we can work around
12964
08:02:04,878 --> 08:02:07,600
walk around we didn't test the feedback
12965
08:02:07,600 --> 08:02:09,440
exactly but
12966
08:02:09,440 --> 08:02:11,840
but uh you you you know what's happening
12967
08:02:11,840 --> 08:02:14,320
here good so are you excited to make the
12968
08:02:14,320 --> 08:02:16,398
naive solution so get ready for that in
12969
08:02:16,398 --> 08:02:20,440
the next one see you in a moment
12970
08:02:21,840 --> 08:02:23,440
so are you ready to make the naive
12971
08:02:23,440 --> 08:02:26,558
solution so in here we are created a
12972
08:02:26,558 --> 08:02:28,958
field that represents this field here
12973
08:02:28,958 --> 08:02:30,638
and this game here where we actually
12974
08:02:30,638 --> 08:02:33,440
start by being the carrier here and we
12975
08:02:33,440 --> 08:02:35,280
need to move over here and drop it off
12976
08:02:35,280 --> 08:02:36,878
here so
12977
08:02:36,878 --> 08:02:39,200
we don't know anything so we are
12978
08:02:39,200 --> 08:02:40,638
basically
12979
08:02:40,638 --> 08:02:42,958
no we have no knowledge so what we would
12980
08:02:42,958 --> 08:02:44,958
do is make a random action and walk
12981
08:02:44,958 --> 08:02:47,600
around and until we succeed so let's try
12982
08:02:47,600 --> 08:02:50,240
to make an implementation of that
12983
08:02:50,240 --> 08:02:51,840
how that would work right
12984
08:02:51,840 --> 08:02:53,040
so
12985
08:02:53,040 --> 08:02:54,558
in order to do that we need to import
12986
08:02:54,558 --> 08:02:56,878
random because we need to
12987
08:02:56,878 --> 08:02:58,878
we need to do random actions right and
12988
08:02:58,878 --> 08:03:00,718
the next thing is let's make a naive
12989
08:03:00,718 --> 08:03:03,280
solution so naive
12990
08:03:03,280 --> 08:03:06,638
solution to it right and this one
12991
08:03:06,638 --> 08:03:08,798
will
12992
08:03:08,798 --> 08:03:09,920
we'll just
12993
08:03:09,920 --> 08:03:13,280
make a field here
12994
08:03:14,000 --> 08:03:15,680
field here and
12995
08:03:15,680 --> 08:03:17,360
we'll make the field actually the same
12996
08:03:17,360 --> 08:03:20,160
as this one here
12997
08:03:20,398 --> 08:03:21,840
we can actually make it a bit more
12998
08:03:21,840 --> 08:03:24,000
readable so one way to do that is
12999
08:03:24,000 --> 08:03:26,798
actually to have the size here to be 10
13000
08:03:26,798 --> 08:03:29,440
and then you change this by size because
13001
08:03:29,440 --> 08:03:32,320
then you know what it is and then it is
13002
08:03:32,320 --> 08:03:34,718
item
13003
08:03:34,798 --> 08:03:36,478
start
13004
08:03:36,478 --> 08:03:40,080
you put that to 0.0
13005
08:03:40,638 --> 08:03:44,520
item start
13006
08:03:44,798 --> 08:03:45,920
item
13007
08:03:45,920 --> 08:03:48,478
drop off
13008
08:03:54,478 --> 08:03:55,600
item
13009
08:03:55,600 --> 08:03:57,680
drop off
13010
08:03:57,680 --> 08:04:00,240
and then we have here we have a
13011
08:04:00,240 --> 08:04:03,360
start position right
13012
08:04:03,360 --> 08:04:06,360
position
13013
08:04:06,718 --> 08:04:07,798
start
13014
08:04:07,798 --> 08:04:10,878
position right
13015
08:04:10,878 --> 08:04:12,398
so here we have it right so it's a bit
13016
08:04:12,398 --> 08:04:14,718
more readable like that right so in that
13017
08:04:14,718 --> 08:04:16,398
way we
13018
08:04:16,398 --> 08:04:18,000
create the field right so now for the
13019
08:04:18,000 --> 08:04:21,040
naive solution right
13020
08:04:21,360 --> 08:04:23,840
and uh
13021
08:04:24,638 --> 08:04:26,718
so so far we actually need
13022
08:04:26,718 --> 08:04:28,398
somehow to
13023
08:04:28,398 --> 08:04:30,240
say if we're done or not because we're
13024
08:04:30,240 --> 08:04:31,920
going to make a loop and just iterate
13025
08:04:31,920 --> 08:04:33,360
and then we'll count how many steps
13026
08:04:33,360 --> 08:04:36,320
we're doing so steps is zero so
13027
08:04:36,320 --> 08:04:39,360
that's it while done we continue until
13028
08:04:39,360 --> 08:04:42,240
we are done right so we make an action
13029
08:04:42,240 --> 08:04:43,920
and we know we can make one out of six
13030
08:04:43,920 --> 08:04:46,160
actions so random
13031
08:04:46,160 --> 08:04:48,398
rand int
13032
08:04:48,398 --> 08:04:50,958
and it is between zero and
13033
08:04:50,958 --> 08:04:53,440
five right because they are not they're
13034
08:04:53,440 --> 08:04:55,360
including both right so it creates a
13035
08:04:55,360 --> 08:04:58,718
random action and then we take a reward
13036
08:04:58,718 --> 08:05:01,200
and we take a done we don't care about
13037
08:05:01,200 --> 08:05:03,040
the reward right now actually and then
13038
08:05:03,040 --> 08:05:05,520
we take the field and
13039
08:05:05,520 --> 08:05:07,120
make action
13040
08:05:07,120 --> 08:05:09,040
action right
13041
08:05:09,040 --> 08:05:09,840
and
13042
08:05:09,840 --> 08:05:11,760
then we take steps
13043
08:05:11,760 --> 08:05:14,160
and we take steps
13044
08:05:14,160 --> 08:05:16,398
plus one right and then we just continue
13045
08:05:16,398 --> 08:05:19,200
like that and then in the end we return
13046
08:05:19,200 --> 08:05:20,320
steps
13047
08:05:20,320 --> 08:05:22,240
so this is actually our naive solution
13048
08:05:22,240 --> 08:05:23,280
right
13049
08:05:23,280 --> 08:05:24,718
this is what we do right we just take a
13050
08:05:24,718 --> 08:05:26,718
random action we create it and we just
13051
08:05:26,718 --> 08:05:28,398
continue until we're done so how does
13052
08:05:28,398 --> 08:05:31,840
that work naive solution
13053
08:05:31,920 --> 08:05:35,718
zero that was not good
13054
08:05:36,080 --> 08:05:36,798
so
13055
08:05:36,798 --> 08:05:39,120
what happened here is
13056
08:05:39,120 --> 08:05:41,600
something not good
13057
08:05:41,600 --> 08:05:43,200
i actually put the drop off and start
13058
08:05:43,200 --> 08:05:45,440
position the same place here you see
13059
08:05:45,440 --> 08:05:47,360
that
13060
08:05:47,360 --> 08:05:49,120
but that shouldn't make a
13061
08:05:49,120 --> 08:05:52,718
zero oh well not done
13062
08:05:52,718 --> 08:05:55,120
thank you
13063
08:05:55,920 --> 08:05:58,160
so here you see it so you make an
13064
08:05:58,160 --> 08:06:00,638
enormous amount of steps here right so
13065
08:06:00,638 --> 08:06:01,760
here
13066
08:06:01,760 --> 08:06:04,080
you could just continue like that right
13067
08:06:04,080 --> 08:06:05,840
so it's different number of steps but
13068
08:06:05,840 --> 08:06:07,120
you see here
13069
08:06:07,120 --> 08:06:11,320
this one here is uh 204 209
13070
08:06:11,320 --> 08:06:14,080
229 steps and
13071
08:06:14,080 --> 08:06:15,440
that's a lot of steps and we're going to
13072
08:06:15,440 --> 08:06:17,200
try to improve that with our smart
13073
08:06:17,200 --> 08:06:20,160
algorithm right so how can we just uh do
13074
08:06:20,160 --> 08:06:24,160
a bit test here so let's just say
13075
08:06:24,160 --> 08:06:26,080
to get some kind of average base case
13076
08:06:26,080 --> 08:06:27,920
how many steps does it take well let's
13077
08:06:27,920 --> 08:06:30,840
just make a list here so
13078
08:06:30,840 --> 08:06:34,878
runs and we have that naive solution we
13079
08:06:34,878 --> 08:06:38,240
run that and we do that for i in range
13080
08:06:38,240 --> 08:06:40,398
let's just i don't know it's pretty slow
13081
08:06:40,398 --> 08:06:43,280
this one so let's just take 100 runs
13082
08:06:43,280 --> 08:06:46,320
and let's see how that goes and then we
13083
08:06:46,320 --> 08:06:49,280
get an average number of that
13084
08:06:49,280 --> 08:06:51,200
or we get it runs on that and then we
13085
08:06:51,200 --> 08:06:52,718
calculate the average
13086
08:06:52,718 --> 08:06:54,398
average of that in a moment when it's
13087
08:06:54,398 --> 08:06:56,638
done
13088
08:06:57,280 --> 08:06:58,840
okay so it's done
13089
08:06:58,840 --> 08:07:01,840
and so what you do is just take the sum
13090
08:07:01,840 --> 08:07:04,638
of the runs and then you divide it by
13091
08:07:04,638 --> 08:07:07,680
divided by the length of runs right it's
13092
08:07:07,680 --> 08:07:10,440
100 but here we have it so on average is
13093
08:07:10,440 --> 08:07:12,718
158 000
13094
08:07:12,718 --> 08:07:15,840
runs or steps to complete it in naive
13095
08:07:15,840 --> 08:07:18,080
solution so this is the naive and then
13096
08:07:18,080 --> 08:07:19,600
in the next one we're going to create
13097
08:07:19,600 --> 08:07:22,558
this q table or the states that is what
13098
08:07:22,558 --> 08:07:24,718
we need to do in the next one is how do
13099
08:07:24,718 --> 08:07:25,920
we map
13100
08:07:25,920 --> 08:07:27,360
from
13101
08:07:27,360 --> 08:07:29,200
this table here
13102
08:07:29,200 --> 08:07:31,840
a position is stated in this one
13103
08:07:31,840 --> 08:07:35,280
to a queue table so we can do updates in
13104
08:07:35,280 --> 08:07:36,878
our queue table that we're going to do
13105
08:07:36,878 --> 08:07:39,200
the computations on remember we need to
13106
08:07:39,200 --> 08:07:41,280
do this q table here with the
13107
08:07:41,280 --> 08:07:43,760
computations but we need somehow to know
13108
08:07:43,760 --> 08:07:45,920
what is the state and the state is
13109
08:07:45,920 --> 08:07:48,000
basically a
13110
08:07:48,000 --> 08:07:50,160
position of this one here so we need one
13111
08:07:50,160 --> 08:07:52,240
state for each of them and then we need
13112
08:07:52,240 --> 08:07:53,920
a
13113
08:07:53,920 --> 08:07:55,440
a action
13114
08:07:55,440 --> 08:07:57,840
probability for each action in it okay
13115
08:07:57,840 --> 08:07:59,680
so are you ready for that i hope so it's
13116
08:07:59,680 --> 08:08:03,200
going to be exciting see you in a moment
13117
08:08:05,760 --> 08:08:07,840
so what we want to do now is to figure
13118
08:08:07,840 --> 08:08:10,958
out a way to map from our world our
13119
08:08:10,958 --> 08:08:13,440
universe here to a state right
13120
08:08:13,440 --> 08:08:18,398
so we need a unique way to represent
13121
08:08:18,398 --> 08:08:20,398
a state in this one here so we need to
13122
08:08:20,398 --> 08:08:22,638
figure out what is a state right so what
13123
08:08:22,638 --> 08:08:24,718
changes in this one well one thing that
13124
08:08:24,718 --> 08:08:26,638
changes is the carrier it can move
13125
08:08:26,638 --> 08:08:28,878
around right and how can it move around
13126
08:08:28,878 --> 08:08:30,958
it can move around this 10 by 10
13127
08:08:30,958 --> 08:08:33,600
universe right so there's at least 10 by
13128
08:08:33,600 --> 08:08:35,840
10 states in it right so that's a one
13129
08:08:35,840 --> 08:08:37,840
variable that can change the another
13130
08:08:37,840 --> 08:08:41,520
variable is where is the item right so
13131
08:08:41,520 --> 08:08:44,478
the item can be in any place also except
13132
08:08:44,478 --> 08:08:46,798
the last one everybody ignore that so it
13133
08:08:46,798 --> 08:08:50,478
can also be in 10 by 10 states so
13134
08:08:50,478 --> 08:08:52,638
when we move around
13135
08:08:52,638 --> 08:08:54,398
in this carrier
13136
08:08:54,398 --> 08:08:56,558
our action should depend upon where this
13137
08:08:56,558 --> 08:08:58,558
one is right so if we move this one down
13138
08:08:58,558 --> 08:08:59,440
here
13139
08:08:59,440 --> 08:09:01,440
our action should be different based on
13140
08:09:01,440 --> 08:09:03,360
that as you can see right
13141
08:09:03,360 --> 08:09:04,878
so
13142
08:09:04,878 --> 08:09:06,798
they're actually 10 by 10 for this one
13143
08:09:06,798 --> 08:09:09,040
and then 10 by 10 by this one but these
13144
08:09:09,040 --> 08:09:11,440
two have to be multiplied right because
13145
08:09:11,440 --> 08:09:13,840
based on the position of this one we
13146
08:09:13,840 --> 08:09:16,080
have different actions different
13147
08:09:16,080 --> 08:09:18,320
behavior we want right so it's actually
13148
08:09:18,320 --> 08:09:21,280
10 by 10 by 10 by 10
13149
08:09:21,280 --> 08:09:23,120
this state of this but there's one more
13150
08:09:23,120 --> 08:09:25,680
dimension that's whether
13151
08:09:25,680 --> 08:09:28,478
we have the item in the car or the
13152
08:09:28,478 --> 08:09:30,958
carrier or not right so it's actually 10
13153
08:09:30,958 --> 08:09:34,398
by 10 by 10 by 10 by 2 right
13154
08:09:34,398 --> 08:09:37,760
so that's the size of our universe then
13155
08:09:37,760 --> 08:09:40,240
afterwards when we have the size of that
13156
08:09:40,240 --> 08:09:42,240
we can create the table because there
13157
08:09:42,240 --> 08:09:44,160
should be one
13158
08:09:44,160 --> 08:09:46,478
entry for each
13159
08:09:46,478 --> 08:09:48,080
state there is and then we need to
13160
08:09:48,080 --> 08:09:50,638
calculate uh based
13161
08:09:50,638 --> 08:09:51,520
the
13162
08:09:51,520 --> 08:09:53,600
probability base for each action
13163
08:09:53,600 --> 08:09:56,080
possible from there right so first of
13164
08:09:56,080 --> 08:09:57,680
all we need the number of states we'll
13165
08:09:57,680 --> 08:10:00,320
make a function or a method that returns
13166
08:10:00,320 --> 08:10:02,958
the number of states and then one that
13167
08:10:02,958 --> 08:10:05,920
maps from the actual position we're in
13168
08:10:05,920 --> 08:10:08,240
to the specific state so let's try to do
13169
08:10:08,240 --> 08:10:09,680
that
13170
08:10:09,680 --> 08:10:11,920
so we'll do that in our field here
13171
08:10:11,920 --> 08:10:15,840
so let's get started
13172
08:10:15,840 --> 08:10:17,760
okay so
13173
08:10:17,760 --> 08:10:20,160
what do we want to do here is get a
13174
08:10:20,160 --> 08:10:22,320
number of
13175
08:10:22,320 --> 08:10:24,478
states
13176
08:10:24,478 --> 08:10:26,798
okay it's a self here and what it does
13177
08:10:26,798 --> 08:10:30,200
it's we already realized that it is
13178
08:10:30,200 --> 08:10:31,760
self.size
13179
08:10:31,760 --> 08:10:32,798
times
13180
08:10:32,798 --> 08:10:35,280
self.size cell the size of that size
13181
08:10:35,280 --> 08:10:37,280
right so that's basically to the power
13182
08:10:37,280 --> 08:10:38,320
of
13183
08:10:38,320 --> 08:10:39,360
four
13184
08:10:39,360 --> 08:10:42,000
and then times two right because we
13185
08:10:42,000 --> 08:10:44,878
needed the two extra there right but
13186
08:10:44,878 --> 08:10:47,360
let's for the sake of it just write it
13187
08:10:47,360 --> 08:10:49,440
out here so it's a bit more clear
13188
08:10:49,440 --> 08:10:50,558
self
13189
08:10:50,558 --> 08:10:52,478
dot size
13190
08:10:52,478 --> 08:10:54,160
times self
13191
08:10:54,160 --> 08:10:54,958
dot
13192
08:10:54,958 --> 08:10:59,200
size times two right so this is our
13193
08:10:59,200 --> 08:11:01,200
the size of the
13194
08:11:01,200 --> 08:11:04,240
q table we need to create right so now
13195
08:11:04,240 --> 08:11:06,320
we can uniquely
13196
08:11:06,320 --> 08:11:07,680
define
13197
08:11:07,680 --> 08:11:08,798
what is the
13198
08:11:08,798 --> 08:11:12,160
state we're in here right so that is now
13199
08:11:12,160 --> 08:11:14,558
we can map the state here to a specific
13200
08:11:14,558 --> 08:11:18,000
number which is in the range from
13201
08:11:18,000 --> 08:11:21,200
this size here so now we need to kind of
13202
08:11:21,200 --> 08:11:24,080
get the state right and get the state
13203
08:11:24,080 --> 08:11:26,398
so how do we calculate that right
13204
08:11:26,398 --> 08:11:28,558
so
13205
08:11:28,558 --> 08:11:30,000
this
13206
08:11:30,000 --> 08:11:30,958
is
13207
08:11:30,958 --> 08:11:33,200
done like this let's just just assume we
13208
08:11:33,200 --> 08:11:35,440
have 10 states right
13209
08:11:35,440 --> 08:11:37,680
so let's start with the position right
13210
08:11:37,680 --> 08:11:39,798
so self dot
13211
08:11:39,798 --> 08:11:43,200
position we take the first coordinate
13212
08:11:43,200 --> 08:11:45,920
and this one should be multiplied by
13213
08:11:45,920 --> 08:11:47,120
self
13214
08:11:47,120 --> 08:11:48,320
size
13215
08:11:48,320 --> 08:11:49,600
self
13216
08:11:49,600 --> 08:11:50,638
size
13217
08:11:50,638 --> 08:11:51,680
self
13218
08:11:51,680 --> 08:11:54,240
size three times and then by two right
13219
08:11:54,240 --> 08:11:55,200
because
13220
08:11:55,200 --> 08:11:57,520
this one fills out the last one of this
13221
08:11:57,520 --> 08:11:59,920
formula here right so
13222
08:11:59,920 --> 08:12:02,558
this one is the first one of this one
13223
08:12:02,558 --> 08:12:04,398
here so this one can be in the range
13224
08:12:04,398 --> 08:12:06,878
from zero to nine right and we multiply
13225
08:12:06,878 --> 08:12:09,440
zero by nine by the rest of the factor
13226
08:12:09,440 --> 08:12:11,520
here right so that's the first
13227
08:12:11,520 --> 08:12:13,760
part of the state and then we
13228
08:12:13,760 --> 08:12:16,798
just i haven't yeah let's just do it
13229
08:12:16,798 --> 08:12:18,798
like this and then we need to add the
13230
08:12:18,798 --> 08:12:20,878
next one right and that's a self
13231
08:12:20,878 --> 08:12:25,440
position again plus self position of
13232
08:12:25,440 --> 08:12:27,360
one here
13233
08:12:27,360 --> 08:12:29,200
and then we multiply by
13234
08:12:29,200 --> 08:12:31,440
this part here right you see
13235
08:12:31,440 --> 08:12:34,160
oh here
13236
08:12:34,638 --> 08:12:36,558
because and now that's that is what
13237
08:12:36,558 --> 08:12:38,478
that's corresponding to right and then
13238
08:12:38,478 --> 08:12:41,600
we take state again equals state
13239
08:12:41,600 --> 08:12:43,440
plus
13240
08:12:43,440 --> 08:12:45,200
if you're familiar with the plus equals
13241
08:12:45,200 --> 08:12:47,040
sign you can use that but if you don't
13242
08:12:47,040 --> 08:12:48,958
know what it is don't worry about it
13243
08:12:48,958 --> 08:12:51,920
and now we need the item
13244
08:12:51,920 --> 08:12:55,280
pickup position right so
13245
08:12:55,280 --> 08:12:57,920
item pickup
13246
08:12:57,920 --> 08:12:59,520
let me take this zero
13247
08:12:59,520 --> 08:13:02,558
and then we multiply by
13248
08:13:02,558 --> 08:13:04,398
in this here
13249
08:13:04,398 --> 08:13:05,920
right
13250
08:13:05,920 --> 08:13:07,120
and uh
13251
08:13:07,120 --> 08:13:08,240
that's it
13252
08:13:08,240 --> 08:13:09,760
and state
13253
08:13:09,760 --> 08:13:11,760
equals state
13254
08:13:11,760 --> 08:13:12,878
plus
13255
08:13:12,878 --> 08:13:14,958
and then we take the
13256
08:13:14,958 --> 08:13:18,478
not this one we take this one here
13257
08:13:18,478 --> 08:13:19,920
and we take the
13258
08:13:19,920 --> 08:13:21,840
second coordinate and then we multiply
13259
08:13:21,840 --> 08:13:24,240
by two right and then the final one is
13260
08:13:24,240 --> 08:13:25,920
if it is in the car but this is a
13261
08:13:25,920 --> 08:13:27,840
boolean up here so you cannot just
13262
08:13:27,840 --> 08:13:31,440
multiply it like this so we say if
13263
08:13:31,440 --> 08:13:32,958
self
13264
08:13:32,958 --> 08:13:34,638
item
13265
08:13:34,638 --> 08:13:38,878
in car if it is then we take state
13266
08:13:38,878 --> 08:13:39,958
equals
13267
08:13:39,958 --> 08:13:42,478
state plus one
13268
08:13:42,478 --> 08:13:44,398
and that's basically it so now we
13269
08:13:44,398 --> 08:13:47,440
actually can map to a specific unique
13270
08:13:47,440 --> 08:13:49,440
state so the key thing to understand
13271
08:13:49,440 --> 08:13:51,440
here is actually
13272
08:13:51,440 --> 08:13:53,600
giving a number here we actually could
13273
08:13:53,600 --> 08:13:56,958
map it backwards to a setup in this one
13274
08:13:56,958 --> 08:14:00,718
here and for each possible setup or each
13275
08:14:00,718 --> 08:14:02,478
possible state here we can map it to a
13276
08:14:02,478 --> 08:14:04,478
number and from each number we can map
13277
08:14:04,478 --> 08:14:05,760
that to a state
13278
08:14:05,760 --> 08:14:07,600
it doesn't really matter how the mapping
13279
08:14:07,600 --> 08:14:09,920
is done it just has to be unique that
13280
08:14:09,920 --> 08:14:12,718
means you cannot have two states that
13281
08:14:12,718 --> 08:14:15,040
map to the same position
13282
08:14:15,040 --> 08:14:16,718
or a position here that doesn't have a
13283
08:14:16,718 --> 08:14:18,718
state right but we have a one-to-one
13284
08:14:18,718 --> 08:14:21,040
mapping right so each state has
13285
08:14:21,040 --> 08:14:23,440
each state up here has a number and each
13286
08:14:23,440 --> 08:14:25,600
number has a state
13287
08:14:25,600 --> 08:14:27,280
one's one mapping right
13288
08:14:27,280 --> 08:14:29,920
perfect so now we can just execute this
13289
08:14:29,920 --> 08:14:31,840
one here and it doesn't really change
13290
08:14:31,840 --> 08:14:34,000
anything but it will change when we do
13291
08:14:34,000 --> 08:14:36,240
the next step where we're gonna teach
13292
08:14:36,240 --> 08:14:38,478
and update our q
13293
08:14:38,478 --> 08:14:40,798
learning table okay are you ready for
13294
08:14:40,798 --> 08:14:42,958
that this was just
13295
08:14:42,958 --> 08:14:46,798
the mapping okay see you in a moment
13296
08:14:49,200 --> 08:14:51,840
so now we're getting there right now we
13297
08:14:51,840 --> 08:14:54,798
have created a mapping from this state
13298
08:14:54,798 --> 08:14:57,440
here to a number inside our code so
13299
08:14:57,440 --> 08:14:59,600
remember we did that by these two
13300
08:14:59,600 --> 08:15:01,360
functions here or methods there the
13301
08:15:01,360 --> 08:15:03,600
first one here is to create uh return
13302
08:15:03,600 --> 08:15:06,240
the size of it you can see there's 20
13303
08:15:06,240 --> 08:15:07,920
there should be a two here
13304
08:15:07,920 --> 08:15:08,840
and
13305
08:15:08,840 --> 08:15:12,798
uh and the second one down here it is to
13306
08:15:12,798 --> 08:15:14,638
get to state right this is doing the
13307
08:15:14,638 --> 08:15:16,318
mapping and remember there's a
13308
08:15:16,318 --> 08:15:18,558
one-to-one mapping between them right so
13309
08:15:18,558 --> 08:15:21,840
let's just execute that one again
13310
08:15:21,840 --> 08:15:23,440
that being said right
13311
08:15:23,440 --> 08:15:26,000
for each state here for each position of
13312
08:15:26,000 --> 08:15:27,520
this one position of this one and
13313
08:15:27,520 --> 08:15:30,080
whether we have the item or not there is
13314
08:15:30,080 --> 08:15:32,318
a number and for each number there is a
13315
08:15:32,318 --> 08:15:34,638
state one to one right
13316
08:15:34,638 --> 08:15:36,718
the next step we need to do is implement
13317
08:15:36,718 --> 08:15:39,360
this algorithm here right so what we
13318
08:15:39,360 --> 08:15:41,680
need to do is initialize a q table with
13319
08:15:41,680 --> 08:15:44,000
all zeros we're going to use numpy for
13320
08:15:44,000 --> 08:15:45,760
that numpy is really good for that it's
13321
08:15:45,760 --> 08:15:47,600
efficient to calculate with
13322
08:15:47,600 --> 08:15:49,600
and then we need to iterate like this
13323
08:15:49,600 --> 08:15:51,600
here right so the agent is in a state so
13324
08:15:51,600 --> 08:15:53,200
we get the state and then with
13325
08:15:53,200 --> 08:15:55,120
probability epsilon we choose to explore
13326
08:15:55,120 --> 08:15:57,840
or exploit if explore then we choose a
13327
08:15:57,840 --> 08:16:00,160
random action if exploit then we choose
13328
08:16:00,160 --> 08:16:01,840
the best action based on the current
13329
08:16:01,840 --> 08:16:03,600
queue table
13330
08:16:03,600 --> 08:16:05,120
then we update the queue table with a
13331
08:16:05,120 --> 08:16:07,760
new reward to the previous state and the
13332
08:16:07,760 --> 08:16:10,160
formula is like this here right this
13333
08:16:10,160 --> 08:16:11,360
long
13334
08:16:11,360 --> 08:16:13,760
i would i was about to say beast here
13335
08:16:13,760 --> 08:16:16,878
okay so let's try to do that and
13336
08:16:16,878 --> 08:16:19,440
actually i copied this down here so we
13337
08:16:19,440 --> 08:16:20,638
have it right
13338
08:16:20,638 --> 08:16:23,280
at our disposal but first let's import
13339
08:16:23,280 --> 08:16:24,558
numpy
13340
08:16:24,558 --> 08:16:26,558
numpy as np because we're going to use
13341
08:16:26,558 --> 08:16:28,160
that for a queue table
13342
08:16:28,160 --> 08:16:29,920
and then we're going to continue our
13343
08:16:29,920 --> 08:16:32,318
journey here and actually we need to
13344
08:16:32,318 --> 08:16:34,558
initialize things just like we did here
13345
08:16:34,558 --> 08:16:37,760
so let's actually do that here
13346
08:16:37,760 --> 08:16:39,680
copy these things down here
13347
08:16:39,680 --> 08:16:41,440
and
13348
08:16:41,440 --> 08:16:42,478
let's just
13349
08:16:42,478 --> 08:16:45,200
put them here right so we need the same
13350
08:16:45,200 --> 08:16:47,600
field here and so on so
13351
08:16:47,600 --> 08:16:49,840
first off we need to make this q table
13352
08:16:49,840 --> 08:16:51,680
so we create a field to get the size of
13353
08:16:51,680 --> 08:16:54,160
the q table right q
13354
08:16:54,160 --> 08:16:56,958
table or number of states we call it a
13355
08:16:56,958 --> 08:16:58,398
number of
13356
08:16:58,398 --> 08:17:00,080
states
13357
08:17:00,080 --> 08:17:04,000
we put that to be the field and we have
13358
08:17:04,000 --> 08:17:05,120
get
13359
08:17:05,120 --> 08:17:07,760
get number of states here right and then
13360
08:17:07,760 --> 08:17:10,160
we have number of
13361
08:17:10,160 --> 08:17:12,878
actions and we put that to
13362
08:17:12,878 --> 08:17:14,240
six
13363
08:17:14,240 --> 08:17:16,558
and then we create our q table
13364
08:17:16,558 --> 08:17:17,920
like this
13365
08:17:17,920 --> 08:17:20,718
we do numpy and zeros and we'll just
13366
08:17:20,718 --> 08:17:23,280
create a numpy full of zeros and uh what
13367
08:17:23,280 --> 08:17:27,520
do we do with that we have the number of
13368
08:17:27,520 --> 08:17:31,360
states and number of
13369
08:17:31,360 --> 08:17:32,878
no
13370
08:17:32,878 --> 08:17:34,958
number of
13371
08:17:34,958 --> 08:17:38,240
actions okay so all this does is if you
13372
08:17:38,240 --> 08:17:40,318
look at the q table here is create a
13373
08:17:40,318 --> 08:17:42,080
long table like that so for each state
13374
08:17:42,080 --> 08:17:43,440
we have
13375
08:17:43,440 --> 08:17:45,040
six possible actions and they're
13376
08:17:45,040 --> 08:17:47,600
initialized to zero all of them right
13377
08:17:47,600 --> 08:17:50,878
perfect so the idea is when
13378
08:17:50,878 --> 08:17:52,958
we use this q table we will update it
13379
08:17:52,958 --> 08:17:55,120
along the way according to this
13380
08:17:55,120 --> 08:17:56,878
formula here right we have a state an
13381
08:17:56,878 --> 08:17:58,478
action and then we update it according
13382
08:17:58,478 --> 08:18:00,718
to this as we learn and either we
13383
08:18:00,718 --> 08:18:02,718
explore or exploit right
13384
08:18:02,718 --> 08:18:05,120
so for that purpose
13385
08:18:05,120 --> 08:18:07,200
let's delete this we also need
13386
08:18:07,200 --> 08:18:08,798
for epsilon
13387
08:18:08,798 --> 08:18:12,718
epsilon and we just use 0.10 you can
13388
08:18:12,718 --> 08:18:14,080
play around with these values how much
13389
08:18:14,080 --> 08:18:15,920
you want to explore and so on
13390
08:18:15,920 --> 08:18:18,398
and then you have the alpha and alpha
13391
08:18:18,398 --> 08:18:21,040
it's i don't know 0.6
13392
08:18:21,040 --> 08:18:22,080
and
13393
08:18:22,080 --> 08:18:25,520
then we need a nose alpha is 0.1 and
13394
08:18:25,520 --> 08:18:29,360
gamma to be 0.6 let's do that
13395
08:18:29,360 --> 08:18:30,398
perfect
13396
08:18:30,398 --> 08:18:32,878
so in the first step here we're actually
13397
08:18:32,878 --> 08:18:34,718
going to iterate
13398
08:18:34,718 --> 08:18:36,398
because we want to teach the algorithm
13399
08:18:36,398 --> 08:18:38,478
so we're going to do a lot of gaming so
13400
08:18:38,478 --> 08:18:41,840
that means we're going to create a field
13401
08:18:41,840 --> 08:18:43,600
use our queue table and learn along the
13402
08:18:43,600 --> 08:18:44,878
way because in beginning we're not going
13403
08:18:44,878 --> 08:18:46,398
to be that smart because we don't know
13404
08:18:46,398 --> 08:18:49,120
anything because our q table is all zero
13405
08:18:49,120 --> 08:18:52,958
so for underscore in range first of all
13406
08:18:52,958 --> 08:18:54,718
we just do one iteration because we just
13407
08:18:54,718 --> 08:18:57,280
want to test our code right
13408
08:18:57,280 --> 08:18:58,718
so what we want to do is actually we
13409
08:18:58,718 --> 08:19:01,200
want to recreate these two here because
13410
08:19:01,200 --> 08:19:04,318
we create a new field for every pass
13411
08:19:04,318 --> 08:19:06,240
actually we don't need that one up here
13412
08:19:06,240 --> 08:19:08,878
so we have a new field to start with and
13413
08:19:08,878 --> 08:19:11,280
what we're gonna do first
13414
08:19:11,280 --> 08:19:13,120
it is uh
13415
08:19:13,120 --> 08:19:15,840
we're gonna go inside here while not
13416
08:19:15,840 --> 08:19:17,760
done we're gonna continue the same thing
13417
08:19:17,760 --> 08:19:20,478
here and then we're gonna get the state
13418
08:19:20,478 --> 08:19:22,718
which state are we in well we have the
13419
08:19:22,718 --> 08:19:24,318
field here get
13420
08:19:24,318 --> 08:19:27,280
state we have the state
13421
08:19:27,280 --> 08:19:28,478
next thing
13422
08:19:28,478 --> 08:19:31,200
next thing we need to do is well we need
13423
08:19:31,200 --> 08:19:33,680
either to explore or exploit right so we
13424
08:19:33,680 --> 08:19:36,718
do explore with probability epsilon how
13425
08:19:36,718 --> 08:19:39,120
do you do that we need random did we
13426
08:19:39,120 --> 08:19:41,120
import random
13427
08:19:41,120 --> 08:19:42,798
i don't remember if we imported random
13428
08:19:42,798 --> 08:19:44,798
oh we did the naive solution here so we
13429
08:19:44,798 --> 08:19:48,160
have random already so if random we say
13430
08:19:48,160 --> 08:19:49,520
uniform
13431
08:19:49,520 --> 08:19:52,318
uniform zero point
13432
08:19:52,318 --> 08:19:53,680
zero point
13433
08:19:53,680 --> 08:19:55,360
zero comma one so that's a uniform
13434
08:19:55,360 --> 08:19:57,680
number in the interval from zero to one
13435
08:19:57,680 --> 08:20:01,600
if that is uh less less than epsilon
13436
08:20:01,600 --> 08:20:04,398
epsilon then we do random action right
13437
08:20:04,398 --> 08:20:07,520
so action will be
13438
08:20:07,840 --> 08:20:09,680
random
13439
08:20:09,680 --> 08:20:11,680
rent int
13440
08:20:11,680 --> 08:20:14,000
zero two five right a random integer
13441
08:20:14,000 --> 08:20:15,760
from zero to five
13442
08:20:15,760 --> 08:20:16,878
else
13443
08:20:16,878 --> 08:20:18,958
we do action and then we do the best
13444
08:20:18,958 --> 08:20:20,638
action we know and that's
13445
08:20:20,638 --> 08:20:24,558
we take the arc max which is a maximum
13446
08:20:24,558 --> 08:20:25,600
of
13447
08:20:25,600 --> 08:20:27,840
our q table
13448
08:20:27,840 --> 08:20:28,798
or
13449
08:20:28,798 --> 08:20:30,638
q table here
13450
08:20:30,638 --> 08:20:33,120
of the state right so what this one
13451
08:20:33,120 --> 08:20:34,638
returns here
13452
08:20:34,638 --> 08:20:37,680
i can just show you an example
13453
08:20:37,680 --> 08:20:39,840
this one will turn an entry
13454
08:20:39,840 --> 08:20:40,878
of
13455
08:20:40,878 --> 08:20:43,280
possible actions we start by all zeros
13456
08:20:43,280 --> 08:20:46,160
remember so the arc max here in this
13457
08:20:46,160 --> 08:20:48,000
case here
13458
08:20:48,000 --> 08:20:49,920
we'll just return i guess it just
13459
08:20:49,920 --> 08:20:53,440
returns the first one in this case
13460
08:20:53,440 --> 08:20:55,680
zero right but if we were in another
13461
08:20:55,680 --> 08:20:58,638
case where we had different values
13462
08:20:58,638 --> 08:21:01,120
it will return the maximum of that right
13463
08:21:01,120 --> 08:21:04,718
okay so now we have an action so
13464
08:21:04,718 --> 08:21:07,840
let's do the action and we have a reward
13465
08:21:07,840 --> 08:21:10,240
and done right if we're done right so we
13466
08:21:10,240 --> 08:21:12,840
do the field
13467
08:21:12,840 --> 08:21:14,478
action
13468
08:21:14,478 --> 08:21:15,520
oh
13469
08:21:15,520 --> 08:21:17,600
i think it was called make action
13470
08:21:17,600 --> 08:21:19,840
action right so now we are done the
13471
08:21:19,840 --> 08:21:20,798
action
13472
08:21:20,798 --> 08:21:23,120
and after that we need to make
13473
08:21:23,120 --> 08:21:25,680
update our table here and this table
13474
08:21:25,680 --> 08:21:28,478
here is this beast formula here
13475
08:21:28,478 --> 08:21:30,478
and either we can do the formula
13476
08:21:30,478 --> 08:21:32,638
immediately like this let's just see we
13477
08:21:32,638 --> 08:21:33,840
can
13478
08:21:33,840 --> 08:21:35,280
have it here
13479
08:21:35,280 --> 08:21:37,600
well this is a long line
13480
08:21:37,600 --> 08:21:39,600
but let's
13481
08:21:39,600 --> 08:21:42,240
let's let's try should we try to write
13482
08:21:42,240 --> 08:21:44,638
it directly
13483
08:21:44,638 --> 08:21:46,718
i don't know q
13484
08:21:46,718 --> 08:21:49,440
table let's try
13485
08:21:49,440 --> 08:21:51,680
uh
13486
08:21:51,760 --> 08:21:52,878
state
13487
08:21:52,878 --> 08:21:55,360
action
13488
08:21:55,360 --> 08:21:58,160
one minus alpha
13489
08:21:58,160 --> 08:21:59,840
here times
13490
08:21:59,840 --> 08:22:02,318
q state action
13491
08:22:02,318 --> 08:22:03,200
or
13492
08:22:03,200 --> 08:22:04,080
q
13493
08:22:04,080 --> 08:22:06,398
table
13494
08:22:06,398 --> 08:22:09,280
state action
13495
08:22:09,280 --> 08:22:11,520
plus alpha
13496
08:22:11,520 --> 08:22:13,120
times
13497
08:22:13,120 --> 08:22:14,718
reward
13498
08:22:14,718 --> 08:22:15,920
plus
13499
08:22:15,920 --> 08:22:17,200
gamma
13500
08:22:17,200 --> 08:22:18,558
times
13501
08:22:18,558 --> 08:22:22,240
and then we have the maximum
13502
08:22:23,120 --> 08:22:25,600
and the maximum of the new state right
13503
08:22:25,600 --> 08:22:28,638
okay so this is this is this is we need
13504
08:22:28,638 --> 08:22:31,760
we need the new state here right so
13505
08:22:31,760 --> 08:22:33,440
new state
13506
08:22:33,440 --> 08:22:35,200
is equal to
13507
08:22:35,200 --> 08:22:37,520
field get state
13508
08:22:37,520 --> 08:22:38,798
here right
13509
08:22:38,798 --> 08:22:41,600
and the maximum of that state here let's
13510
08:22:41,600 --> 08:22:45,600
just have haven't calculated here so
13511
08:22:45,600 --> 08:22:47,040
new
13512
08:22:47,040 --> 08:22:50,798
state max is equal to
13513
08:22:50,798 --> 08:22:53,200
q table
13514
08:22:53,200 --> 08:22:54,718
q table
13515
08:22:54,718 --> 08:22:58,958
new state and we just take the np max of
13516
08:22:58,958 --> 08:23:00,958
that right so i have the maximum value
13517
08:23:00,958 --> 08:23:02,718
of the new state right because we're
13518
08:23:02,718 --> 08:23:06,080
looking forward here right
13519
08:23:06,160 --> 08:23:07,280
new
13520
08:23:07,280 --> 08:23:08,878
state
13521
08:23:08,878 --> 08:23:10,000
max
13522
08:23:10,000 --> 08:23:12,318
and then we actually subtract the old
13523
08:23:12,318 --> 08:23:14,160
state q
13524
08:23:14,160 --> 08:23:16,638
table
13525
08:23:17,840 --> 08:23:19,680
state
13526
08:23:19,680 --> 08:23:22,478
action right and this should actually be
13527
08:23:22,478 --> 08:23:23,280
it
13528
08:23:23,280 --> 08:23:25,360
always a bit scary with these long
13529
08:23:25,360 --> 08:23:27,440
formulas but it looks pretty
13530
08:23:27,440 --> 08:23:29,360
accurate okay
13531
08:23:29,360 --> 08:23:30,160
so
13532
08:23:30,160 --> 08:23:32,240
so far so good so actually now we should
13533
08:23:32,240 --> 08:23:34,638
have run it once here so let's just try
13534
08:23:34,638 --> 08:23:36,718
to run it once
13535
08:23:36,718 --> 08:23:39,040
and already done so we actually solved
13536
08:23:39,040 --> 08:23:40,878
the solution one here and let's just
13537
08:23:40,878 --> 08:23:42,798
look at the queue table to see that it's
13538
08:23:42,798 --> 08:23:44,638
not all zero anymore right so now it's
13539
08:23:44,638 --> 08:23:47,200
updated not always all values are
13540
08:23:47,200 --> 08:23:49,200
updated and it's probably states that we
13541
08:23:49,200 --> 08:23:51,040
will never encounter it even though we
13542
08:23:51,040 --> 08:23:53,280
run it again and again okay
13543
08:23:53,280 --> 08:23:55,760
perfect so now we need to run it
13544
08:23:55,760 --> 08:23:57,680
multiple times and i'm a bit worried
13545
08:23:57,680 --> 08:24:00,240
about how long it takes actually
13546
08:24:00,240 --> 08:24:02,478
okay it's pretty fast so let's let's run
13547
08:24:02,478 --> 08:24:03,600
it
13548
08:24:03,600 --> 08:24:06,878
uh 1000 times here
13549
08:24:06,878 --> 08:24:09,120
let's see how it goes and it goes pretty
13550
08:24:09,120 --> 08:24:10,478
fast and
13551
08:24:10,478 --> 08:24:12,558
the more you run it the more it learns
13552
08:24:12,558 --> 08:24:13,680
right so
13553
08:24:13,680 --> 08:24:15,600
what i'm gonna do now here is going to
13554
08:24:15,600 --> 08:24:18,478
run it let's say 10 000 times and
13555
08:24:18,478 --> 08:24:19,760
then in the next one we're going to
13556
08:24:19,760 --> 08:24:22,240
evaluate how good our algorithm or our
13557
08:24:22,240 --> 08:24:24,080
queue table is based on that and i'll
13558
08:24:24,080 --> 08:24:26,000
show you in the last one how to do that
13559
08:24:26,000 --> 08:24:27,520
it's going to be amazing i promise you
13560
08:24:27,520 --> 08:24:31,840
that so see you in a moment
13561
08:24:34,080 --> 08:24:36,160
so actually it was faster than i thought
13562
08:24:36,160 --> 08:24:38,160
so actually ten thousand
13563
08:24:38,160 --> 08:24:39,680
ten thousand times is
13564
08:24:39,680 --> 08:24:41,920
probably nothing you can do it more but
13565
08:24:41,920 --> 08:24:43,520
let's just see how it performs with ten
13566
08:24:43,520 --> 08:24:45,440
thousand iterations it was just like a
13567
08:24:45,440 --> 08:24:46,878
few seconds so
13568
08:24:46,878 --> 08:24:49,280
it was like wow faster than i thought
13569
08:24:49,280 --> 08:24:51,600
right so now we want to evaluate this
13570
08:24:51,600 --> 08:24:53,760
one just like we evaluated the naive
13571
08:24:53,760 --> 08:24:55,520
solution up here remember we just did
13572
08:24:55,520 --> 08:24:57,520
the naive so we're going to make a
13573
08:24:57,520 --> 08:24:58,878
similar one
13574
08:24:58,878 --> 08:25:00,958
down here a function here which is
13575
08:25:00,958 --> 08:25:02,638
called re
13576
08:25:02,638 --> 08:25:03,680
in
13577
08:25:03,680 --> 08:25:04,798
force
13578
08:25:04,798 --> 08:25:05,680
meant
13579
08:25:05,680 --> 08:25:06,878
learning
13580
08:25:06,878 --> 08:25:09,280
and do the similar thing here right so
13581
08:25:09,280 --> 08:25:13,040
what we need here is uh the same things
13582
08:25:13,040 --> 08:25:15,360
but we don't want to overwrite what's
13583
08:25:15,360 --> 08:25:18,318
called overwrite our q table as it is
13584
08:25:18,318 --> 08:25:20,318
but we are learning along the way
13585
08:25:20,318 --> 08:25:22,318
actually so actually we
13586
08:25:22,318 --> 08:25:23,920
we want these variables and we're going
13587
08:25:23,920 --> 08:25:26,718
to do the same thing as down there
13588
08:25:26,718 --> 08:25:27,760
but
13589
08:25:27,760 --> 08:25:29,840
first thing first right so
13590
08:25:29,840 --> 08:25:32,558
we need the field here and then we need
13591
08:25:32,558 --> 08:25:33,680
to
13592
08:25:33,680 --> 08:25:37,680
see how many steps we're using now steps
13593
08:25:37,680 --> 08:25:39,840
equal to zero right and then we are
13594
08:25:39,840 --> 08:25:42,398
actually gonna do the same thing here
13595
08:25:42,398 --> 08:25:46,080
we're gonna do while not done
13596
08:25:46,080 --> 08:25:48,160
we're actually gonna do exactly
13597
08:25:48,160 --> 08:25:50,398
this
13598
08:25:50,878 --> 08:25:54,080
and this thing here
13599
08:25:54,080 --> 08:25:56,478
perfect
13600
08:25:58,398 --> 08:25:59,840
but we're going to do one more thing in
13601
08:25:59,840 --> 08:26:01,920
the end here we're going to add
13602
08:26:01,920 --> 08:26:03,040
steps
13603
08:26:03,040 --> 08:26:06,638
equals to steps plus one and then after
13604
08:26:06,638 --> 08:26:08,638
we're done here right we're going to
13605
08:26:08,638 --> 08:26:10,080
return
13606
08:26:10,080 --> 08:26:11,600
return
13607
08:26:11,600 --> 08:26:12,638
steps
13608
08:26:12,638 --> 08:26:13,600
so
13609
08:26:13,600 --> 08:26:14,878
this should basically be it because
13610
08:26:14,878 --> 08:26:17,120
we're going to do the exact same thing
13611
08:26:17,120 --> 08:26:19,440
this one was not intended correct we're
13612
08:26:19,440 --> 08:26:21,600
going to do the except exact same thing
13613
08:26:21,600 --> 08:26:22,398
here
13614
08:26:22,398 --> 08:26:24,958
and we're going to continue learning
13615
08:26:24,958 --> 08:26:27,120
because that's how the algorithm is it
13616
08:26:27,120 --> 08:26:28,718
automatically becomes smarter all the
13617
08:26:28,718 --> 08:26:30,798
time and
13618
08:26:30,798 --> 08:26:32,318
then we're going to see how many steps
13619
08:26:32,318 --> 08:26:33,600
we are using
13620
08:26:33,600 --> 08:26:36,558
after we have trained it 10 000 times
13621
08:26:36,558 --> 08:26:38,240
and you could probably train it more but
13622
08:26:38,240 --> 08:26:39,680
let's just see how it performs i have no
13623
08:26:39,680 --> 08:26:41,520
idea how it performs so let's execute
13624
08:26:41,520 --> 08:26:42,798
this one and then we have this
13625
08:26:42,798 --> 08:26:45,520
reinforcement learning and let's just
13626
08:26:45,520 --> 08:26:47,760
recall how many steps we used up in this
13627
08:26:47,760 --> 08:26:52,240
one here on average 150 000 so let's see
13628
08:26:52,240 --> 08:26:55,040
just a random run here 32
13629
08:26:55,040 --> 08:26:58,240
32 steps wow let's do again was that it
13630
08:26:58,240 --> 08:27:01,520
wow that's good so let's see how we do
13631
08:27:01,520 --> 08:27:04,478
so let's make runs again here
13632
08:27:04,478 --> 08:27:06,398
runs reinforcement learning
13633
08:27:06,398 --> 08:27:07,760
runs rl
13634
08:27:07,760 --> 08:27:09,120
so we don't overwrite the things up
13635
08:27:09,120 --> 08:27:11,920
there then we do reinforcement learning
13636
08:27:11,920 --> 08:27:13,120
and how many
13637
08:27:13,120 --> 08:27:16,000
runs did we do up there we did 100
13638
08:27:16,000 --> 08:27:19,440
so for underscore in range 100.
13639
08:27:19,440 --> 08:27:22,478
we have this one here and then we do
13640
08:27:22,478 --> 08:27:24,318
just a sum
13641
08:27:24,318 --> 08:27:26,240
of runs
13642
08:27:26,240 --> 08:27:27,280
pl
13643
08:27:27,280 --> 08:27:30,398
divided by length of runs
13644
08:27:30,398 --> 08:27:31,600
pl
13645
08:27:31,600 --> 08:27:33,120
and you see on average okay it's a bit
13646
08:27:33,120 --> 08:27:35,920
more than these were a bit lucky but 50
13647
08:27:35,920 --> 08:27:38,080
steps comparing to
13648
08:27:38,080 --> 08:27:39,280
[Music]
13649
08:27:39,280 --> 08:27:40,798
comparing to
13650
08:27:40,798 --> 08:27:44,318
150 000 steps on average okay so this is
13651
08:27:44,318 --> 08:27:46,638
what this algorithm does right isn't
13652
08:27:46,638 --> 08:27:48,080
that amazing
13653
08:27:48,080 --> 08:27:51,040
how amazing it is and let's see
13654
08:27:51,040 --> 08:27:52,958
do we remember the optimal we actually
13655
08:27:52,958 --> 08:27:54,958
did the optimal here how many steps is
13656
08:27:54,958 --> 08:27:58,240
the optimal uh so we have one two three
13657
08:27:58,240 --> 08:28:01,280
four five six seven eight nine
13658
08:28:01,280 --> 08:28:03,200
ten plus nine
13659
08:28:03,200 --> 08:28:04,558
plus nine
13660
08:28:04,558 --> 08:28:07,280
so that's 19 plus uh
13661
08:28:07,280 --> 08:28:08,958
28 plus
13662
08:28:08,958 --> 08:28:11,360
one here it is
13663
08:28:11,360 --> 08:28:13,680
twenty
13664
08:28:13,680 --> 08:28:16,638
nine right optimus 29 so actually these
13665
08:28:16,638 --> 08:28:18,318
ones were pretty good actually but on
13666
08:28:18,318 --> 08:28:19,840
average there sometimes it goes a bit
13667
08:28:19,840 --> 08:28:21,920
off track apparently and maybe these
13668
08:28:21,920 --> 08:28:25,040
outliers are way out so the optimal is
13669
08:28:25,040 --> 08:28:28,000
29 and you cannot do better than that so
13670
08:28:28,000 --> 08:28:29,680
this is pretty good this is pretty good
13671
08:28:29,680 --> 08:28:32,160
i mean i mean
13672
08:28:32,160 --> 08:28:33,440
that's nice
13673
08:28:33,440 --> 08:28:35,760
so here you have it right
13674
08:28:35,760 --> 08:28:38,558
amazing little journey we had together
13675
08:28:38,558 --> 08:28:40,878
and i really hope you enjoyed this one
13676
08:28:40,878 --> 08:28:43,120
and you see how amazing this is and we
13677
08:28:43,120 --> 08:28:45,360
actually built this from scratch
13678
08:28:45,360 --> 08:28:47,440
the only library we're using is a random
13679
08:28:47,440 --> 08:28:50,080
library and then numpy and we use just
13680
08:28:50,080 --> 08:28:51,920
the data structure from numpy we don't
13681
08:28:51,920 --> 08:28:55,280
use any advanced things and random is
13682
08:28:55,280 --> 08:28:58,000
just part of the algorithm so i hope you
13683
08:28:58,000 --> 08:29:00,478
enjoyed this one it has been amazing to
13684
08:29:00,478 --> 08:29:03,200
create your own reinforcement learning
13685
08:29:03,200 --> 08:29:06,000
model this is this is this is so crazy
13686
08:29:06,000 --> 08:29:07,920
right now you can say you can say i
13687
08:29:07,920 --> 08:29:09,840
built my own machine learning model from
13688
08:29:09,840 --> 08:29:13,440
scratch congratulations that's awesome
13689
08:29:13,440 --> 08:29:15,040
perfect so
13690
08:29:15,040 --> 08:29:17,440
thank you so much for this one and now
13691
08:29:17,440 --> 08:29:18,878
i'm just going to finish it off in the
13692
08:29:18,878 --> 08:29:22,680
next one see you in a moment
13693
08:29:24,478 --> 08:29:26,638
thank you so much for joining me on this
13694
08:29:26,638 --> 08:29:29,600
journey remember you went from the start
13695
08:29:29,600 --> 08:29:32,558
creating a simple hello world program
13696
08:29:32,558 --> 08:29:34,718
and then you learned about variables you
13697
08:29:34,718 --> 08:29:36,958
learned about program flows you learned
13698
08:29:36,958 --> 08:29:39,760
about dictionaries and lists and you
13699
08:29:39,760 --> 08:29:42,558
learned about numpy pandas you learned
13700
08:29:42,558 --> 08:29:44,638
about machine learning you created your
13701
08:29:44,638 --> 08:29:46,878
own machine learning model you should be
13702
08:29:46,878 --> 08:29:48,318
proud of yourself
13703
08:29:48,318 --> 08:29:50,398
how many people can go and say well i
13704
08:29:50,398 --> 08:29:52,318
built my own machine learning model from
13705
08:29:52,318 --> 08:29:54,958
scratch that's huge
13706
08:29:54,958 --> 08:29:56,398
and
13707
08:29:56,398 --> 08:29:58,638
many people say then what next right i
13708
08:29:58,638 --> 08:30:00,240
still don't feel i can sit down at the
13709
08:30:00,240 --> 08:30:02,718
keyboard and just type away well it
13710
08:30:02,718 --> 08:30:05,120
takes time right start with small
13711
08:30:05,120 --> 08:30:07,280
projects and build upon that and then
13712
08:30:07,280 --> 08:30:10,080
continue every single day the more you
13713
08:30:10,080 --> 08:30:12,638
do it the better we all been there and
13714
08:30:12,638 --> 08:30:13,920
we all still
13715
08:30:13,920 --> 08:30:16,240
even i i google things all the time to
13716
08:30:16,240 --> 08:30:17,840
figure out how to solve it so don't
13717
08:30:17,840 --> 08:30:20,558
worry about you don't remember it slowly
13718
08:30:20,558 --> 08:30:22,718
more and more will be on place but i'll
13719
08:30:22,718 --> 08:30:24,798
reveal to you in the end
13720
08:30:24,798 --> 08:30:26,318
there is no end there will never be a
13721
08:30:26,318 --> 08:30:27,760
day where you just remember everything
13722
08:30:27,760 --> 08:30:29,280
and knows everything
13723
08:30:29,280 --> 08:30:31,760
programming is about learning new things
13724
08:30:31,760 --> 08:30:34,240
all the time new libraries come new ways
13725
08:30:34,240 --> 08:30:35,680
to do things
13726
08:30:35,680 --> 08:30:38,398
and it continues and that's why it is so
13727
08:30:38,398 --> 08:30:40,080
awesome you learn new things all the
13728
08:30:40,080 --> 08:30:42,398
time and you can solve problems in front
13729
08:30:42,398 --> 08:30:45,440
of your computer it's so amazing right
13730
08:30:45,440 --> 08:30:47,520
i love that and i hope you kind of got
13731
08:30:47,520 --> 08:30:50,080
the energy from that because this is
13732
08:30:50,080 --> 08:30:51,920
what i want to give to you to how
13733
08:30:51,920 --> 08:30:54,000
awesome it is to program and how much
13734
08:30:54,000 --> 08:30:55,120
you can
13735
08:30:55,120 --> 08:30:56,878
build on your own in front of your
13736
08:30:56,878 --> 08:30:58,240
computer
13737
08:30:58,240 --> 08:30:59,120
so
13738
08:30:59,120 --> 08:31:00,878
what's next
13739
08:31:00,878 --> 08:31:03,280
i do have more free resources you can
13740
08:31:03,280 --> 08:31:05,760
have i have some free courses here on my
13741
08:31:05,760 --> 08:31:07,600
youtube channel you can go to my web
13742
08:31:07,600 --> 08:31:09,680
page as well there's a link below and
13743
08:31:09,680 --> 08:31:11,600
you can look at the free video courses
13744
08:31:11,600 --> 08:31:13,600
there you can scroll down there and you
13745
08:31:13,600 --> 08:31:14,958
can see
13746
08:31:14,958 --> 08:31:17,200
and then take them as well please also
13747
08:31:17,200 --> 08:31:18,718
if you didn't get the ebook get the
13748
08:31:18,718 --> 08:31:20,478
ebook because it will help you to
13749
08:31:20,478 --> 08:31:22,958
remember how to do stuff
13750
08:31:22,958 --> 08:31:24,878
finally you also have some paid courses
13751
08:31:24,878 --> 08:31:26,798
if you're really serious about this then
13752
08:31:26,798 --> 08:31:29,280
a good way is also to have some more
13753
08:31:29,280 --> 08:31:31,840
longer courses for instance i have my
13754
08:31:31,840 --> 08:31:34,240
python for finance course if you're into
13755
08:31:34,240 --> 08:31:35,520
finance and you want to learn how to
13756
08:31:35,520 --> 08:31:38,160
invest well this is a course for you and
13757
08:31:38,160 --> 08:31:41,280
it is like i think it's 21.5 hours long
13758
08:31:41,280 --> 08:31:44,080
and it is full of code similar to this
13759
08:31:44,080 --> 08:31:47,200
just in the aspect of finites and you'll
13760
08:31:47,200 --> 08:31:50,240
learn a lot with pandas and numpy and
13761
08:31:50,240 --> 08:31:52,398
actually also matplotlib these are the
13762
08:31:52,398 --> 08:31:54,478
main libraries we use in that course and
13763
08:31:54,478 --> 08:31:56,240
you'll learn how to find the right
13764
08:31:56,240 --> 08:31:58,718
investments okay so you're excited about
13765
08:31:58,718 --> 08:32:00,478
that thank you
13766
08:32:00,478 --> 08:32:02,558
finally and just say i hope you
13767
08:32:02,558 --> 08:32:04,478
subscribe to this channel because i'll
13768
08:32:04,478 --> 08:32:06,718
be posting more free tutorials like this
13769
08:32:06,718 --> 08:32:09,760
one on courses like this one and
13770
08:32:09,760 --> 08:32:11,680
yeah like subscribe and all that and
13771
08:32:11,680 --> 08:32:13,840
spread the word i
13772
08:32:13,840 --> 08:32:16,000
really the way i
13773
08:32:16,000 --> 08:32:18,478
the way i get encouraged to do this is
13774
08:32:18,478 --> 08:32:20,318
helping people so the more people that
13775
08:32:20,318 --> 08:32:22,958
know about this the better so without
13776
08:32:22,958 --> 08:32:24,878
said please leave a comment below how
13777
08:32:24,878 --> 08:32:27,840
you like this course and how you want
13778
08:32:27,840 --> 08:32:30,318
what you what your ambitions are what is
13779
08:32:30,318 --> 08:32:31,840
that you want to be do you want to be a
13780
08:32:31,840 --> 08:32:33,680
data scientist do you want to be a web
13781
08:32:33,680 --> 08:32:35,440
developer or what is it that you want to
13782
08:32:35,440 --> 08:32:37,360
be please let me know i like to hear
13783
08:32:37,360 --> 08:32:40,080
that so i know more about what troubles
13784
08:32:40,080 --> 08:32:42,080
or what challenges you have in front of
13785
08:32:42,080 --> 08:32:44,958
you so unless anything else let me know
13786
08:32:44,958 --> 08:32:47,040
in the comments so see you in the future
13787
08:32:47,040 --> 08:32:49,600
bye bye
907507
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.