All language subtitles for Learn Python - Full Course for Beginners [Tutorial]_HIGH
Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,150 --> 00:00:04,560
in this course I'm gonna teach you everything you need to know to get started programming in
2
00:00:04,590 --> 00:00:05,310
python.
3
00:00:05,700 --> 00:00:09,270
Python is one of the most popular programming languages out there,
4
00:00:09,450 --> 00:00:13,200
and it's by far one of the most sought after for jobs
5
00:00:13,410 --> 00:00:14,910
and so if you're trying to get a job
6
00:00:14,940 --> 00:00:16,170
or you're trying to you know,
7
00:00:16,200 --> 00:00:17,400
automate your life
8
00:00:17,520 --> 00:00:20,580
or you try to write awesome scripts to do a bunch of different things than
9
00:00:20,610 --> 00:00:21,840
python's for you
10
00:00:21,990 --> 00:00:22,410
honestly
11
00:00:22,440 --> 00:00:27,600
more and more developers every day are moving their projects over to python because it's such a powerful
12
00:00:27,780 --> 00:00:28,350
and the surgeon
13
00:00:28,380 --> 00:00:29,640
easy to use language,
14
00:00:29,910 --> 00:00:33,330
a lot of programming languages out there just aren't very beginner friendly there's
15
00:00:33,690 --> 00:00:38,490
a lot of syntax there's a lot of like little things that if you get wrong the program will yell at you.
16
00:00:38,700 --> 00:00:39,930
python is the complete
17
00:00:39,960 --> 00:00:40,890
opposite of that.
18
00:00:41,010 --> 00:00:45,660
you basically just type out what you want to do in python does it it's that simple there's not
19
00:00:45,870 --> 00:00:50,460
a whole lot of syntax to learn the learning curve is literally zero you jump in,
20
00:00:50,610 --> 00:00:53,100
you can start writing your first program in seconds.
21
00:00:53,370 --> 00:00:54,180
in this course
22
00:00:54,210 --> 00:00:55,260
I'm gonna teach you guys.
23
00:00:55,470 --> 00:00:57,840
everything you need to know to get started in python.
24
00:00:58,020 --> 00:00:59,070
I designed this course
25
00:00:59,100 --> 00:01:00,840
especially for python,
26
00:01:00,960 --> 00:01:03,810
and each lesson has been specially designed with examples
27
00:01:03,840 --> 00:01:05,130
that will help you along the way.
28
00:01:05,190 --> 00:01:07,800
with so many people starting to learn python the question isn't,
29
00:01:08,010 --> 00:01:11,130
why should you learn pipe on the question is why shouldn't you ?
30
00:01:11,460 --> 00:01:17,910
and I think for a lot of people the reason they might not want to learn python is because they're intimidated or they're afraid that it's going to be too hard.
31
00:01:18,240 --> 00:01:24,810
trust me I am going to hold your hand through this entire course we're going to talk about all the core concepts in python we're going to look at
32
00:01:25,170 --> 00:01:26,490
everything you need to know
33
00:01:26,580 --> 00:01:34,110
to start programming in python and start being confidence are writing scripts and start writing programs that are awesome in doing cool things in your life.
34
00:01:34,320 --> 00:01:34,800
anyway
35
00:01:34,890 --> 00:01:37,140
I'm super pumped to be teaching you guys python.
36
00:01:37,200 --> 00:01:38,850
I can't wait to get started in this course
37
00:01:38,880 --> 00:01:44,100
and I hope you guys stick around and fall along with the course and learn this amazing programming language
38
00:01:48,150 --> 00:01:52,320
in this tutorial dominates three guys how to install python onto your computer.
39
00:01:52,650 --> 00:01:56,220
and we're also going to install a text editor that we can use to write
40
00:01:56,250 --> 00:01:57,720
our python programs
41
00:01:57,780 --> 00:01:58,110
in.
42
00:01:58,590 --> 00:02:01,560
so the first order of business is to actually install
43
00:02:01,590 --> 00:02:03,360
python on your computer.
44
00:02:03,660 --> 00:02:06,120
so we want to do is head over to your web browser
45
00:02:06,630 --> 00:02:07,140
and
46
00:02:07,170 --> 00:02:09,330
you want to go over here to this page it's just
47
00:02:09,690 --> 00:02:12,180
www dot python dot org
48
00:02:12,210 --> 00:02:13,260
forward slash
49
00:02:13,290 --> 00:02:14,130
downloads
50
00:02:14,430 --> 00:02:14,940
and on this
51
00:02:14,970 --> 00:02:15,780
page there's
52
00:02:15,810 --> 00:02:16,350
going to be
53
00:02:16,380 --> 00:02:17,700
two buttons down here
54
00:02:18,030 --> 00:02:21,540
and this is going to say download python three point six point three.
55
00:02:21,990 --> 00:02:22,590
and at least
56
00:02:22,620 --> 00:02:26,850
the version that I have right now or download python two point seven point one four.
57
00:02:27,420 --> 00:02:31,770
so here's the thing about python there's actually two major versions of python
58
00:02:31,800 --> 00:02:32,940
that are in use
59
00:02:32,970 --> 00:02:33,570
currently
60
00:02:33,930 --> 00:02:34,440
there is
61
00:02:34,470 --> 00:02:35,640
python two
62
00:02:35,700 --> 00:02:38,130
and there's python theories you can see over here,
63
00:02:38,340 --> 00:02:40,920
this is like two point seven point one four
64
00:02:41,610 --> 00:02:43,890
basically any python two
65
00:02:43,980 --> 00:02:46,170
version we would just refer to as like python two
66
00:02:46,440 --> 00:02:47,670
and here's like the latest
67
00:02:47,700 --> 00:02:49,200
python three version.
68
00:02:49,380 --> 00:02:55,230
and so there's these two versions that you can download and the first thing we have to decide on which version do we want to download.
69
00:02:55,500 --> 00:02:56,760
and here's the basic difference
70
00:02:56,820 --> 00:02:57,540
python
71
00:02:57,570 --> 00:02:58,230
two
72
00:02:58,500 --> 00:03:01,920
is a legacy version of python which basically means that
73
00:03:02,160 --> 00:03:02,760
it's like an
74
00:03:02,790 --> 00:03:07,170
old version and it's not being like actively maintained or supported
75
00:03:07,350 --> 00:03:09,570
like officially by python anymore.
76
00:03:09,870 --> 00:03:10,380
python
77
00:03:10,410 --> 00:03:16,830
three is like the future of python it's like the newest version it's the one that's getting actively maintained and supported.
78
00:03:17,130 --> 00:03:19,830
so there's pros and cons to picking either won
79
00:03:20,490 --> 00:03:22,770
a lot of people say like python too
80
00:03:22,830 --> 00:03:25,440
has been around longer and so there's more like
81
00:03:25,590 --> 00:03:30,270
libraries there's basically just more python code written in python two
82
00:03:30,600 --> 00:03:35,400
so therefore like there's a few more things that you can do in pipe onto then you can do in python three
83
00:03:35,730 --> 00:03:36,630
but then again
84
00:03:36,780 --> 00:03:38,880
python two is not supported and you know,
85
00:03:38,970 --> 00:03:40,350
five or ten years from now
86
00:03:40,380 --> 00:03:42,120
probably no one's going to be using it.
87
00:03:42,810 --> 00:03:47,100
python three it like a site is like the future of python it's the newest version it's the one that
88
00:03:47,130 --> 00:03:49,800
you know it's sort of being maintained going forward.
89
00:03:50,280 --> 00:03:53,460
so for the purposes of this tutorial I'm going to be teaching you guys
90
00:03:53,490 --> 00:03:54,240
python
91
00:03:54,270 --> 00:03:55,020
three
92
00:03:55,200 --> 00:03:57,120
so we're going to want to download python
93
00:03:57,150 --> 00:03:57,600
three
94
00:03:57,840 --> 00:03:58,860
now here's vaguely
95
00:03:59,040 --> 00:04:03,450
if you learn python three or you learn python to the differences aren't very big.
96
00:04:03,720 --> 00:04:07,050
there are a few differences in like some syntax and just so
97
00:04:07,080 --> 00:04:08,700
you know little things here and there,
98
00:04:08,760 --> 00:04:11,700
but if you learn python three you'll be able to jump right in and
99
00:04:11,730 --> 00:04:14,610
code in python two as well don't let anyone
100
00:04:14,940 --> 00:04:15,630
tell you that
101
00:04:15,720 --> 00:04:17,040
you have to learn one of the other.
102
00:04:17,100 --> 00:04:21,840
we're going to learn python three just because it's I think probably the best for a beginner to learn.
103
00:04:22,050 --> 00:04:26,159
and so that's the one that we want to download so I'm just going to click download python three
104
00:04:26,489 --> 00:04:27,749
and we're gonna go ahead and download
105
00:04:27,779 --> 00:04:28,649
this version.
106
00:04:29,009 --> 00:04:33,089
and when that's done downloading I'm going to head down to my downloads folder
107
00:04:33,989 --> 00:04:35,969
and you'll see here we just have this file
108
00:04:36,989 --> 00:04:37,679
doubleclick,
109
00:04:37,949 --> 00:04:41,609
and we get this like python installer so I'm going to click through here,
110
00:04:42,029 --> 00:04:45,359
and we'll be able to install python three on our computer
111
00:04:45,509 --> 00:04:51,449
right when that's done and stalling we can just close out of this and we should begin to get us now we have python three
112
00:04:51,719 --> 00:04:53,159
installed on our computer.
113
00:04:53,549 --> 00:04:54,479
the next step
114
00:04:54,509 --> 00:04:56,399
is we need to choose a text
115
00:04:56,429 --> 00:04:57,239
editor so
116
00:04:57,899 --> 00:05:04,529
we're going to be writing a bunch of code so we're going to need some you know environment of some program that we can write all that code in.
117
00:05:04,829 --> 00:05:09,959
and really you can write python in any text editor you could write it in like a note pad or tax at it,
118
00:05:10,199 --> 00:05:11,099
it doesn't really matter
119
00:05:11,339 --> 00:05:13,019
but there are special
120
00:05:13,049 --> 00:05:14,699
text editors that are designed
121
00:05:14,729 --> 00:05:16,979
just for writing python code.
122
00:05:17,249 --> 00:05:18,209
and these are called
123
00:05:18,269 --> 00:05:20,129
id ease and not stands for
124
00:05:20,159 --> 00:05:22,019
integrated development environment.
125
00:05:22,379 --> 00:05:27,269
it's basically just a special environment where we can you know ron and execute our python code.
126
00:05:27,479 --> 00:05:30,569
and it'll you know basically like tell us how we're doing so were
127
00:05:30,629 --> 00:05:32,879
the only if we write something that's wrong or we
128
00:05:32,909 --> 00:05:34,109
have errors it'll kind of
129
00:05:34,529 --> 00:05:37,259
point us in the right direction of what we need to do to fix that stuff,
130
00:05:37,649 --> 00:05:39,779
so in this course we're going to be using an idea
131
00:05:39,809 --> 00:05:40,229
and
132
00:05:40,259 --> 00:05:41,219
one of my favorites
133
00:05:41,249 --> 00:05:44,879
and one of the most popular ity ease for python is called pi charm.
134
00:05:45,239 --> 00:05:46,889
so I'm over here on this website.
135
00:05:46,949 --> 00:05:47,489
it's called
136
00:05:47,519 --> 00:05:48,599
jet brains
137
00:05:48,629 --> 00:05:49,559
dotcom
138
00:05:49,589 --> 00:05:50,519
forward slash
139
00:05:50,549 --> 00:05:51,329
pi charm.
140
00:05:51,659 --> 00:05:54,569
and this is the idea that we're gonna be using in this course
141
00:05:54,599 --> 00:05:57,029
so I'm just gonna come over here and click this big download
142
00:05:57,059 --> 00:05:57,809
now button
143
00:05:58,319 --> 00:05:59,668
and we'll go ahead and
144
00:05:59,698 --> 00:06:00,629
download this
145
00:06:00,659 --> 00:06:01,979
pie charm program
146
00:06:02,309 --> 00:06:06,268
right so I'm getting this page are here you can see there's two versions of pi charm
147
00:06:06,478 --> 00:06:09,958
one as a professional version and that one's like paid they have to pay for it.
148
00:06:10,228 --> 00:06:14,878
but then there's this community version down here and that's free and open source so I'm going to download this one
149
00:06:15,268 --> 00:06:18,688
and this should have everything we need to get started using python
150
00:06:19,258 --> 00:06:21,658
right when that finishes downloading I'm just going to
151
00:06:21,688 --> 00:06:23,458
pull that up in my downloads folder
152
00:06:23,938 --> 00:06:24,538
and
153
00:06:24,598 --> 00:06:25,738
again we can just sort of
154
00:06:25,768 --> 00:06:26,818
run this guy
155
00:06:26,938 --> 00:06:30,778
and I'm on a mac so I'm going to have to drag it over to my applications folder.
156
00:06:31,258 --> 00:06:33,058
all right so now have pi charm
157
00:06:33,088 --> 00:06:34,498
and we have python
158
00:06:34,528 --> 00:06:36,328
three installed on your computer.
159
00:06:36,748 --> 00:06:39,118
so we're ready to start programming in
160
00:06:39,148 --> 00:06:39,868
python.
161
00:06:43,768 --> 00:06:46,108
in this tutorial we're going to create our first
162
00:06:46,138 --> 00:06:47,248
python program.
163
00:06:47,518 --> 00:06:48,988
and we're going to be able to run it and
164
00:06:49,048 --> 00:06:50,848
see how everything works.
165
00:06:51,088 --> 00:06:52,708
the first thing I want to do is open up
166
00:06:52,738 --> 00:06:54,808
pi charm so pi charm was the
167
00:06:54,838 --> 00:06:55,948
idea he the
168
00:06:56,008 --> 00:06:57,658
integrated development environment
169
00:06:57,928 --> 00:07:00,388
that we downloaded in the last tutorial so
170
00:07:00,658 --> 00:07:02,698
I'm just going to go out and search for it on my computer
171
00:07:03,508 --> 00:07:04,708
and I can just open it up
172
00:07:04,768 --> 00:07:07,918
and we first opened up high charm we should basically just get a window
173
00:07:07,948 --> 00:07:10,588
prompting us to create a project.
174
00:07:10,858 --> 00:07:12,058
so you can see that down here.
175
00:07:12,328 --> 00:07:15,777
actually the first thing I want to do though is come over here to configure
176
00:07:16,287 --> 00:07:17,247
and I'm just going to
177
00:07:17,277 --> 00:07:18,627
click on preferences.
178
00:07:19,077 --> 00:07:20,757
and I actually want to
179
00:07:20,787 --> 00:07:22,347
change the appearance
180
00:07:22,377 --> 00:07:22,887
so
181
00:07:23,337 --> 00:07:24,627
I'm gonna go ahead and
182
00:07:25,167 --> 00:07:28,707
give this a theme so I just went over here to appearance and behavior appearance
183
00:07:29,067 --> 00:07:30,927
and I'm gonna change the theme to
184
00:07:31,047 --> 00:07:31,767
darker color
185
00:07:31,917 --> 00:07:33,807
because I think it's a little bit easier to
186
00:07:33,897 --> 00:07:35,037
use and look at,
187
00:07:35,247 --> 00:07:36,957
but you don't have to do that if you don't want you
188
00:07:37,437 --> 00:07:38,037
so
189
00:07:38,067 --> 00:07:38,727
down here
190
00:07:38,757 --> 00:07:39,507
I'm just going to click
191
00:07:39,537 --> 00:07:40,917
create new projects
192
00:07:41,307 --> 00:07:41,967
and it's going to
193
00:07:41,997 --> 00:07:45,567
give us this little window right here so I can just name my project.
194
00:07:45,897 --> 00:07:47,157
and I'm just going to name this
195
00:07:47,217 --> 00:07:47,967
graph.
196
00:07:48,597 --> 00:07:51,777
and then there's other option down here where it says interpreter.
197
00:07:52,167 --> 00:07:52,677
now
198
00:07:53,487 --> 00:07:54,657
what we wanna select
199
00:07:54,687 --> 00:07:55,287
is
200
00:07:55,377 --> 00:07:57,087
python version three
201
00:07:57,117 --> 00:08:00,837
so if I click down here you'll notice that there's a couple different options.
202
00:08:01,077 --> 00:08:02,907
so I'm on a mac computer
203
00:08:02,937 --> 00:08:03,387
and
204
00:08:03,417 --> 00:08:05,517
by default mac has
205
00:08:05,577 --> 00:08:06,237
python
206
00:08:06,267 --> 00:08:08,127
version two installed on it.
207
00:08:08,427 --> 00:08:11,277
if you're on a windows machine I'm not sure if it does but
208
00:08:11,907 --> 00:08:16,437
in this tutorial we're going to be using python three so you wanna make sure that you have python
209
00:08:16,467 --> 00:08:18,807
three selected as the interpreter,
210
00:08:19,077 --> 00:08:19,587
otherwise
211
00:08:19,737 --> 00:08:19,977
you
212
00:08:20,007 --> 00:08:23,007
might not be able to fully follow along with what we're doing in this video.
213
00:08:23,307 --> 00:08:25,377
so now it's going to come down here and click
214
00:08:25,407 --> 00:08:26,007
create.
215
00:08:26,277 --> 00:08:28,737
and this is going to go ahead and create our projects
216
00:08:28,767 --> 00:08:29,517
for us
217
00:08:29,607 --> 00:08:30,807
right so now we have
218
00:08:30,837 --> 00:08:31,377
our
219
00:08:31,407 --> 00:08:32,307
python project
220
00:08:32,337 --> 00:08:32,967
up and running,
221
00:08:33,327 --> 00:08:36,177
and I'm sure you guys how we can create our first
222
00:08:36,297 --> 00:08:37,617
python program,
223
00:08:37,917 --> 00:08:42,297
so over here in this draft folder and this is just that project that we created.
224
00:08:42,747 --> 00:08:43,737
I'm just going to right click
225
00:08:43,767 --> 00:08:44,937
and I'm saying new
226
00:08:45,627 --> 00:08:46,857
and I'm going to come down and click
227
00:08:46,887 --> 00:08:50,487
python file so we want to create a new python file this will be our first
228
00:08:50,517 --> 00:08:51,567
python program.
229
00:08:52,137 --> 00:08:52,467
and
230
00:08:52,497 --> 00:08:53,787
I can just give this a name,
231
00:08:53,847 --> 00:08:55,197
so why don't we just call this
232
00:08:55,287 --> 00:08:55,617
app
233
00:08:55,737 --> 00:08:56,817
and it's going to click ok
234
00:08:56,937 --> 00:08:59,097
all right so now we have our first
235
00:08:59,127 --> 00:08:59,937
python file
236
00:08:59,967 --> 00:09:00,507
open
237
00:09:01,017 --> 00:09:04,407
and we can just start typing in some python so I want to show you guys.
238
00:09:04,617 --> 00:09:06,837
does a very basic python program.
239
00:09:07,047 --> 00:09:11,698
and this is just going to be a hello world programs so we're just gonna print something out onto the screen.
240
00:09:11,998 --> 00:09:12,538
so when I say
241
00:09:12,598 --> 00:09:15,928
what I want to do is I want to type out p r iyer anti prince
242
00:09:16,348 --> 00:09:17,008
and wanted to have an
243
00:09:17,038 --> 00:09:17,938
open and closed
244
00:09:17,968 --> 00:09:18,808
parentheses
245
00:09:19,048 --> 00:09:19,348
now
246
00:09:19,378 --> 00:09:21,838
inside of those parentheses we can make some
247
00:09:21,868 --> 00:09:22,798
quotation marks
248
00:09:23,008 --> 00:09:25,408
and inside of the quotation marks I'm just going to tape out
249
00:09:25,468 --> 00:09:26,218
hello
250
00:09:26,278 --> 00:09:26,818
world.
251
00:09:27,148 --> 00:09:29,968
so this is like a very basic python program.
252
00:09:30,178 --> 00:09:31,438
and what this is gonna do is
253
00:09:31,468 --> 00:09:33,718
it's just going to print out hello world
254
00:09:33,748 --> 00:09:34,828
onto the screen.
255
00:09:35,278 --> 00:09:36,568
and so now what I can do
256
00:09:36,658 --> 00:09:41,068
is I can actually run this file and we're actually getting a little arrow here it wants us to create a new line
257
00:09:41,368 --> 00:09:42,448
at the end of the file.
258
00:09:42,988 --> 00:09:47,518
and so now in order to run our python program I'm just going to come up here to the top
259
00:09:47,908 --> 00:09:49,348
and I'm cinematic run
260
00:09:49,468 --> 00:09:51,448
and we'll click this run button right here
261
00:09:51,868 --> 00:09:52,948
and I will see what happens
262
00:09:52,979 --> 00:09:53,729
so it's
263
00:09:53,789 --> 00:09:56,249
asking me what I want to run I can just click add up
264
00:09:56,939 --> 00:09:57,359
and
265
00:09:57,389 --> 00:10:01,679
down here at the bottom you'll notice that we have this text that just got printed out
266
00:10:01,709 --> 00:10:02,639
hello world,
267
00:10:02,999 --> 00:10:03,509
so
268
00:10:03,569 --> 00:10:04,349
whatever I
269
00:10:04,409 --> 00:10:04,919
print
270
00:10:05,159 --> 00:10:08,219
or whatever I put inside of this print statement is going to get printed out
271
00:10:08,249 --> 00:10:10,079
down below in the council so
272
00:10:10,319 --> 00:10:13,019
as long as you're getting that print statements work then you
273
00:10:13,109 --> 00:10:15,359
actually written your first python program.
274
00:10:15,659 --> 00:10:16,499
and as we go through it
275
00:10:16,529 --> 00:10:18,059
forward in the course were can be writing
276
00:10:18,089 --> 00:10:20,159
all sorts of awesome python programs.
277
00:10:20,219 --> 00:10:21,059
and we're going to do an
278
00:10:21,089 --> 00:10:22,379
all sorts of cool stuff
279
00:10:26,129 --> 00:10:33,299
in this tutorial I wanna talk to you about writing a basic python programs so we're going to write it as a very simple python program.
280
00:10:33,449 --> 00:10:36,929
we're going to look at how we can go ahead and write up programs we're going to talk about
281
00:10:37,079 --> 00:10:40,229
how our programs are getting executed by python
282
00:10:40,529 --> 00:10:44,099
and we're also going to draw out a little shape onto the screen so
283
00:10:44,339 --> 00:10:46,109
this is going to be pretty cool I'm excited to
284
00:10:46,139 --> 00:10:47,519
talk you guys about just the
285
00:10:47,549 --> 00:10:49,200
bare basics of python,
286
00:10:49,440 --> 00:10:51,720
and really just sort of give you an introduction so
287
00:10:51,810 --> 00:10:52,470
over here
288
00:10:52,650 --> 00:10:53,790
we have our
289
00:10:53,820 --> 00:10:55,320
basic text editor and so
290
00:10:55,680 --> 00:10:56,880
any of the
291
00:10:56,940 --> 00:10:59,790
python code that I write inside of this file
292
00:10:59,970 --> 00:11:02,910
is actually going to get executed by a python so
293
00:11:03,120 --> 00:11:04,440
this python file
294
00:11:04,470 --> 00:11:05,430
has a bunch of
295
00:11:05,460 --> 00:11:06,960
python code inside of it.
296
00:11:07,410 --> 00:11:09,600
and basically what we're doing when we're
297
00:11:09,630 --> 00:11:13,770
programming in python is we're just giving the computer a set of instructions.
298
00:11:14,070 --> 00:11:18,150
right that's really what programming is it's just like we're specifying a set of instructions
299
00:11:18,390 --> 00:11:22,470
and the computer is going to go off and execute those instructions that we give it.
300
00:11:22,980 --> 00:11:23,460
and so
301
00:11:23,490 --> 00:11:27,030
the more complex the instructions we give to the computer the more complex
302
00:11:27,060 --> 00:11:27,900
the tasks
303
00:11:27,930 --> 00:11:28,890
the computer can
304
00:11:28,950 --> 00:11:29,610
carry up.
305
00:11:30,090 --> 00:11:34,620
so I'll show you guys how we can use some python instructions or some python code
306
00:11:34,890 --> 00:11:37,710
in order to draw out a shape onto the screen so
307
00:11:37,950 --> 00:11:39,090
I'm actually going to draw out
308
00:11:39,120 --> 00:11:40,230
a little triangle.
309
00:11:40,650 --> 00:11:41,490
so over here,
310
00:11:41,550 --> 00:11:43,950
we can actually print something out onto the
311
00:11:43,980 --> 00:11:48,060
screen and python using something called a print statement so I can just type out
312
00:11:48,090 --> 00:11:48,540
print.
313
00:11:48,960 --> 00:11:50,970
and inside of these parentheses.
314
00:11:51,390 --> 00:11:52,260
I can just type
315
00:11:52,410 --> 00:11:53,700
some quotation marks
316
00:11:53,730 --> 00:11:54,990
and inside the quotation marks
317
00:11:55,020 --> 00:11:55,410
we can
318
00:11:55,440 --> 00:11:57,480
put whatever we want to print out onto the screen.
319
00:11:57,990 --> 00:11:58,890
so I'm gonna
320
00:11:58,980 --> 00:12:00,631
copy this and I'm actually going to make
321
00:12:00,661 --> 00:12:02,761
a few of these little prince statements
322
00:12:02,971 --> 00:12:04,441
and we're going actually draw a sheep.
323
00:12:04,801 --> 00:12:05,371
so
324
00:12:05,431 --> 00:12:06,391
we're gonna draw like
325
00:12:06,421 --> 00:12:07,921
a triangle type shape
326
00:12:07,951 --> 00:12:10,201
so down here it's gonna draw a forward slash
327
00:12:10,531 --> 00:12:13,951
and then up here I'll make a space and we'll do another foreign sash
328
00:12:14,371 --> 00:12:14,911
here will make
329
00:12:14,941 --> 00:12:16,051
two spaces
330
00:12:16,411 --> 00:12:17,791
with united forward slash.
331
00:12:17,851 --> 00:12:18,691
and over here
332
00:12:18,751 --> 00:12:20,731
we can make three spaces and afford sash.
333
00:12:21,301 --> 00:12:24,721
and now I'm going to draw like a vertical bar is going all the way down.
334
00:12:27,391 --> 00:12:29,701
and actually we can do some underscores here as well.
335
00:12:29,791 --> 00:12:30,511
I think high school
336
00:12:32,011 --> 00:12:35,191
right so now we have our triangle looking shave and you can see
337
00:12:35,461 --> 00:12:37,381
it looks kind of like a right triangle
338
00:12:37,501 --> 00:12:38,911
so I can save my file.
339
00:12:39,211 --> 00:12:41,971
and I can either come up here to run and
340
00:12:42,031 --> 00:12:43,231
click run app
341
00:12:43,531 --> 00:12:47,281
or of using pie charm you can also just come over here and click this play button
342
00:12:47,881 --> 00:12:51,451
and when I click the play button I want you to notice what happens down here
343
00:12:51,751 --> 00:12:52,231
so
344
00:12:52,291 --> 00:12:54,481
down here we have this little window and
345
00:12:54,511 --> 00:12:56,101
this is called the consul
346
00:12:56,611 --> 00:13:00,182
and it basically the council is a place where python is going to
347
00:13:00,242 --> 00:13:02,042
output some information so
348
00:13:02,341 --> 00:13:05,612
when we use this print statement were basically telling python late
349
00:13:05,822 --> 00:13:08,012
hey can you print something out onto the consul.
350
00:13:08,282 --> 00:13:08,612
so
351
00:13:08,642 --> 00:13:12,722
there's a lot of situations where we're gonna wanna see what's going on in our code.
352
00:13:13,052 --> 00:13:14,852
and we can use that print statement and
353
00:13:14,912 --> 00:13:16,562
print things out to the council.
354
00:13:16,802 --> 00:13:20,582
and we can basically like have a little window into what our programs doing
355
00:13:20,972 --> 00:13:24,512
in our case we're just going to be printing out this triangle onto the consul.
356
00:13:24,962 --> 00:13:27,242
so I'm gonna come over here and click this play button
357
00:13:27,722 --> 00:13:28,742
and you'll see down here
358
00:13:28,772 --> 00:13:30,302
we're actually printing out that
359
00:13:30,332 --> 00:13:30,932
triangle
360
00:13:31,172 --> 00:13:34,172
so mission accomplished we were able to print out our shape.
361
00:13:34,502 --> 00:13:37,592
so I can really draw any shape I want it as long as I was
362
00:13:37,622 --> 00:13:38,252
able to
363
00:13:38,282 --> 00:13:39,092
specify
364
00:13:39,122 --> 00:13:40,622
inside of these print statements.
365
00:13:41,162 --> 00:13:41,552
so
366
00:13:41,583 --> 00:13:44,883
essentially what python's doing when I click that play button
367
00:13:45,062 --> 00:13:49,623
is it's going into this file and it's looking at all of these instructions in order.
368
00:13:49,833 --> 00:13:52,623
so the first thing it does is it goes to this instruction and it says
369
00:13:52,653 --> 00:13:53,073
ok,
370
00:13:53,253 --> 00:13:57,903
they want me to draw out these like little forward slash in this vertical bar onto the strain,
371
00:13:58,203 --> 00:14:01,083
once it does that it goes down to this instruction it says
372
00:14:01,113 --> 00:14:01,413
ok
373
00:14:01,443 --> 00:14:02,883
they want me to print something on again
374
00:14:03,183 --> 00:14:05,613
when it prints dot out it goes down to this instruction
375
00:14:05,643 --> 00:14:06,273
etc
376
00:14:06,723 --> 00:14:07,203
so
377
00:14:07,233 --> 00:14:11,223
python is actually going to execute the lines of code that we write
378
00:14:11,523 --> 00:14:12,303
in order.
379
00:14:12,513 --> 00:14:12,933
so
380
00:14:12,963 --> 00:14:14,913
the order in which I write the instructions
381
00:14:14,943 --> 00:14:16,083
matters a lot.
382
00:14:16,173 --> 00:14:18,963
so for example if I was to take this last line here
383
00:14:19,263 --> 00:14:20,944
and put it up here at the top.
384
00:14:22,264 --> 00:14:23,704
now when I save the file.
385
00:14:23,764 --> 00:14:25,744
instead of just drawing up that triangle.
386
00:14:26,014 --> 00:14:27,034
it's going to draw out
387
00:14:27,064 --> 00:14:28,534
this little upside down
388
00:14:28,564 --> 00:14:30,154
bottom thing at the top and then
389
00:14:30,184 --> 00:14:31,864
the rest of the triangle down here so
390
00:14:32,194 --> 00:14:35,854
the order of the instructions actually matters a lot.
391
00:14:35,974 --> 00:14:39,154
so this is basically how your python programs are going to go.
392
00:14:39,214 --> 00:14:48,304
as we go through this course we're going to learn more and more of these little lines so here we're just using this little print function basically and just print something out on to the screen,
393
00:14:48,484 --> 00:14:51,634
there's a bunch of little things like this that we can learn as we go through
394
00:14:51,844 --> 00:14:55,504
will learn more and more instructions that we can give to the computer.
395
00:14:55,864 --> 00:14:58,984
but in this lesson I just wanted to kind of show you guys the basics right.
396
00:14:59,224 --> 00:14:59,674
oh
397
00:15:00,184 --> 00:15:03,934
we can essentially just define these little instructions for the computer
398
00:15:04,114 --> 00:15:06,004
and the computer will execute them
399
00:15:06,034 --> 00:15:06,694
in order.
400
00:15:10,504 --> 00:15:14,555
and this tutorial I wanna talk to you guys about using variables in
401
00:15:14,585 --> 00:15:15,395
python.
402
00:15:15,875 --> 00:15:17,945
now in python and you're going to be dealing with
403
00:15:17,975 --> 00:15:19,235
a lot of data
404
00:15:19,265 --> 00:15:21,935
and so a lot of times in our program we're going to be working with
405
00:15:21,965 --> 00:15:25,205
all types of information and data and values,
406
00:15:25,625 --> 00:15:27,005
and sometimes that data
407
00:15:27,035 --> 00:15:28,835
can be difficult to manage.
408
00:15:29,165 --> 00:15:32,465
so in python we have this thing called a variable.
409
00:15:32,705 --> 00:15:34,715
and it's basically just a container
410
00:15:34,985 --> 00:15:36,485
where we can store certain
411
00:15:36,515 --> 00:15:37,565
data values.
412
00:15:37,775 --> 00:15:40,055
and when we use a variable when we put those
413
00:15:40,115 --> 00:15:42,065
data values inside containers.
414
00:15:42,245 --> 00:15:43,145
it makes it a lot
415
00:15:43,175 --> 00:15:45,605
easier for us to work with and manage
416
00:15:45,635 --> 00:15:46,565
all of the different
417
00:15:46,595 --> 00:15:48,515
data inside of our programs.
418
00:15:48,815 --> 00:15:51,995
so variables are extremely helpful and it's sort of like a
419
00:15:52,025 --> 00:15:53,585
core topic in
420
00:15:53,735 --> 00:15:56,195
python that you're really going to want to know and master.
421
00:15:56,585 --> 00:15:58,655
so in this tutorial omelets each you guys.
422
00:15:58,745 --> 00:16:02,616
everything you need to know to get started with variables we're going to look at what they are
423
00:16:02,826 --> 00:16:05,916
why they're useful and we'll look at the different types of variables
424
00:16:05,946 --> 00:16:06,936
and the different types of
425
00:16:07,026 --> 00:16:08,616
data that we can store
426
00:16:08,646 --> 00:16:09,846
inside of variables,
427
00:16:10,026 --> 00:16:11,256
who over here in my
428
00:16:11,286 --> 00:16:13,806
python file I just have a very simple program.
429
00:16:14,196 --> 00:16:17,406
and it's basically just printing some text out onto the screen.
430
00:16:17,826 --> 00:16:20,556
and so this is actually a little story that I wrote it says.
431
00:16:20,796 --> 00:16:22,686
there once was a man named george
432
00:16:23,016 --> 00:16:24,636
he was seventy years old.
433
00:16:24,966 --> 00:16:26,646
he really liked the name george
434
00:16:26,826 --> 00:16:28,836
but didn't like being seventy.
435
00:16:29,166 --> 00:16:32,136
so this is a valid python program I can go ahead and
436
00:16:32,166 --> 00:16:33,156
run this program
437
00:16:33,546 --> 00:16:35,676
and you'll see down here in the council
438
00:16:35,706 --> 00:16:37,056
everything prints out and
439
00:16:37,116 --> 00:16:38,076
it looks great so
440
00:16:38,376 --> 00:16:40,386
we have an awesome little python program here.
441
00:16:40,806 --> 00:16:44,586
well let's say that inside of our story I wanted to change
442
00:16:44,617 --> 00:16:46,026
the character's name
443
00:16:46,057 --> 00:16:49,597
so instead of naming the character george let's say I wanted to name the character
444
00:16:49,627 --> 00:16:50,197
jon
445
00:16:50,617 --> 00:16:51,067
well
446
00:16:51,247 --> 00:16:59,557
I'm going to have to go through and I'm going to have to manually change the name george to the name john at every place inside of this story where it's mentioned.
447
00:16:59,647 --> 00:17:01,927
so I'm not to go over here and I'll say
448
00:17:01,957 --> 00:17:02,227
ok
449
00:17:02,257 --> 00:17:04,537
john I'm going to have to manually change that
450
00:17:04,777 --> 00:17:05,467
and then
451
00:17:05,497 --> 00:17:09,846
ok it's out here we're going up to again manually type in john and change it to john.
452
00:17:10,386 --> 00:17:15,606
so in order to change the character's name I had to manually go in and change it in both places.
453
00:17:16,086 --> 00:17:17,046
and now let's say
454
00:17:17,076 --> 00:17:17,376
ok
455
00:17:17,406 --> 00:17:19,626
maybe we want to change the characters ne
456
00:17:19,806 --> 00:17:22,446
age also so in addition to changing the name.
457
00:17:22,716 --> 00:17:28,656
we also want to change the age let's make him a little bit younger so why don't we say john is going to be thirty five.
458
00:17:29,406 --> 00:17:34,747
so you see here I had to come here and manually change the age and then come down here
459
00:17:35,017 --> 00:17:36,787
and manually change it again
460
00:17:37,207 --> 00:17:37,627
right.
461
00:17:38,017 --> 00:17:39,247
and now that we changed it like
462
00:17:39,277 --> 00:17:41,587
it's going to work it's going to be updated in our program.
463
00:17:41,977 --> 00:17:47,947
but you'll notice that in order to make that change like I had to look through the entire program find it where that
464
00:17:47,977 --> 00:17:49,597
value was and change it,
465
00:17:49,657 --> 00:17:50,077
and
466
00:17:50,137 --> 00:17:51,517
this was only with
467
00:17:51,547 --> 00:17:52,447
four lines
468
00:17:52,477 --> 00:17:55,357
of the story imagine if I had a story that was like
469
00:17:55,537 --> 00:17:57,067
thousands of lines long.
470
00:17:57,337 --> 00:17:59,017
and we mentioned that the character's name and
471
00:17:59,047 --> 00:17:59,707
age like
472
00:17:59,737 --> 00:18:00,847
hundreds of times.
473
00:18:01,177 --> 00:18:03,637
we don't have to look through each one of those lines and
474
00:18:03,847 --> 00:18:05,887
manually change the character's name
475
00:18:06,067 --> 00:18:09,127
and that is not a very good way for us to do this
476
00:18:09,487 --> 00:18:09,997
and
477
00:18:10,117 --> 00:18:14,077
it's really not a good way for us to manage the data in our program right the
478
00:18:14,107 --> 00:18:15,637
character's name in the age.
479
00:18:15,967 --> 00:18:18,187
and so we can actually use a variable
480
00:18:18,367 --> 00:18:19,777
in order to store
481
00:18:19,807 --> 00:18:21,788
the character's name and the characters.
482
00:18:21,848 --> 00:18:22,358
age.
483
00:18:22,568 --> 00:18:25,147
and when we use that variable it'll make it a lot
484
00:18:25,177 --> 00:18:27,758
easier for us to put the character's name and age.
485
00:18:27,818 --> 00:18:29,648
inside of our little program here.
486
00:18:30,038 --> 00:18:33,698
so I'm gonna show you guys how we can create a variable for the character's name and age.
487
00:18:33,998 --> 00:18:36,698
now it's going to go up here above this print statement.
488
00:18:37,088 --> 00:18:37,508
and
489
00:18:37,538 --> 00:18:40,238
up here I want to create a variable.
490
00:18:40,538 --> 00:18:42,518
so when we create a variable in
491
00:18:42,548 --> 00:18:44,828
python we actually need to give
492
00:18:45,008 --> 00:18:45,578
python
493
00:18:45,608 --> 00:18:47,228
a couple pieces of information.
494
00:18:47,708 --> 00:18:53,948
the first piece of information we need to give python is the name of the variable so I need to actually assign a name
495
00:18:54,128 --> 00:18:57,218
to this container where we're going to be storing information.
496
00:18:57,698 --> 00:18:59,528
so all I have to do is just type out
497
00:18:59,558 --> 00:19:00,818
the name of the variable
498
00:19:00,848 --> 00:19:02,708
that I want to create so I'm going to create a
499
00:19:02,798 --> 00:19:04,808
variable called character name.
500
00:19:05,288 --> 00:19:06,338
so I'm just going to say
501
00:19:07,028 --> 00:19:07,808
character
502
00:19:08,408 --> 00:19:09,758
adam's they underscore
503
00:19:09,788 --> 00:19:10,478
name
504
00:19:10,778 --> 00:19:12,998
so generally when you're creating a name
505
00:19:13,028 --> 00:19:14,738
for a variable in python.
506
00:19:14,888 --> 00:19:17,108
you want to separate different words
507
00:19:17,258 --> 00:19:21,788
with an underscore so I have two words here and I'm separating them with an underscore.
508
00:19:22,328 --> 00:19:24,249
and now what I need to do is I need to
509
00:19:24,279 --> 00:19:25,359
put a value
510
00:19:25,389 --> 00:19:27,399
inside of this very more so
511
00:19:27,459 --> 00:19:29,229
basically what I can do is I can just say
512
00:19:29,649 --> 00:19:30,459
equals
513
00:19:30,579 --> 00:19:32,439
and over here I can type a value
514
00:19:32,469 --> 00:19:34,839
so I'm just gonna type out the character's name inside of
515
00:19:35,019 --> 00:19:35,859
quotation marks.
516
00:19:36,159 --> 00:19:37,749
so we're just gonna type out john.
517
00:19:38,289 --> 00:19:41,499
so now we have a variable for the character's name
518
00:19:42,159 --> 00:19:46,629
and below this character named variable I want to create another variable called
519
00:19:46,719 --> 00:19:47,319
character
520
00:19:47,349 --> 00:19:49,149
age certain just going to tape out
521
00:19:49,719 --> 00:19:50,469
character
522
00:19:50,709 --> 00:19:51,459
underscore
523
00:19:51,519 --> 00:19:52,239
age.
524
00:19:52,599 --> 00:19:53,919
and I'm going to set this
525
00:19:53,949 --> 00:19:56,949
equal to the characters age which is thirty five.
526
00:19:58,120 --> 00:19:59,679
so we now have two variables,
527
00:19:59,949 --> 00:20:03,069
one representing the character's name and one representing the characters
528
00:20:03,099 --> 00:20:03,549
age.
529
00:20:03,819 --> 00:20:06,219
so what I can do now as I can replace
530
00:20:06,249 --> 00:20:08,559
the character's name inside of this story
531
00:20:08,589 --> 00:20:09,069
with
532
00:20:09,189 --> 00:20:10,359
this variable.
533
00:20:10,659 --> 00:20:12,130
and I'm gonna show you guys how to do that
534
00:20:12,160 --> 00:20:15,340
so if we want to put a variable inside of this print statement.
535
00:20:15,580 --> 00:20:17,500
I'm actually going to have to do a couple of things.
536
00:20:17,710 --> 00:20:19,840
the first thing I'm going to have to do is
537
00:20:20,020 --> 00:20:21,370
end off this
538
00:20:21,400 --> 00:20:23,380
text in here so I'm going to have to put
539
00:20:23,770 --> 00:20:24,220
a
540
00:20:24,280 --> 00:20:26,110
quotation marks here the end
541
00:20:26,410 --> 00:20:27,910
and you can see I'm basically
542
00:20:27,940 --> 00:20:29,890
wrapping this whole thing into a
543
00:20:29,950 --> 00:20:31,750
single like quoted line.
544
00:20:32,320 --> 00:20:36,760
and now I also have this tax overhear the end so I'm going to have to put a quotation mark here.
545
00:20:37,210 --> 00:20:37,990
so now I have
546
00:20:38,021 --> 00:20:38,470
a
547
00:20:38,531 --> 00:20:40,660
bunch of tax year in quotation marks.
548
00:20:41,080 --> 00:20:43,810
and then I also have tax over here in quotation marks
549
00:20:44,050 --> 00:20:45,520
now inside of here
550
00:20:45,610 --> 00:20:46,090
instead of
551
00:20:46,120 --> 00:20:47,650
saying the character's name
552
00:20:47,680 --> 00:20:49,750
I want to refer to that character name
553
00:20:49,780 --> 00:20:50,500
variable
554
00:20:50,920 --> 00:20:52,810
so I'm just going to say plus
555
00:20:54,430 --> 00:20:55,240
character
556
00:20:56,230 --> 00:20:57,340
underscore name
557
00:20:57,910 --> 00:21:01,421
and I want to say another plus sign so I basically I'm saying I want to
558
00:21:01,451 --> 00:21:03,100
print out all of this text,
559
00:21:03,641 --> 00:21:04,480
plus
560
00:21:04,661 --> 00:21:07,181
the value that stored inside of character name
561
00:21:07,511 --> 00:21:08,351
plus
562
00:21:08,651 --> 00:21:09,791
all of this text.
563
00:21:10,481 --> 00:21:14,021
and what this will do is they will actually print out the character's name we print this
564
00:21:14,291 --> 00:21:16,031
so I'm gonna go ahead and run this program
565
00:21:16,601 --> 00:21:18,041
and you'll see down here
566
00:21:18,101 --> 00:21:19,961
and actually let me put a space over here,
567
00:21:20,681 --> 00:21:21,641
and we'll run it again.
568
00:21:21,911 --> 00:21:23,381
so you can see down here,
569
00:21:23,561 --> 00:21:26,171
we still are printing out there once was a man named
570
00:21:26,201 --> 00:21:26,891
john.
571
00:21:27,491 --> 00:21:31,241
and so what python is doing is when it executes this line of code
572
00:21:31,541 --> 00:21:33,371
it's coming over here and it's seeing
573
00:21:33,461 --> 00:21:34,931
ok they want to turn out.
574
00:21:35,021 --> 00:21:37,331
the value inside of character name
575
00:21:37,661 --> 00:21:38,141
so it
576
00:21:38,171 --> 00:21:41,051
python's going to go up here it's going to get the value,
577
00:21:41,291 --> 00:21:41,801
and it's going to
578
00:21:41,831 --> 00:21:43,361
insert it inside of there
579
00:21:43,781 --> 00:21:48,611
so I can basically do this for every instance of the character name in my file so I can
580
00:21:48,911 --> 00:21:49,271
you know
581
00:21:49,331 --> 00:21:51,311
r is copy this guy right here
582
00:21:51,911 --> 00:21:52,421
and
583
00:21:52,481 --> 00:21:55,661
I can just paste it down here where the characters name is
584
00:21:55,871 --> 00:21:56,891
so apace this
585
00:21:57,071 --> 00:22:00,912
and you can see now were doing exactly the same thing that we did up there.
586
00:22:01,302 --> 00:22:03,792
I can also do this for the characters
587
00:22:03,852 --> 00:22:05,592
age someone to come down here
588
00:22:05,832 --> 00:22:07,872
and I'll paste in what we just paste it in.
589
00:22:08,832 --> 00:22:12,312
and I'm going to change this instead of character name was changed to character
590
00:22:12,342 --> 00:22:12,912
age.
591
00:22:14,502 --> 00:22:15,552
and I'm going to do this
592
00:22:15,582 --> 00:22:19,302
in one more spots are going to do this over here we're mentioning the age
593
00:22:19,992 --> 00:22:22,152
and again I'll just change this to
594
00:22:22,212 --> 00:22:22,482
carry
595
00:22:22,512 --> 00:22:23,142
your age.
596
00:22:23,832 --> 00:22:29,082
and so now when I run this program it's going to print out the same story they were printing out before,
597
00:22:29,502 --> 00:22:29,892
but
598
00:22:29,922 --> 00:22:34,632
now I don't actually have to type in the character's name and the characters age.
599
00:22:34,872 --> 00:22:36,312
I can just refer to this
600
00:22:36,342 --> 00:22:37,062
variable.
601
00:22:37,482 --> 00:22:41,352
and the cool thing about variables as if I wanted to change the character's name.
602
00:22:41,892 --> 00:22:46,212
now all I have to do is change it up here so I could change the characters names you like
603
00:22:46,242 --> 00:22:47,352
tom or something.
604
00:22:47,682 --> 00:22:49,902
and we could also change their age so I could change
605
00:22:50,052 --> 00:22:51,732
the age to be like fifty
606
00:22:52,032 --> 00:22:55,872
and now that's going to automatically update throughout our entire story
607
00:22:56,262 --> 00:22:58,002
when I click this play button you'll see
608
00:22:58,212 --> 00:23:00,312
now we're using the name tom
609
00:23:00,522 --> 00:23:02,382
and he's fifty years old.
610
00:23:02,652 --> 00:23:04,812
so that's where variables can come in handy and
611
00:23:04,842 --> 00:23:08,742
this can be a really awesome way to control and manage
612
00:23:08,982 --> 00:23:11,172
the data that's inside of our programs
613
00:23:11,592 --> 00:23:13,152
with variables you can also
614
00:23:13,182 --> 00:23:14,742
modify their values
615
00:23:14,772 --> 00:23:15,282
so
616
00:23:15,432 --> 00:23:19,602
for example let's say that halfway through the story I wanted to change the character's name
617
00:23:20,022 --> 00:23:22,122
why can just make some new lines over here,
618
00:23:22,482 --> 00:23:23,532
and down here
619
00:23:23,562 --> 00:23:25,452
I can actually assign a new
620
00:23:25,482 --> 00:23:27,222
value to one of these variables.
621
00:23:27,462 --> 00:23:28,662
so I can say like
622
00:23:29,532 --> 00:23:30,312
character
623
00:23:30,372 --> 00:23:31,512
underscore name,
624
00:23:31,962 --> 00:23:35,442
and in order to give it a different value all I have to do is just say equals
625
00:23:35,472 --> 00:23:37,182
and will give it a different value and so
626
00:23:37,693 --> 00:23:41,293
let's say halfway through the story we want to change the character's name to mike
627
00:23:42,313 --> 00:23:43,873
one now when I run my program
628
00:23:44,683 --> 00:23:47,263
you'll see here in the first part of the story it says
629
00:23:47,293 --> 00:23:48,433
there once was a man named
630
00:23:48,463 --> 00:23:49,123
tom.
631
00:23:49,453 --> 00:23:51,163
and in the second part of the story,
632
00:23:51,253 --> 00:23:53,083
it's referring to the name as
633
00:23:53,143 --> 00:23:53,803
mike.
634
00:23:54,013 --> 00:23:55,033
so I actually
635
00:23:55,063 --> 00:23:56,653
updated the variable
636
00:23:56,683 --> 00:23:58,153
inside of my program
637
00:23:58,183 --> 00:23:58,993
over here
638
00:23:59,383 --> 00:24:00,943
and that's a really awesome way
639
00:24:00,973 --> 00:24:05,533
you know a lot of times in these programs you're going to want to be modifying the values of variables
640
00:24:05,743 --> 00:24:06,553
so you can do it
641
00:24:06,583 --> 00:24:07,603
just like that.
642
00:24:07,663 --> 00:24:10,363
and so finally I want to talk to you guys about the different
643
00:24:10,573 --> 00:24:14,293
types of data that we can store inside of these variables.
644
00:24:14,593 --> 00:24:15,523
so over here
645
00:24:15,553 --> 00:24:18,073
I have the character name and character age
646
00:24:18,313 --> 00:24:18,643
and
647
00:24:18,703 --> 00:24:21,794
I'm actually storing what are called strings,
648
00:24:21,974 --> 00:24:24,314
so a string is basically just
649
00:24:24,524 --> 00:24:25,874
plain tax straight
650
00:24:26,114 --> 00:24:28,664
so the name tom that's just plain text
651
00:24:29,084 --> 00:24:31,574
down here these guys are strings as well.
652
00:24:31,844 --> 00:24:34,154
so there's a data type in python,
653
00:24:34,394 --> 00:24:36,554
called a string and it's just
654
00:24:36,584 --> 00:24:38,054
basically going to store
655
00:24:38,115 --> 00:24:38,955
plain text
656
00:24:38,985 --> 00:24:39,345
so
657
00:24:39,615 --> 00:24:43,185
you know any text that you would have like in a story early know someone's name
658
00:24:43,395 --> 00:24:45,344
you can store inside of a string.
659
00:24:45,885 --> 00:24:47,924
there's also another type of data
660
00:24:47,954 --> 00:24:49,935
that we can store inside of python
661
00:24:49,965 --> 00:24:51,075
which is numbers
662
00:24:51,105 --> 00:24:53,835
so an additional storing text we can also store
663
00:24:53,865 --> 00:24:54,495
numbers.
664
00:24:54,885 --> 00:24:57,165
so if I wanted to start a number for example
665
00:24:57,195 --> 00:25:00,705
let's say we wanted to store the character age instead of inside of a string.
666
00:25:01,005 --> 00:25:03,135
we can store it inside of a number so
667
00:25:03,915 --> 00:25:05,805
I could just type out fifty.
668
00:25:06,255 --> 00:25:09,915
and when we're storing a number we don't need these quotation marks
669
00:25:09,945 --> 00:25:11,625
you only need that quotation mark
670
00:25:11,895 --> 00:25:15,016
when you're storing a string so if I wanted to a number I can just
671
00:25:15,046 --> 00:25:16,216
write it out like this,
672
00:25:16,666 --> 00:25:20,295
and in addition to using whole numbers I can also use decimal numbers.
673
00:25:20,355 --> 00:25:23,205
so I could say like fifty point five six seven eight
674
00:25:23,235 --> 00:25:24,196
to one three
675
00:25:24,586 --> 00:25:26,536
and pythons are going to be able to store
676
00:25:26,566 --> 00:25:27,886
that number as well.
677
00:25:28,126 --> 00:25:29,956
you can store all different types of numbers
678
00:25:30,286 --> 00:25:32,206
and we can also store
679
00:25:32,236 --> 00:25:34,306
what's called a boolean value
680
00:25:34,576 --> 00:25:39,046
and a boolean value is essentially a true or false value.
681
00:25:39,376 --> 00:25:43,306
and there's a lot of instances in programming where we're going to want to represent
682
00:25:43,336 --> 00:25:44,566
true or false
683
00:25:44,626 --> 00:25:45,196
data
684
00:25:45,616 --> 00:25:47,836
for example I can have a variable called like
685
00:25:47,956 --> 00:25:48,976
his mail
686
00:25:49,306 --> 00:25:52,156
and this would tell me whether or not someone was a male,
687
00:25:52,486 --> 00:25:55,906
and in my case it will be true because I'm a guy right so I can
688
00:25:56,176 --> 00:25:57,346
actually this needs to be
689
00:25:57,376 --> 00:25:57,916
capital
690
00:25:58,756 --> 00:25:59,236
so
691
00:25:59,476 --> 00:26:01,876
I could sort of value of either true
692
00:26:02,416 --> 00:26:02,986
or
693
00:26:03,916 --> 00:26:04,696
false.
694
00:26:04,846 --> 00:26:07,036
and actually if we were naming this in python
695
00:26:07,066 --> 00:26:08,896
we want to use an underscore or so I would say
696
00:26:08,956 --> 00:26:10,546
is underscore mail
697
00:26:10,846 --> 00:26:12,706
and this can be either true or false
698
00:26:12,736 --> 00:26:13,126
so
699
00:26:13,366 --> 00:26:17,957
true or false values is maybe not something that you're used to dealing with like in the real world
700
00:26:18,497 --> 00:26:18,947
but
701
00:26:18,977 --> 00:26:22,007
in programming we're going to be using a true or false values
702
00:26:22,067 --> 00:26:24,707
all the time they're super important so
703
00:26:25,427 --> 00:26:29,537
like I said there's three basic types of data that we can work with in python there's
704
00:26:29,597 --> 00:26:32,117
strings which is just like a plain text,
705
00:26:32,177 --> 00:26:36,587
numbers which would be like either decimal numbers or whole numbers like this,
706
00:26:36,827 --> 00:26:38,207
and there's true or false
707
00:26:38,237 --> 00:26:38,927
values.
708
00:26:39,257 --> 00:26:45,857
and these are the basic types of data I mean there's a bunch of other types of data that we can use but I would say ninety nine percent of the time.
709
00:26:46,097 --> 00:26:47,597
as a new user
710
00:26:47,627 --> 00:26:49,398
in a new programmer to python,
711
00:26:49,608 --> 00:26:51,198
you're just going to be dealing with these
712
00:26:51,288 --> 00:26:52,668
three types of data
713
00:26:52,698 --> 00:26:53,118
so
714
00:26:53,388 --> 00:26:54,378
those are the basics
715
00:26:54,438 --> 00:26:55,398
of the data
716
00:26:55,428 --> 00:26:55,818
and
717
00:26:55,908 --> 00:26:57,228
also with variables
718
00:26:57,288 --> 00:26:58,548
and you're going to be using variables
719
00:26:58,578 --> 00:27:01,998
all the time in python so you definitely want to practice up and get comfortable
720
00:27:02,028 --> 00:27:02,748
using them
721
00:27:06,768 --> 00:27:11,298
in this tutorial are talks you guys about working with strings in python.
722
00:27:11,748 --> 00:27:13,458
now what the most common types of
723
00:27:13,488 --> 00:27:17,148
data that we're going to be working with in python is going to be strings
724
00:27:17,418 --> 00:27:19,308
and strings are basically just
725
00:27:19,428 --> 00:27:21,408
plain text so any text
726
00:27:21,708 --> 00:27:23,478
that we want to have inside of our program
727
00:27:23,688 --> 00:27:25,848
we can store inside of a string.
728
00:27:26,148 --> 00:27:30,318
so I wanna talk to you guys about all the cool things we can do with strings and we're basically just going to get a
729
00:27:30,558 --> 00:27:33,408
full introduction into why strings are awesome.
730
00:27:33,948 --> 00:27:34,938
so over here,
731
00:27:35,118 --> 00:27:36,918
I'm just going to actually print out
732
00:27:36,948 --> 00:27:39,109
a strings I'm just going to say print
733
00:27:39,529 --> 00:27:39,889
and
734
00:27:39,919 --> 00:27:41,359
inside of these parentheses.
735
00:27:41,419 --> 00:27:42,799
I can type out a string
736
00:27:43,219 --> 00:27:47,269
in order to create a string I need to use quotation marks so I can make an
737
00:27:47,299 --> 00:27:48,799
open and close quotation marks
738
00:27:48,829 --> 00:27:49,729
just like that
739
00:27:50,059 --> 00:27:50,389
now
740
00:27:50,449 --> 00:27:51,019
inside
741
00:27:51,049 --> 00:27:53,209
the quotation mark I can put whatever text
742
00:27:53,239 --> 00:27:55,549
I want the string to have so we could say like
743
00:27:56,059 --> 00:27:56,689
draff
744
00:27:56,749 --> 00:27:57,439
academy.
745
00:27:58,309 --> 00:27:59,989
and so now we have a string
746
00:28:00,019 --> 00:28:00,829
with the text
747
00:28:00,859 --> 00:28:02,359
draff academy inside of it
748
00:28:02,719 --> 00:28:04,129
so if I run my program.
749
00:28:04,249 --> 00:28:07,879
now down here we're going to print out draff academy as you can see,
750
00:28:08,059 --> 00:28:12,199
and when we have these strings there's actually a bunch of cool things that we can do with them so
751
00:28:12,499 --> 00:28:18,529
one thing I could do would be to create a new line inside of the string so if I wanted I could come over here,
752
00:28:18,799 --> 00:28:20,269
and I could save backslash
753
00:28:20,329 --> 00:28:20,870
n
754
00:28:21,290 --> 00:28:23,840
and you can see it got highlighted in a different color.
755
00:28:24,140 --> 00:28:30,320
and what this is gonna do is it's actually going to insert a new line into the string so now it's going to say draff on one line
756
00:28:30,530 --> 00:28:32,420
and academy on another line.
757
00:28:32,900 --> 00:28:34,400
so I'm gonna click play.
758
00:28:34,580 --> 00:28:37,130
and you'll see down here we just get draff academy,
759
00:28:37,520 --> 00:28:39,110
an addition to the backslash
760
00:28:39,140 --> 00:28:39,470
n
761
00:28:39,500 --> 00:28:40,910
I could also use
762
00:28:41,090 --> 00:28:42,110
a backslash
763
00:28:42,140 --> 00:28:43,430
quotation marks so
764
00:28:43,670 --> 00:28:46,760
if I wanted to put a quotation mark inside of my string.
765
00:28:47,180 --> 00:28:49,370
I can't just put a quotation mark like that
766
00:28:49,640 --> 00:28:52,371
because pythons going to think that I'm trying to end
767
00:28:52,401 --> 00:28:53,421
this strength.
768
00:28:53,691 --> 00:28:55,881
so if I want to include a quotation mark I can just use this
769
00:28:55,911 --> 00:28:57,531
special backslash character
770
00:28:57,981 --> 00:28:59,991
and that's called the escape character and it
771
00:29:00,021 --> 00:29:02,031
basically just tells python that
772
00:29:02,361 --> 00:29:05,391
whatever character comes after it we want to
773
00:29:05,452 --> 00:29:06,922
render a literally so
774
00:29:07,161 --> 00:29:08,572
when I say backslash
775
00:29:08,602 --> 00:29:09,472
quotation mark.
776
00:29:09,652 --> 00:29:10,522
it basically means like
777
00:29:10,552 --> 00:29:11,302
hey python
778
00:29:11,332 --> 00:29:12,772
I want to point out a quotation mark.
779
00:29:13,102 --> 00:29:14,572
and so now we'll be able to print
780
00:29:14,602 --> 00:29:14,842
out
781
00:29:14,872 --> 00:29:16,042
a quotation mark
782
00:29:16,072 --> 00:29:16,642
right there.
783
00:29:16,972 --> 00:29:20,752
I can also use this to print out of backslash so if I needed to put out a backslash.
784
00:29:20,812 --> 00:29:22,102
I could see backslash,
785
00:29:22,402 --> 00:29:22,912
and
786
00:29:23,152 --> 00:29:25,282
it'll just print out a normal backslash now
787
00:29:26,002 --> 00:29:27,622
so you can see just like that so
788
00:29:27,772 --> 00:29:29,752
if you want and you can use that backslash to make
789
00:29:29,782 --> 00:29:31,672
new lines or pronounce quotation marks,
790
00:29:31,943 --> 00:29:33,683
or you can just use it as a normal
791
00:29:33,713 --> 00:29:34,373
backslash
792
00:29:35,123 --> 00:29:39,503
in addition to just typing out a string here I could also create a string
793
00:29:39,533 --> 00:29:40,283
variable.
794
00:29:40,793 --> 00:29:41,933
so I could come down here
795
00:29:41,963 --> 00:29:44,423
up here and we can create a variable and let's call it
796
00:29:44,513 --> 00:29:45,443
phrase.
797
00:29:45,803 --> 00:29:46,523
and I'm going to set it
798
00:29:46,553 --> 00:29:47,543
equal to
799
00:29:47,633 --> 00:29:48,593
drop off a colony,
800
00:29:49,073 --> 00:29:49,763
so I can
801
00:29:49,823 --> 00:29:54,114
store this string value inside of a variable called phrase
802
00:29:54,384 --> 00:29:55,524
and then when I want to print
803
00:29:55,554 --> 00:29:56,664
out that variable,
804
00:29:56,754 --> 00:29:58,884
or I want to access that string variable.
805
00:29:59,094 --> 00:29:59,844
I can just
806
00:30:00,024 --> 00:30:01,344
type the name of
807
00:30:01,404 --> 00:30:02,184
the variable.
808
00:30:02,394 --> 00:30:06,204
and you'll see that it's going to print out the value that was stored inside of it.
809
00:30:06,564 --> 00:30:09,534
I can also use something called concatenation
810
00:30:09,774 --> 00:30:13,464
and concatenation is basically the process of taking a string and
811
00:30:13,644 --> 00:30:15,504
appending another string onto it.
812
00:30:15,834 --> 00:30:18,144
so I could come over here and I could say phrase,
813
00:30:18,414 --> 00:30:18,894
and I can say
814
00:30:18,924 --> 00:30:19,734
plus.
815
00:30:19,884 --> 00:30:23,035
and now I can add in another string so I could say like
816
00:30:23,305 --> 00:30:24,205
is cool.
817
00:30:24,445 --> 00:30:25,795
and now this is going to say
818
00:30:25,825 --> 00:30:26,995
druff academy
819
00:30:27,025 --> 00:30:27,625
is
820
00:30:27,655 --> 00:30:28,195
cool,
821
00:30:28,675 --> 00:30:31,345
so I'm basically appending another string
822
00:30:31,435 --> 00:30:33,655
onto another one they call that concatenation.
823
00:30:34,045 --> 00:30:38,815
and so in addition to doing all that stuff we can also use a special thing is called
824
00:30:38,845 --> 00:30:39,745
functions
825
00:30:40,045 --> 00:30:43,945
and a function is basically just a little block of code that we can run
826
00:30:44,215 --> 00:30:45,865
and it will perform a specific
827
00:30:45,895 --> 00:30:47,275
operation for us,
828
00:30:47,515 --> 00:30:50,756
so we can use functions to modify our strings.
829
00:30:50,996 --> 00:30:55,046
we can also use functions to get information about our strings.
830
00:30:55,256 --> 00:30:55,736
so
831
00:30:55,886 --> 00:30:59,486
I'm gonna show you guys a couple common functions we can use with the strings.
832
00:30:59,756 --> 00:31:00,086
and
833
00:31:00,116 --> 00:31:02,156
they're actually going to do awesome stuff so
834
00:31:02,426 --> 00:31:06,146
in order to access one of these functions I can just say phrase and then I can say
835
00:31:06,176 --> 00:31:06,716
dot.
836
00:31:07,016 --> 00:31:07,376
and
837
00:31:07,466 --> 00:31:10,586
I'm gonna show you guys a function that we can use to convert this
838
00:31:10,616 --> 00:31:14,786
string entirely into lowercase so I could just say phrase dot lower.
839
00:31:15,116 --> 00:31:16,136
and I'm going to want to type an
840
00:31:16,166 --> 00:31:17,786
open and close parentheses,
841
00:31:17,996 --> 00:31:19,706
and this will take this phrase,
842
00:31:19,826 --> 00:31:22,526
it'll take my string and it will convert it to lower case.
843
00:31:22,706 --> 00:31:27,086
so you can see now we just have a draft academy done here but it's entirely in lower case.
844
00:31:27,356 --> 00:31:31,076
I could also do the same thing for upper case so I could say phrase dot
845
00:31:31,196 --> 00:31:31,766
upper
846
00:31:32,216 --> 00:31:34,586
and this will convert the entire string into
847
00:31:34,616 --> 00:31:36,116
upper case so you can see now it's
848
00:31:36,146 --> 00:31:37,406
entirely upper case.
849
00:31:37,466 --> 00:31:38,996
so in addition to
850
00:31:39,026 --> 00:31:40,587
converting the string into upper case
851
00:31:40,617 --> 00:31:41,157
lower case
852
00:31:41,187 --> 00:31:41,727
I can also
853
00:31:41,757 --> 00:31:46,167
check to see if a string is entirely upper case are entirely lowercase.
854
00:31:46,617 --> 00:31:48,627
so for example I could say phrase dot
855
00:31:48,657 --> 00:31:49,647
is upper.
856
00:31:49,917 --> 00:31:53,517
and this is going to give me back a true or false value
857
00:31:53,547 --> 00:31:54,837
so it's going to be true
858
00:31:55,077 --> 00:31:57,057
if the string is entirely upper case
859
00:31:57,087 --> 00:31:57,777
or false
860
00:31:57,807 --> 00:31:58,617
if it's not.
861
00:31:59,097 --> 00:32:02,067
and you can see here we're getting a false value because this
862
00:32:02,097 --> 00:32:02,457
is an
863
00:32:02,487 --> 00:32:03,207
upper case
864
00:32:03,747 --> 00:32:08,817
I can also use these functions in combination with each other so for example,
865
00:32:08,877 --> 00:32:10,647
I could say phrase
866
00:32:11,457 --> 00:32:11,907
dot
867
00:32:11,967 --> 00:32:12,627
upper
868
00:32:13,017 --> 00:32:13,557
and that a
869
00:32:13,617 --> 00:32:14,577
parentheses
870
00:32:14,937 --> 00:32:16,647
and then after this I can say
871
00:32:16,677 --> 00:32:17,037
dot
872
00:32:17,068 --> 00:32:17,698
is upper
873
00:32:17,728 --> 00:32:20,398
and now what it's going to do is it's going to run this
874
00:32:20,428 --> 00:32:21,418
upper function,
875
00:32:21,628 --> 00:32:23,458
it's going to convert it into upper case.
876
00:32:23,638 --> 00:32:24,928
and then it's going to run this
877
00:32:24,988 --> 00:32:27,088
is upper function right after that
878
00:32:27,208 --> 00:32:33,028
and you'll see now we're going to get a true value back because it will have converted the whole thing into upper case.
879
00:32:33,298 --> 00:32:36,058
so you can see now we're getting a true value so
880
00:32:36,388 --> 00:32:37,468
the news these functions
881
00:32:37,498 --> 00:32:39,808
one after another it can be really useful.
882
00:32:40,318 --> 00:32:43,379
and there's a few other ones that I want to show you so we can also
883
00:32:43,469 --> 00:32:44,849
figure out the length
884
00:32:44,909 --> 00:32:45,329
of
885
00:32:45,389 --> 00:32:46,829
this string so
886
00:32:47,159 --> 00:32:50,099
if I wanted to figure out how many characters were inside of this
887
00:32:50,129 --> 00:32:51,509
string I could just say
888
00:32:51,539 --> 00:32:52,349
l e n
889
00:32:52,709 --> 00:32:53,759
and I'm actually going to make an
890
00:32:53,789 --> 00:32:54,959
open parentheses,
891
00:32:55,169 --> 00:32:57,149
and I'm going to make a close parentheses.
892
00:32:57,389 --> 00:32:58,679
so I'm essentially saying
893
00:32:58,709 --> 00:33:01,859
alien and this is another function it's the length function.
894
00:33:02,129 --> 00:33:05,519
and inside of this alien function I'm actually passing
895
00:33:05,549 --> 00:33:06,059
this
896
00:33:06,269 --> 00:33:07,529
phrase variable
897
00:33:07,829 --> 00:33:12,509
basically giving the length function this and it's going to spit out a number so tell me how many
898
00:33:12,569 --> 00:33:14,369
characters are inside of this string.
899
00:33:15,059 --> 00:33:20,639
as you can see here we get fifteen because there's fifteen characters inside of draff academy.
900
00:33:20,999 --> 00:33:25,889
so that's how you can get the whole length of the string and that's going to be really useful as we go forward in python.
901
00:33:25,949 --> 00:33:26,969
we can also get
902
00:33:26,999 --> 00:33:29,789
individual characters inside of a string so
903
00:33:30,089 --> 00:33:34,589
imagine if I wanted to just grab one of these characters like imagine if I wanted to
904
00:33:34,619 --> 00:33:37,379
figure out what the first character in the string is
905
00:33:37,739 --> 00:33:38,969
we're going to actually use
906
00:33:39,029 --> 00:33:40,020
and open a closed
907
00:33:40,050 --> 00:33:41,190
square bracket
908
00:33:41,220 --> 00:33:42,120
just like that.
909
00:33:42,360 --> 00:33:44,340
and in here I can specify the
910
00:33:44,370 --> 00:33:46,620
index of the character that I want to graph.
911
00:33:46,920 --> 00:33:49,860
so if I wanted to grab the first character in the string
912
00:33:49,890 --> 00:33:51,390
I can put in a zero.
913
00:33:51,690 --> 00:33:53,100
so if I say phrase
914
00:33:53,130 --> 00:33:54,570
square bracket zero,
915
00:33:54,750 --> 00:33:57,060
this is going to give me that capital g
916
00:33:57,300 --> 00:33:58,710
and you can see down here
917
00:33:58,740 --> 00:34:00,090
that's what gets printed out.
918
00:34:00,450 --> 00:34:01,771
now I want to point something out
919
00:34:01,860 --> 00:34:02,401
in
920
00:34:02,521 --> 00:34:03,421
python.
921
00:34:03,541 --> 00:34:05,131
when we're working with strings.
922
00:34:05,461 --> 00:34:06,211
a string
923
00:34:06,241 --> 00:34:07,141
gets indexed
924
00:34:07,171 --> 00:34:08,460
starting with zero.
925
00:34:08,730 --> 00:34:11,700
so you'll notice that in order to access this g.
926
00:34:11,791 --> 00:34:13,501
I had to put a zero in here.
927
00:34:13,801 --> 00:34:15,361
that's because in python.
928
00:34:15,781 --> 00:34:18,931
when we use indexes on a string we start with zero
929
00:34:19,171 --> 00:34:21,841
so if python is counting the characters
930
00:34:22,051 --> 00:34:25,771
or its indexing the characters in a string it's going to start with zero so it's going to say
931
00:34:25,981 --> 00:34:27,001
g is zero
932
00:34:27,361 --> 00:34:28,981
I as one are as to
933
00:34:29,011 --> 00:34:29,761
a history.
934
00:34:30,061 --> 00:34:32,431
so we would say that g is at position
935
00:34:32,461 --> 00:34:33,871
zero in the string.
936
00:34:33,931 --> 00:34:35,402
I is at position one
937
00:34:35,732 --> 00:34:36,962
r is at position two
938
00:34:36,992 --> 00:34:38,702
a's at position three etc.
939
00:34:38,942 --> 00:34:40,382
so we start counting
940
00:34:40,412 --> 00:34:41,462
at zero.
941
00:34:42,302 --> 00:34:43,712
so if I wanted to access
942
00:34:43,952 --> 00:34:44,672
the first
943
00:34:45,122 --> 00:34:46,413
character in the string.
944
00:34:46,593 --> 00:34:48,753
this g I have to say phrase
945
00:34:48,783 --> 00:34:50,613
zero and that's just a special thing
946
00:34:51,062 --> 00:34:53,942
in python and actually most programming languages
947
00:34:53,972 --> 00:34:55,322
do that so they'll start with
948
00:34:55,352 --> 00:34:55,982
zero.
949
00:34:56,342 --> 00:34:58,262
so for example if I wanted to access this
950
00:34:58,292 --> 00:34:58,802
ei,
951
00:34:59,042 --> 00:35:00,002
I'm going to have to put
952
00:35:00,032 --> 00:35:00,873
zero
953
00:35:02,493 --> 00:35:03,033
one
954
00:35:03,063 --> 00:35:06,213
two three so I put three inside of here
955
00:35:06,453 --> 00:35:08,643
now will be able to access that first
956
00:35:08,703 --> 00:35:09,123
a.
957
00:35:09,363 --> 00:35:10,474
as you can see we get an
958
00:35:10,504 --> 00:35:11,434
a right here,
959
00:35:11,824 --> 00:35:12,784
so this
960
00:35:12,844 --> 00:35:16,924
is actually really useful being able to grab a specific character inside of a string
961
00:35:16,984 --> 00:35:17,914
and you're gonna be using it
962
00:35:17,944 --> 00:35:19,895
that a lot as we go forward and python
963
00:35:20,015 --> 00:35:23,795
is also another really awesome function that we can use and it's called the
964
00:35:23,825 --> 00:35:24,905
index function.
965
00:35:25,685 --> 00:35:28,895
and basically what the index function will do is it'll tell us
966
00:35:28,925 --> 00:35:30,635
where a specific
967
00:35:30,666 --> 00:35:33,335
character or string is located
968
00:35:33,365 --> 00:35:35,615
inside of our strings like unsafe phrase
969
00:35:36,005 --> 00:35:36,335
dot
970
00:35:36,365 --> 00:35:37,085
index.
971
00:35:37,415 --> 00:35:37,895
and
972
00:35:38,105 --> 00:35:42,906
I can actually give this a value so sometimes when we use these functions in python,
973
00:35:43,146 --> 00:35:45,966
we can actually give them information so I can give this
974
00:35:45,996 --> 00:35:46,746
of value
975
00:35:47,076 --> 00:35:50,286
and we would call this passing a parameter so
976
00:35:50,376 --> 00:35:53,076
I would call a value that I would give to a function
977
00:35:53,106 --> 00:35:55,266
a parameter and you'll hear that word a lot.
978
00:35:55,656 --> 00:35:56,346
so
979
00:35:56,436 --> 00:35:58,686
for example I can say inside of here
980
00:35:58,716 --> 00:35:59,886
capitol g,
981
00:36:00,066 --> 00:36:01,926
and now this is going to return
982
00:36:01,956 --> 00:36:02,826
the index
983
00:36:02,856 --> 00:36:03,276
of
984
00:36:03,306 --> 00:36:05,526
the capitol g inside of our string
985
00:36:05,736 --> 00:36:07,236
so it should give us back
986
00:36:07,266 --> 00:36:09,907
a zero because g is at the zero of index
987
00:36:10,267 --> 00:36:13,717
and you'll see down here that we get a zero because that's where g is.
988
00:36:14,137 --> 00:36:15,847
so for example if I put in
989
00:36:15,877 --> 00:36:17,677
a inside it here like the lower case
990
00:36:17,707 --> 00:36:18,037
a
991
00:36:18,067 --> 00:36:21,247
it should give me zero one two three
992
00:36:21,457 --> 00:36:22,987
because that's where the first
993
00:36:23,047 --> 00:36:24,697
aid is inside of this string,
994
00:36:25,207 --> 00:36:26,527
so I can click the play button
995
00:36:26,917 --> 00:36:28,327
and you'll see it's giving us
996
00:36:28,357 --> 00:36:28,957
a three.
997
00:36:29,257 --> 00:36:32,647
you can also put actual words in here so for example I could put like
998
00:36:32,948 --> 00:36:34,177
academy in here,
999
00:36:34,448 --> 00:36:35,857
or I could even just put like
1000
00:36:35,917 --> 00:36:37,208
a c a d.
1001
00:36:37,508 --> 00:36:40,507
and this is going to tell me where this starts
1002
00:36:40,537 --> 00:36:42,787
inside of my string so when I click play,
1003
00:36:43,177 --> 00:36:43,957
it's going to give me an
1004
00:36:43,987 --> 00:36:44,287
a
1005
00:36:44,317 --> 00:36:44,887
because
1006
00:36:44,917 --> 00:36:45,698
that's where
1007
00:36:45,758 --> 00:36:47,138
a cat and he starts right
1008
00:36:47,438 --> 00:36:49,928
zero one two three four five six seven
1009
00:36:49,958 --> 00:36:50,319
eight
1010
00:36:51,129 --> 00:36:55,749
if I put something in here that wasn't in the strings of for example if I put a z in here,
1011
00:36:56,109 --> 00:36:57,039
that's not in here.
1012
00:36:57,129 --> 00:37:01,389
it's actually going to throw an error so when I play this you'll see that we get this error down here
1013
00:37:01,419 --> 00:37:01,839
because
1014
00:37:01,989 --> 00:37:04,809
the z is not found inside of our program so
1015
00:37:04,959 --> 00:37:08,709
that the next function again can be really useful we'll be using that a lot.
1016
00:37:08,769 --> 00:37:11,049
there's also one more than I want to show you which
1017
00:37:11,079 --> 00:37:12,579
is called replace
1018
00:37:12,609 --> 00:37:15,010
so we can say phrase not replace
1019
00:37:15,310 --> 00:37:17,410
and in here I can actually give this
1020
00:37:17,440 --> 00:37:20,440
two parameters so I can give this replace function
1021
00:37:20,770 --> 00:37:22,510
two values that it can use.
1022
00:37:22,750 --> 00:37:24,100
and the first thing I want to you
1023
00:37:24,130 --> 00:37:27,221
to give it is what I want to replace so for example I could say
1024
00:37:27,251 --> 00:37:27,941
giraffe.
1025
00:37:28,421 --> 00:37:30,341
and then I'm going to put a comma in here,
1026
00:37:30,611 --> 00:37:33,101
and I want to put in here what I want to replace
1027
00:37:33,131 --> 00:37:35,260
draft with so I could just say like
1028
00:37:35,381 --> 00:37:36,041
elephant
1029
00:37:36,401 --> 00:37:39,641
and now instead of saying draff academy this is going to print out
1030
00:37:39,671 --> 00:37:40,901
elephant academy.
1031
00:37:41,321 --> 00:37:43,991
so you can see down here it just says elephant academy so
1032
00:37:44,201 --> 00:37:45,161
this replace
1033
00:37:45,191 --> 00:37:45,701
function
1034
00:37:45,731 --> 00:37:46,181
can be
1035
00:37:46,211 --> 00:37:47,831
really awesome because we can replace
1036
00:37:48,041 --> 00:37:48,641
certain
1037
00:37:48,911 --> 00:37:50,802
words or even certain letters
1038
00:37:50,832 --> 00:37:52,092
inside of our springs with
1039
00:37:52,182 --> 00:37:52,842
other ones.
1040
00:37:52,932 --> 00:37:58,002
so those are some basic ways that we can work with strings inside of python
1041
00:37:58,032 --> 00:37:58,302
and
1042
00:37:58,542 --> 00:38:01,842
there's a lot of these different functions that we can use with strings.
1043
00:38:02,052 --> 00:38:05,202
these are some of the most common the ones that I just showed you right now,
1044
00:38:05,472 --> 00:38:08,263
but if you just do a google search you can find all sorts of
1045
00:38:08,503 --> 00:38:11,353
python functions that you can try out in use and you know,
1046
00:38:11,563 --> 00:38:12,523
see what they do,
1047
00:38:12,913 --> 00:38:17,322
but you definitely want to get comfortable working with strings and python because you're going to be working with them
1048
00:38:17,352 --> 00:38:17,892
a lot.
1049
00:38:21,912 --> 00:38:25,902
in this tutorial I wanna talk to you about working with numbers in
1050
00:38:25,962 --> 00:38:26,652
python
1051
00:38:27,042 --> 00:38:28,362
and numbers are one most
1052
00:38:28,392 --> 00:38:30,882
common data types in python and
1053
00:38:31,212 --> 00:38:35,173
any python program you write is most likely going to be dealing with numbers at
1054
00:38:35,203 --> 00:38:36,073
some point
1055
00:38:36,103 --> 00:38:36,403
so
1056
00:38:36,703 --> 00:38:43,003
I want to talk to you guys about the basics of using numbers we can talk about the different types of numbers that we can represent in python.
1057
00:38:43,453 --> 00:38:44,924
and I also want to show you guys some
1058
00:38:44,954 --> 00:38:51,194
awesome functions that we can use with number so we can do a certain like mathematical operations mechanism
1059
00:38:51,224 --> 00:38:52,214
awesome things
1060
00:38:52,484 --> 00:38:54,014
with numbers I'm going to show you guys
1061
00:38:54,044 --> 00:38:56,385
all of that in this video it's gonna be awesome so
1062
00:38:57,014 --> 00:38:58,034
first thing we can do is
1063
00:38:58,334 --> 00:39:00,375
we can actually just like print out a number.
1064
00:39:00,615 --> 00:39:05,865
so if I want to write a number in python it's really easy I basically just write the number so I could say like print
1065
00:39:05,896 --> 00:39:06,466
too.
1066
00:39:06,796 --> 00:39:10,096
and this is just going to print the number two out onto the screen,
1067
00:39:10,666 --> 00:39:15,977
so I can use a whole number like this I could also use a decimal number so I can say like two point
1068
00:39:16,007 --> 00:39:17,237
oh nine eight seven
1069
00:39:17,657 --> 00:39:20,988
and pythons are gonna be just fine with that we'll be able to print that on
1070
00:39:21,018 --> 00:39:21,918
the screen as well.
1071
00:39:22,368 --> 00:39:23,658
I can also make numbers
1072
00:39:23,688 --> 00:39:25,428
negative so I could make this
1073
00:39:25,458 --> 00:39:25,908
two point
1074
00:39:25,938 --> 00:39:26,418
oh nine
1075
00:39:26,478 --> 00:39:27,168
eight seven
1076
00:39:27,198 --> 00:39:28,668
a negative number and
1077
00:39:28,968 --> 00:39:31,548
python to be able to handle that just fine too.
1078
00:39:32,358 --> 00:39:35,057
in python we can also use
1079
00:39:35,117 --> 00:39:39,048
basic arithmetic so I could do things like addition subtraction multiplication
1080
00:39:39,348 --> 00:39:40,008
fancy like
1081
00:39:40,038 --> 00:39:40,638
three
1082
00:39:40,668 --> 00:39:41,868
plus four
1083
00:39:41,958 --> 00:39:45,108
and now this is going to print this out or was he like three plus
1084
00:39:45,138 --> 00:39:46,428
four point five.
1085
00:39:46,999 --> 00:39:50,509
and this will be able to print out the answer so we get seven point five.
1086
00:39:50,779 --> 00:39:53,149
and we can do a dish in we can do subtraction.
1087
00:39:53,479 --> 00:39:54,530
we can do division
1088
00:39:54,560 --> 00:39:56,930
or we could do like multiplication as well so you can
1089
00:39:56,960 --> 00:39:59,690
pretty much do whatever you want inside of python,
1090
00:40:00,170 --> 00:40:05,031
and if you want to make more complex mathematical equations we can also use
1091
00:40:05,571 --> 00:40:08,121
things to specify order of operations
1092
00:40:08,151 --> 00:40:09,591
so I could use parentheses.
1093
00:40:10,071 --> 00:40:13,730
so for example if I said three times four plus five
1094
00:40:14,601 --> 00:40:23,031
what python is gonna do is it's gonna multiply three and four together so it's going to be twelve and then we'll add five to that so we should get seventeen.
1095
00:40:24,201 --> 00:40:26,301
but let's say that we wanted to change up the order
1096
00:40:26,331 --> 00:40:26,631
right
1097
00:40:26,661 --> 00:40:29,991
I could actually put a parentheses around four and five
1098
00:40:30,501 --> 00:40:31,401
and now
1099
00:40:31,461 --> 00:40:38,391
it's going to add them first social ad foreign fighters will get nine and will multiply that times three so we should end up with twenty seven,
1100
00:40:38,871 --> 00:40:45,141
so you can see we can use those parentheses to specify order of operations so I could make like a very complex
1101
00:40:45,711 --> 00:40:49,011
little equation here and just by using numbers and parentheses.
1102
00:40:49,161 --> 00:40:50,421
we can also
1103
00:40:50,481 --> 00:40:54,861
use one other operation which is called the modulates operator so I could say like
1104
00:40:54,891 --> 00:40:55,641
ted,
1105
00:40:55,941 --> 00:40:57,741
and use this percent sign
1106
00:40:58,011 --> 00:40:59,961
three and this is actually read
1107
00:40:59,991 --> 00:41:00,501
ten
1108
00:41:00,531 --> 00:41:01,221
mod
1109
00:41:01,251 --> 00:41:01,791
three
1110
00:41:02,181 --> 00:41:05,211
and basically what this is gonna do is it's going to take the first number
1111
00:41:05,421 --> 00:41:07,221
divided by the second number,
1112
00:41:07,312 --> 00:41:09,232
and it's going to spit out the remainder.
1113
00:41:09,472 --> 00:41:10,552
so it's basically going to say
1114
00:41:10,582 --> 00:41:10,912
ok
1115
00:41:10,942 --> 00:41:12,562
ten divided by three.
1116
00:41:12,772 --> 00:41:14,062
that's going to be three
1117
00:41:14,092 --> 00:41:15,562
with a remainder of one.
1118
00:41:15,832 --> 00:41:17,872
so this is going to give us the remainder.
1119
00:41:18,172 --> 00:41:18,682
and
1120
00:41:18,742 --> 00:41:20,932
you'll see down here we get one because
1121
00:41:20,962 --> 00:41:23,422
that's the remainder of ten divided by three
1122
00:41:23,692 --> 00:41:26,512
that modulates operator can come in handy quite a bit.
1123
00:41:26,662 --> 00:41:28,192
we can also store these
1124
00:41:28,852 --> 00:41:30,623
numbers inside of variables
1125
00:41:30,653 --> 00:41:32,393
so we can store them inside of these
1126
00:41:32,423 --> 00:41:33,653
variable containers,
1127
00:41:33,923 --> 00:41:34,523
so I could
1128
00:41:34,553 --> 00:41:35,573
come over here
1129
00:41:35,663 --> 00:41:37,523
and I could create a variable called like
1130
00:41:37,613 --> 00:41:39,143
my underscored gnome
1131
00:41:39,833 --> 00:41:41,663
and we'll just store a value
1132
00:41:41,693 --> 00:41:43,313
of let's say like five and here
1133
00:41:43,673 --> 00:41:47,364
is why have you come down here and I can just print out my underscore numb.
1134
00:41:47,694 --> 00:41:50,154
and we'll be able to print that number out to the screen
1135
00:41:50,184 --> 00:41:50,964
just fine.
1136
00:41:51,114 --> 00:41:54,054
so in addition to doing things like a basic arithmetic
1137
00:41:54,084 --> 00:41:55,584
we can also
1138
00:41:55,734 --> 00:42:00,923
do some other stuff so one thing I could do is I could actually convert this number into a string.
1139
00:42:01,283 --> 00:42:05,244
so if I wanted to convert this number into a string I can just say s t r
1140
00:42:05,664 --> 00:42:08,274
and I can put the number that I want to convert
1141
00:42:08,304 --> 00:42:10,134
inside of these parentheses.
1142
00:42:10,434 --> 00:42:14,125
and so what's going to happen now is this number is going to be converted
1143
00:42:14,425 --> 00:42:14,905
into
1144
00:42:14,935 --> 00:42:16,434
a strings when I click
1145
00:42:16,554 --> 00:42:17,694
the run button you'll see it's
1146
00:42:17,904 --> 00:42:22,434
just printing out five but now instead of being a number this is actually a string.
1147
00:42:22,764 --> 00:42:26,814
and this is going to come in handy when you want to print out numbers alongside
1148
00:42:26,844 --> 00:42:27,715
strings,
1149
00:42:28,045 --> 00:42:29,995
so I can come over here and I can say like
1150
00:42:30,475 --> 00:42:31,195
my
1151
00:42:32,245 --> 00:42:33,415
favorite number,
1152
00:42:33,895 --> 00:42:35,395
and we'll be able to print this
1153
00:42:35,425 --> 00:42:37,345
number along with this
1154
00:42:37,375 --> 00:42:39,085
string so I click play,
1155
00:42:39,295 --> 00:42:41,155
and it's as five my favorite number,
1156
00:42:41,485 --> 00:42:43,314
if I was to get rid of this
1157
00:42:43,344 --> 00:42:44,094
string
1158
00:42:44,155 --> 00:42:44,814
right here
1159
00:42:44,844 --> 00:42:47,515
and I wasn't converting the number into a string.
1160
00:42:47,815 --> 00:42:49,855
now pythons gonna have a problem with this.
1161
00:42:50,035 --> 00:42:52,585
it's not going to allow us to do that you can see we get an
1162
00:42:52,615 --> 00:42:53,305
error so
1163
00:42:53,545 --> 00:42:55,255
anytime you want to print out a number
1164
00:42:55,285 --> 00:42:59,245
next to a string you gotta make sure that you use that little string function.
1165
00:42:59,995 --> 00:43:00,445
so
1166
00:43:00,475 --> 00:43:03,505
there's a bunch of other stuff that we can do with numbers and
1167
00:43:03,625 --> 00:43:05,096
a lot of times in python
1168
00:43:05,126 --> 00:43:07,315
you're gonna want to be using specific
1169
00:43:07,345 --> 00:43:10,135
metabolic more advanced math operator so
1170
00:43:10,525 --> 00:43:12,145
there's a bunch of different math
1171
00:43:12,175 --> 00:43:14,605
functions that we can use on our numbers
1172
00:43:14,815 --> 00:43:19,435
and a function is basically just like a little collection of code that does something so
1173
00:43:19,705 --> 00:43:24,235
a function could perform an operation like a mathematical operation on our number,
1174
00:43:24,715 --> 00:43:27,385
we can also give us information about our number,
1175
00:43:27,625 --> 00:43:32,036
so I'm sure you guys some of the most common functions that you'll be using in python
1176
00:43:32,066 --> 00:43:33,176
related to numbers.
1177
00:43:33,746 --> 00:43:35,456
the first one is called
1178
00:43:35,906 --> 00:43:36,626
abs
1179
00:43:36,656 --> 00:43:40,255
and it stands for absolute value so we can get the absolute value
1180
00:43:40,555 --> 00:43:41,005
of
1181
00:43:41,035 --> 00:43:41,666
a number.
1182
00:43:42,476 --> 00:43:43,676
and so over here I'm going to
1183
00:43:43,706 --> 00:43:45,656
make this variable negative five
1184
00:43:46,135 --> 00:43:47,396
and basically I can just say
1185
00:43:47,426 --> 00:43:48,385
abs
1186
00:43:48,476 --> 00:43:49,106
and I can make an
1187
00:43:49,166 --> 00:43:51,146
open enclosing parentheses over here,
1188
00:43:51,536 --> 00:43:54,445
and this is going to give me the absolute value of
1189
00:43:54,475 --> 00:43:55,825
this number up here,
1190
00:43:56,215 --> 00:43:57,655
so when I click the play button,
1191
00:43:57,925 --> 00:44:03,445
you'll see it's just giving us five because five is the absolute value of negative five,
1192
00:44:03,625 --> 00:44:06,205
I can use a few other functions there is another one
1193
00:44:06,235 --> 00:44:07,105
which is called
1194
00:44:07,225 --> 00:44:09,745
pau at so it says p o w
1195
00:44:10,105 --> 00:44:12,956
and I'm actually not going to use this variable we just as a normal number
1196
00:44:13,436 --> 00:44:13,766
and
1197
00:44:13,796 --> 00:44:16,166
this function is going to allow us to pass it
1198
00:44:16,226 --> 00:44:19,346
to pieces of information so I can give this function
1199
00:44:19,376 --> 00:44:20,606
two pieces of information.
1200
00:44:20,967 --> 00:44:22,227
the first is going to be
1201
00:44:22,646 --> 00:44:23,636
like a number.
1202
00:44:23,816 --> 00:44:28,827
and the second is going to be the power that I want to take that number two so I could say like three
1203
00:44:29,187 --> 00:44:29,727
comma
1204
00:44:29,757 --> 00:44:30,327
two
1205
00:44:30,597 --> 00:44:32,517
and this is basically just going to be
1206
00:44:32,577 --> 00:44:33,297
three
1207
00:44:33,327 --> 00:44:34,917
raised to the power of two,
1208
00:44:35,217 --> 00:44:35,757
so
1209
00:44:35,817 --> 00:44:38,817
it's just going to be three squared so we should get nine down here,
1210
00:44:39,177 --> 00:44:40,167
you can see that we do,
1211
00:44:40,557 --> 00:44:41,787
so I could pass in like
1212
00:44:41,817 --> 00:44:42,177
you know
1213
00:44:42,208 --> 00:44:43,318
some crazy number like
1214
00:44:43,558 --> 00:44:45,088
we could pass in a four
1215
00:44:45,118 --> 00:44:47,488
and we can raise it to the power of six,
1216
00:44:47,788 --> 00:44:49,588
and so we should get like a pretty big number here
1217
00:44:50,008 --> 00:44:52,648
and you can see we get four thousand ninety six so
1218
00:44:53,098 --> 00:44:53,458
this
1219
00:44:53,489 --> 00:44:56,938
power function is really useful for taking numbers to specific
1220
00:44:56,969 --> 00:44:57,598
powers.
1221
00:44:57,988 --> 00:45:02,638
so in addition to using this power function we can also use another function which is called
1222
00:45:02,668 --> 00:45:03,628
max.
1223
00:45:03,898 --> 00:45:05,188
so I can say max.
1224
00:45:05,338 --> 00:45:08,248
and what this is gonna do is it's basically gonna return
1225
00:45:08,278 --> 00:45:11,128
the larger of the two numbers that we pass into it
1226
00:45:11,398 --> 00:45:12,748
so right now I'm giving this
1227
00:45:12,778 --> 00:45:14,338
a four and a six
1228
00:45:14,518 --> 00:45:16,828
and this should tell us which number is higher
1229
00:45:17,158 --> 00:45:20,458
so over here it's just pulling out six because that's the bigger number.
1230
00:45:20,728 --> 00:45:22,558
I cannot see is another function called
1231
00:45:22,588 --> 00:45:28,739
men and this is going to do the opposite so now instead of printing out the max number it's going to print out the smallest number.
1232
00:45:29,009 --> 00:45:31,739
and it's going to turn out for down here as you can see.
1233
00:45:32,039 --> 00:45:34,919
another cool function is called the round function
1234
00:45:34,949 --> 00:45:40,409
and this is going to allow us to round a number so it's just going to follow like standard rounding rules.
1235
00:45:40,709 --> 00:45:43,469
so if I said like three point to inside of here
1236
00:45:43,739 --> 00:45:44,999
now is going around it
1237
00:45:45,029 --> 00:45:47,099
down to just normal three
1238
00:45:47,129 --> 00:45:49,229
but if I said like three point seven.
1239
00:45:49,949 --> 00:45:54,150
it's going to round it up to four so that'll allow you to round a number.
1240
00:45:54,660 --> 00:45:58,500
so there's a few other functions that I want to show you guys but in order to
1241
00:45:58,530 --> 00:46:01,830
get access to them I'm actually going to have to do something called
1242
00:46:01,890 --> 00:46:02,640
importing
1243
00:46:03,180 --> 00:46:05,430
and in python we can actually
1244
00:46:05,460 --> 00:46:06,270
import
1245
00:46:06,360 --> 00:46:07,650
external code
1246
00:46:08,040 --> 00:46:10,890
into our files and so if I want to access these
1247
00:46:10,920 --> 00:46:11,610
specific
1248
00:46:11,640 --> 00:46:12,720
math functions.
1249
00:46:13,260 --> 00:46:15,601
I have to import something called python math
1250
00:46:15,631 --> 00:46:17,281
so I can just say from
1251
00:46:17,521 --> 00:46:18,990
up here math
1252
00:46:19,591 --> 00:46:20,431
import
1253
00:46:21,331 --> 00:46:24,450
and this star and basically what this is gonna do is it's going to
1254
00:46:24,690 --> 00:46:26,130
go out and it's going to grab
1255
00:46:26,190 --> 00:46:29,371
a bunch of different math functions that we can use so
1256
00:46:29,611 --> 00:46:33,961
I already showed you guys a few of the zipper math functions but there's actually a bunch more.
1257
00:46:34,322 --> 00:46:38,762
and in order to access them we're going to need to include this line of code inside of our file.
1258
00:46:39,062 --> 00:46:42,032
so once we have that now I can access a few other so
1259
00:46:42,062 --> 00:46:44,942
is another function which is called the floor method and it's just
1260
00:46:45,002 --> 00:46:46,082
f l o r
1261
00:46:46,472 --> 00:46:48,962
and what this will do is it'll basically just grab
1262
00:46:48,992 --> 00:46:49,532
the
1263
00:46:49,562 --> 00:46:53,252
lowest number so it's essentially just going to chop off this decimal point.
1264
00:46:53,762 --> 00:46:55,292
and you can see over here now
1265
00:46:55,322 --> 00:46:57,872
we get a three because we're using that floor function.
1266
00:46:58,232 --> 00:46:59,462
there's also another one called
1267
00:46:59,492 --> 00:47:00,302
seal.
1268
00:47:00,722 --> 00:47:04,382
and that's just going to do the exact opposite so that's just going around the number up
1269
00:47:04,412 --> 00:47:05,552
no matter what so
1270
00:47:05,612 --> 00:47:07,652
no matter what will always get for
1271
00:47:07,922 --> 00:47:10,022
which we have a three point whatever here
1272
00:47:10,322 --> 00:47:14,732
and there's another one which is called square root so it's just asking you our team
1273
00:47:15,062 --> 00:47:19,712
and essentially this is just going to return the square root of a number so I can say like
1274
00:47:19,742 --> 00:47:20,702
thirty six.
1275
00:47:20,972 --> 00:47:22,772
and now we should get six back.
1276
00:47:23,522 --> 00:47:24,242
so
1277
00:47:24,332 --> 00:47:26,552
those are also very interesting functions and
1278
00:47:26,912 --> 00:47:28,082
inside of this
1279
00:47:28,112 --> 00:47:34,202
math module so we would call this a module and you don't have to worry too much about what that is right now,
1280
00:47:34,532 --> 00:47:37,862
just know that when we put this line of code into our program
1281
00:47:37,892 --> 00:47:40,232
it gives us access to a lot more
1282
00:47:40,262 --> 00:47:41,012
math
1283
00:47:41,492 --> 00:47:42,332
function so though
1284
00:47:42,572 --> 00:47:45,842
it basically allows us to do a lot more things with math
1285
00:47:45,872 --> 00:47:46,982
inside of our program
1286
00:47:47,312 --> 00:47:49,653
and there's a bunch of different math functions
1287
00:47:49,863 --> 00:47:54,483
in python and if you why you can basically just go online and search for different math functions.
1288
00:47:54,783 --> 00:47:58,804
I showed you guys a few here and I would say the ones that we looked at here are
1289
00:47:59,074 --> 00:48:02,524
probably the most commonly used but there's a bunch more.
1290
00:48:02,764 --> 00:48:03,034
and
1291
00:48:03,124 --> 00:48:04,174
like I said you know there's
1292
00:48:04,204 --> 00:48:07,324
tons of documentation on all this stuff so you can just look up
1293
00:48:07,564 --> 00:48:09,004
your math functions in
1294
00:48:09,034 --> 00:48:12,814
python and there's going to be tons and tons like lists of these things
1295
00:48:13,114 --> 00:48:16,594
that you can use inside of your programs to perform different math
1296
00:48:16,624 --> 00:48:17,404
operations,
1297
00:48:17,524 --> 00:48:24,334
but for now that has been a little bit of by using numbers a little bit about doing it on certain math operations and using functions
1298
00:48:24,425 --> 00:48:25,625
with those numbers
1299
00:48:29,495 --> 00:48:31,715
in this tutorial I'm going to show you how to get
1300
00:48:31,745 --> 00:48:33,455
input from the user.
1301
00:48:33,725 --> 00:48:36,575
so we're basically going to allow a user to
1302
00:48:36,635 --> 00:48:39,305
input information into our program.
1303
00:48:39,605 --> 00:48:42,785
and I'm actually going to take the information that the user inputs.
1304
00:48:42,995 --> 00:48:43,895
I'm gonna store it
1305
00:48:43,925 --> 00:48:47,646
inside of a variable and then we're going to be able to do something with
1306
00:48:47,706 --> 00:48:48,786
that variable.
1307
00:48:49,266 --> 00:48:52,146
so I want to show you guys how we can actually go about getting
1308
00:48:52,206 --> 00:48:53,316
input from someone.
1309
00:48:53,586 --> 00:48:55,656
and down here in my python file.
1310
00:48:56,166 --> 00:48:59,826
all I have to do to get input from someone is I just have to type out
1311
00:48:59,886 --> 00:49:00,546
input
1312
00:49:01,026 --> 00:49:02,556
and then an open and closed
1313
00:49:02,586 --> 00:49:03,576
parentheses.
1314
00:49:03,936 --> 00:49:07,056
and what this is basically going to do is it's going to tell python like
1315
00:49:07,086 --> 00:49:08,315
hey we want to get
1316
00:49:08,406 --> 00:49:09,305
input from
1317
00:49:09,335 --> 00:49:10,745
a user in python will
1318
00:49:10,955 --> 00:49:12,485
allow the user to
1319
00:49:12,515 --> 00:49:14,255
type in some information
1320
00:49:14,795 --> 00:49:17,585
and inside of these parentheses we can actually type
1321
00:49:17,615 --> 00:49:18,485
a prompt
1322
00:49:18,935 --> 00:49:22,175
and so generally when we want the user to enter in some information
1323
00:49:22,205 --> 00:49:23,915
we want to tell them what we want them
1324
00:49:23,945 --> 00:49:24,605
to enter.
1325
00:49:24,965 --> 00:49:27,545
and that's what we can put inside of here so I'm just going to say.
1326
00:49:28,115 --> 00:49:29,225
enter your
1327
00:49:29,255 --> 00:49:29,915
name,
1328
00:49:30,875 --> 00:49:33,966
so we're actually going to create a little python app,
1329
00:49:34,296 --> 00:49:36,756
which is going to allow the user to enter in their name
1330
00:49:37,056 --> 00:49:40,806
and then will store the name inside of a variable and then we'll basically just
1331
00:49:40,836 --> 00:49:43,327
say hi to the user so we'll say like high
1332
00:49:43,597 --> 00:49:45,697
and then whatever the name they entered was
1333
00:49:46,447 --> 00:49:49,117
so what I want to do is I actually wanna store
1334
00:49:49,147 --> 00:49:52,057
whatever the user and put it into our program
1335
00:49:52,477 --> 00:49:54,007
inside of a variable.
1336
00:49:54,217 --> 00:49:58,927
so I can actually go over here and I can create a variable I could just call it name
1337
00:49:59,347 --> 00:50:01,147
and I could set this variable
1338
00:50:01,207 --> 00:50:02,317
equal to
1339
00:50:02,737 --> 00:50:03,307
input.
1340
00:50:03,727 --> 00:50:07,957
so what I'm doing now is I'm taking the value that the user inputs
1341
00:50:08,437 --> 00:50:08,827
and I'm
1342
00:50:09,037 --> 00:50:10,537
storing it inside of this
1343
00:50:10,567 --> 00:50:12,277
variable container called
1344
00:50:12,337 --> 00:50:12,967
name
1345
00:50:13,447 --> 00:50:14,407
and so now
1346
00:50:14,827 --> 00:50:17,467
I have access to whatever they entered it.
1347
00:50:17,797 --> 00:50:19,537
so what we can do is we can say
1348
00:50:19,567 --> 00:50:20,287
print
1349
00:50:21,007 --> 00:50:22,027
and inside of the
1350
00:50:22,057 --> 00:50:24,127
parentheses I can just print out
1351
00:50:24,577 --> 00:50:25,207
hello
1352
00:50:26,257 --> 00:50:28,028
and then I'm just going to add on to this
1353
00:50:28,177 --> 00:50:28,778
name
1354
00:50:29,588 --> 00:50:31,688
and actually want to put an exclamation point.
1355
00:50:32,318 --> 00:50:35,498
so essentially we're getting a name from the user.
1356
00:50:35,648 --> 00:50:37,868
restoring it inside of the named variable
1357
00:50:38,018 --> 00:50:38,888
and I'm printing it
1358
00:50:38,918 --> 00:50:40,508
out onto the screen.
1359
00:50:40,778 --> 00:50:42,458
so I'm gonna go ahead and play this ?
1360
00:50:42,848 --> 00:50:45,698
and when we run the program you'll notice down here
1361
00:50:45,728 --> 00:50:47,978
python is giving us this little problem
1362
00:50:48,008 --> 00:50:48,668
so it saying
1363
00:50:48,698 --> 00:50:49,448
enter your name.
1364
00:50:49,838 --> 00:50:50,198
now
1365
00:50:50,229 --> 00:50:54,099
in here I can actually type in of values so I could type in might.
1366
00:50:54,999 --> 00:50:56,528
and then I can just hit enter
1367
00:50:57,218 --> 00:51:01,448
and pythons going to go ahead and store this value inside of that variable
1368
00:51:01,779 --> 00:51:03,159
and then it's going to print out
1369
00:51:03,219 --> 00:51:03,879
hello
1370
00:51:03,909 --> 00:51:04,449
mike.
1371
00:51:04,539 --> 00:51:05,979
and so this is kind of cool and
1372
00:51:06,009 --> 00:51:07,989
actually what we could do is we could
1373
00:51:08,199 --> 00:51:11,919
prompt the user to enter in more than one piece of information.
1374
00:51:12,549 --> 00:51:13,839
so I can actually
1375
00:51:13,869 --> 00:51:15,429
copy this line of code.
1376
00:51:16,119 --> 00:51:16,599
and I'm an
1377
00:51:16,629 --> 00:51:17,889
pasted below here
1378
00:51:18,069 --> 00:51:21,310
and why don't we have the user enter in another variable.
1379
00:51:21,520 --> 00:51:23,679
so we could have them enter in for example their
1380
00:51:23,709 --> 00:51:24,339
age.
1381
00:51:24,699 --> 00:51:26,859
and over here we just want to say enter your
1382
00:51:26,949 --> 00:51:27,550
age.
1383
00:51:27,850 --> 00:51:28,540
so now
1384
00:51:28,570 --> 00:51:31,750
we're able to get two pieces of information from the user.
1385
00:51:32,020 --> 00:51:33,640
and I could say hello name.
1386
00:51:34,030 --> 00:51:35,020
and then I can say
1387
00:51:35,830 --> 00:51:36,820
you are
1388
00:51:37,240 --> 00:51:38,410
and I'll print out their
1389
00:51:38,440 --> 00:51:38,860
age
1390
00:51:38,890 --> 00:51:40,030
so I'm going to print
1391
00:51:40,390 --> 00:51:40,930
age.
1392
00:51:41,170 --> 00:51:45,521
so now I'm basically able to get both of these pieces of information
1393
00:51:45,551 --> 00:51:47,831
from the user I can get their name
1394
00:51:48,161 --> 00:51:50,981
and I can get their age so when we run this program.
1395
00:51:52,421 --> 00:51:55,901
I can type in both of those pieces of information so as they enter your name.
1396
00:51:56,231 --> 00:51:56,801
so
1397
00:51:56,831 --> 00:51:57,371
we could just
1398
00:51:57,431 --> 00:51:58,961
make up a name like john
1399
00:51:59,261 --> 00:52:02,292
and then enter the age that say john is twenty five
1400
00:52:02,802 --> 00:52:05,532
and now is going to say hello john you are twenty five.
1401
00:52:05,922 --> 00:52:09,102
so the program is able to get input from the user and then it's
1402
00:52:09,132 --> 00:52:11,292
able to use that information
1403
00:52:11,502 --> 00:52:13,572
in order to say hi to the user and
1404
00:52:13,602 --> 00:52:15,102
tell them how old they are,
1405
00:52:15,432 --> 00:52:15,882
so
1406
00:52:15,942 --> 00:52:20,922
getting input from the user is a great way to make your programs more interactive and
1407
00:52:21,222 --> 00:52:27,012
here we're just scratching the surface right word just basically getting to know a piece of information from the user but
1408
00:52:27,312 --> 00:52:29,143
you can use these inputs to do
1409
00:52:29,203 --> 00:52:32,263
awesome things in python and as we go through this course.
1410
00:52:32,503 --> 00:52:33,193
you're going to see some
1411
00:52:33,223 --> 00:52:34,903
really cool things that we can do
1412
00:52:34,963 --> 00:52:36,283
with these inputs
1413
00:52:40,124 --> 00:52:41,984
in this tutorial I'm going to show you how to build
1414
00:52:42,014 --> 00:52:45,254
a very basic calculator in python.
1415
00:52:45,584 --> 00:52:49,454
we're basically going to build a calculator where we'll get to numbers from a user,
1416
00:52:49,664 --> 00:52:50,174
and then we'll
1417
00:52:50,204 --> 00:52:53,714
add those numbers together and print the answer out onto the screen.
1418
00:52:54,044 --> 00:52:58,664
so this will give us some practice in getting input from users and we'll also talk about getting
1419
00:52:58,694 --> 00:53:01,034
numbers from users as opposed to just
1420
00:53:01,094 --> 00:53:01,904
strings.
1421
00:53:02,204 --> 00:53:03,434
so I'm really excited to
1422
00:53:03,674 --> 00:53:04,964
get started on this calculator.
1423
00:53:05,474 --> 00:53:07,005
the first thing we want to do is
1424
00:53:07,035 --> 00:53:07,665
create
1425
00:53:07,695 --> 00:53:09,045
two variables and
1426
00:53:09,105 --> 00:53:11,685
inside of those variables we want to store
1427
00:53:11,745 --> 00:53:14,745
the two numbers that the user wants to add together
1428
00:53:15,195 --> 00:53:16,005
so down here,
1429
00:53:16,095 --> 00:53:17,086
I'm just going to say,
1430
00:53:18,046 --> 00:53:18,855
number one,
1431
00:53:19,125 --> 00:53:20,776
and that's what we'll call our first variable
1432
00:53:21,076 --> 00:53:21,316
is
1433
00:53:21,346 --> 00:53:22,216
equal to.
1434
00:53:22,456 --> 00:53:25,396
and now I need to get input from the user so I'm going to say.
1435
00:53:25,456 --> 00:53:26,146
input
1436
00:53:26,566 --> 00:53:28,006
and inside these parentheses
1437
00:53:28,036 --> 00:53:28,846
I'm going to say.
1438
00:53:28,996 --> 00:53:30,826
enter a number,
1439
00:53:33,496 --> 00:53:36,046
and now I basically want to do the same exact
1440
00:53:36,076 --> 00:53:36,736
thing
1441
00:53:36,766 --> 00:53:37,696
but for
1442
00:53:37,726 --> 00:53:38,506
the second number,
1443
00:53:38,956 --> 00:53:40,606
so we'll piece this guy down here,
1444
00:53:41,296 --> 00:53:43,456
and I'm just going to say gnome
1445
00:53:43,486 --> 00:53:44,086
two
1446
00:53:44,686 --> 00:53:45,796
and then we'll just say
1447
00:53:45,976 --> 00:53:47,356
enter another number.
1448
00:53:47,927 --> 00:53:50,207
so now we're able to store the user's input
1449
00:53:50,447 --> 00:53:51,377
inside of these
1450
00:53:51,407 --> 00:53:51,887
two
1451
00:53:51,917 --> 00:53:52,637
variables.
1452
00:53:52,817 --> 00:53:56,507
so now all I want to do is just print out the results so
1453
00:53:56,867 --> 00:54:01,308
I'm actually going to create a variable called result somebody's going to say a result
1454
00:54:01,548 --> 00:54:02,538
is equal to
1455
00:54:02,568 --> 00:54:06,168
and basically we just want to add these two numbers together something as a number one
1456
00:54:06,468 --> 00:54:06,948
plus
1457
00:54:06,978 --> 00:54:07,518
numb
1458
00:54:07,548 --> 00:54:07,998
too.
1459
00:54:08,988 --> 00:54:12,318
and now all we have to do is print out the results I'm just going to print
1460
00:54:12,918 --> 00:54:13,519
result
1461
00:54:14,329 --> 00:54:14,899
so
1462
00:54:14,929 --> 00:54:18,259
we basically have our entire program written out here
1463
00:54:18,469 --> 00:54:22,878
and this will allow us to enter in two numbers and then we'll add them together and print out the answer
1464
00:54:24,948 --> 00:54:25,998
so I could play.
1465
00:54:26,418 --> 00:54:29,268
and down here we can enter our number,
1466
00:54:29,328 --> 00:54:31,368
so I'm gonna enter the first number we'll say five,
1467
00:54:32,088 --> 00:54:35,118
and I'm going to enter my second number so let's say
1468
00:54:35,148 --> 00:54:36,828
eight point zero
1469
00:54:37,338 --> 00:54:38,508
or else a point
1470
00:54:38,718 --> 00:54:39,258
three
1471
00:54:40,278 --> 00:54:41,958
it's now should print out the answer,
1472
00:54:42,228 --> 00:54:42,888
but
1473
00:54:43,038 --> 00:54:44,628
if you look over here.
1474
00:54:45,288 --> 00:54:49,188
that's not quite the answer we were looking for at five plus
1475
00:54:49,218 --> 00:54:49,698
eight point
1476
00:54:49,728 --> 00:54:52,968
three is definitely not fifty eight points three
1477
00:54:53,328 --> 00:54:54,558
and here's what happened
1478
00:54:55,218 --> 00:54:57,648
when we get input from a user
1479
00:54:57,708 --> 00:54:59,178
by default.
1480
00:54:59,808 --> 00:55:01,518
python is just going to convert
1481
00:55:01,548 --> 00:55:02,508
it into a string,
1482
00:55:02,718 --> 00:55:04,458
so it doesn't matter what we put
1483
00:55:04,488 --> 00:55:06,408
down their when we're entering the numbers
1484
00:55:06,738 --> 00:55:08,328
python's always is going to be like.
1485
00:55:08,388 --> 00:55:08,808
ok
1486
00:55:08,838 --> 00:55:09,829
this is a string
1487
00:55:09,859 --> 00:55:10,579
that's it
1488
00:55:10,969 --> 00:55:12,019
sounds good right ?
1489
00:55:12,198 --> 00:55:13,879
it's just going to make it a string
1490
00:55:14,179 --> 00:55:16,578
in order for us to make these number one and number
1491
00:55:16,608 --> 00:55:18,018
two variables numbers,
1492
00:55:18,168 --> 00:55:22,368
we're actually going to have to convert the strings that we get from the user
1493
00:55:22,758 --> 00:55:24,018
into numbers,
1494
00:55:24,108 --> 00:55:24,618
and so
1495
00:55:24,858 --> 00:55:26,988
the way that we can do that is by
1496
00:55:27,018 --> 00:55:28,548
basically just coming over here
1497
00:55:28,818 --> 00:55:30,918
and when we add the two numbers together
1498
00:55:30,948 --> 00:55:33,618
I can use a special python function
1499
00:55:33,918 --> 00:55:35,418
in order to convert those
1500
00:55:35,448 --> 00:55:36,378
strings
1501
00:55:36,678 --> 00:55:37,698
into numbers.
1502
00:55:38,118 --> 00:55:39,888
and there's actually two
1503
00:55:39,918 --> 00:55:41,988
python functions that we could use for this.
1504
00:55:42,228 --> 00:55:43,219
the first is called
1505
00:55:43,249 --> 00:55:43,638
int
1506
00:55:43,668 --> 00:55:45,559
so I could say I auntie.
1507
00:55:45,889 --> 00:55:46,459
I can make an
1508
00:55:46,489 --> 00:55:49,489
open parentheses and I can make a close parentheses
1509
00:55:49,729 --> 00:55:53,988
and basically what this is gonna do is it's going to convert whatever is inside of these
1510
00:55:54,018 --> 00:55:55,398
open or close parentheses
1511
00:55:55,668 --> 00:55:56,148
into an
1512
00:55:56,178 --> 00:55:56,838
integer
1513
00:55:56,868 --> 00:55:57,469
number,
1514
00:55:57,918 --> 00:55:58,248
and an
1515
00:55:58,278 --> 00:56:04,219
integer number is basically a whole number so it's like one two three four or five so it's a,
1516
00:56:04,458 --> 00:56:07,489
it's a whole number another word that can't have a decimal point,
1517
00:56:08,749 --> 00:56:10,458
so what I could do is I could say
1518
00:56:10,908 --> 00:56:11,838
I n t,
1519
00:56:12,318 --> 00:56:13,308
and I could put these
1520
00:56:13,338 --> 00:56:14,148
inside of
1521
00:56:14,328 --> 00:56:15,168
parentheses.
1522
00:56:15,378 --> 00:56:19,788
and now what this is gonna do is it's going to convert both of these numbers into
1523
00:56:19,848 --> 00:56:21,048
integers in other words
1524
00:56:21,408 --> 00:56:22,248
into
1525
00:56:22,338 --> 00:56:24,528
whole numbers that don't have decimals,
1526
00:56:24,708 --> 00:56:28,698
and it's going to add them together and will print out the result so why don't we do that
1527
00:56:28,759 --> 00:56:30,528
we'll just see if this works I'm gonna
1528
00:56:30,648 --> 00:56:31,578
click the play button
1529
00:56:31,998 --> 00:56:35,688
and down here we'll enter our first number sums can enter into four
1530
00:56:36,078 --> 00:56:37,549
and then I'll answer in a five
1531
00:56:37,789 --> 00:56:41,358
and now you can see it's printing out the correct answer four plus
1532
00:56:41,388 --> 00:56:42,018
five
1533
00:56:42,198 --> 00:56:45,168
and so that's essentially our basic calculator.
1534
00:56:45,228 --> 00:56:46,488
but we do have one
1535
00:56:46,518 --> 00:56:50,719
problem with this calculator salmon run it again and I'll show you guys with that problem is
1536
00:56:50,749 --> 00:56:52,159
if I wanted to add in
1537
00:56:52,189 --> 00:56:57,169
a decimal number so we'll add four point three and five point five.
1538
00:56:58,099 --> 00:56:59,929
you'll see that we're getting this error.
1539
00:57:00,169 --> 00:57:02,869
and that's because I'm using this
1540
00:57:02,959 --> 00:57:03,320
ain't
1541
00:57:03,350 --> 00:57:05,030
function of here and this
1542
00:57:05,090 --> 00:57:08,029
int function is looking for a whole number.
1543
00:57:08,299 --> 00:57:08,659
so if
1544
00:57:08,689 --> 00:57:11,900
I put decimal numbers inside of there it's going to break the programs.
1545
00:57:12,710 --> 00:57:14,510
there's another function we can use
1546
00:57:14,570 --> 00:57:15,200
instead of an
1547
00:57:15,230 --> 00:57:16,969
n we can say float
1548
00:57:17,240 --> 00:57:18,020
and a float
1549
00:57:18,050 --> 00:57:21,709
is basically just a number that has decimal so it's a decimal number
1550
00:57:22,129 --> 00:57:25,339
so I can convert both of these guys into floats
1551
00:57:26,119 --> 00:57:29,449
and now I'll be able to use decimal number so I can click play.
1552
00:57:29,959 --> 00:57:33,079
and I can just enter into number so I could say like four
1553
00:57:33,559 --> 00:57:35,899
and I could also say like five point five.
1554
00:57:36,139 --> 00:57:38,089
and now it's going to be able to add
1555
00:57:38,119 --> 00:57:39,259
both of those numbers.
1556
00:57:39,619 --> 00:57:41,060
even if one of them is a decimal
1557
00:57:41,090 --> 00:57:44,299
and that's the beauty of using that little float function so
1558
00:57:44,599 --> 00:57:49,309
in certain circumstances you might want the user to only be able to enter into an integer
1559
00:57:49,579 --> 00:57:50,569
to a whole number.
1560
00:57:50,719 --> 00:57:52,999
but in a lot of cases like in this calculator.
1561
00:57:53,059 --> 00:57:56,870
we want them to be able to answer any number that they want so we're going to use this flow
1562
00:57:57,200 --> 00:57:57,710
function.
1563
00:57:58,190 --> 00:57:58,580
so
1564
00:57:58,610 --> 00:58:02,750
I'm just going to recap what we did one more time we created two variables number one and number two
1565
00:58:03,410 --> 00:58:08,240
and we basically stored the two numbers that the user's implanted into those variables,
1566
00:58:08,660 --> 00:58:11,210
then we converted them into numbers
1567
00:58:11,571 --> 00:58:12,141
and
1568
00:58:12,171 --> 00:58:12,651
weed
1569
00:58:12,681 --> 00:58:14,990
out of them together and we printed out the results so
1570
00:58:15,051 --> 00:58:17,301
this is a pretty cool calculator, i'm happy with it.
1571
00:58:17,601 --> 00:58:18,951
hopefully you guys learned something.
1572
00:58:19,161 --> 00:58:26,272
and as we go forward in this python course you're going to learn all sorts of ways that we can make this calculator more complex
1573
00:58:30,082 --> 00:58:32,452
in this tutorial I wanna show you guys how to build a
1574
00:58:32,482 --> 00:58:34,372
mad libs game in
1575
00:58:34,402 --> 00:58:35,062
python,
1576
00:58:35,482 --> 00:58:41,632
so a mad libs game is basically just a game where you can enter in a bunch of random words so like
1577
00:58:41,752 --> 00:58:42,112
you know
1578
00:58:42,142 --> 00:58:43,342
verbs nouns
1579
00:58:43,402 --> 00:58:44,302
names
1580
00:58:44,422 --> 00:58:45,112
colors
1581
00:58:45,532 --> 00:58:46,042
and
1582
00:58:46,132 --> 00:58:48,022
you basically take all of those words and
1583
00:58:48,052 --> 00:58:50,662
put them into a story randomly so
1584
00:58:51,412 --> 00:58:52,282
over here I had
1585
00:58:52,312 --> 00:58:53,692
my web browser I just have
1586
00:58:53,752 --> 00:58:55,912
an example of a mad libs so you know
1587
00:58:55,942 --> 00:59:00,353
down here were basically just taking random words like an adjective or a noun or a pronoun
1588
00:59:00,743 --> 00:59:02,153
and entering them in
1589
00:59:02,213 --> 00:59:06,083
sort of a story so like you read through the story than like some random word pops up in
1590
00:59:06,353 --> 00:59:08,423
mad libs can be pretty fun and I'm sure ..>
1591
00:59:08,453 --> 00:59:08,723
yeah
1592
00:59:08,753 --> 00:59:10,283
he's heard of mad libs before,
1593
00:59:10,763 --> 00:59:12,743
but if not, now it is a little introduction.
1594
00:59:12,803 --> 00:59:14,783
so I want to create a mad libs in python
1595
00:59:14,813 --> 00:59:16,944
and this is going to be really cool so
1596
00:59:17,244 --> 00:59:18,504
down here I have this, like,
1597
00:59:18,534 --> 00:59:19,824
a little poem which says:
1598
00:59:20,094 --> 00:59:22,554
roses are red \ violets are blue \ I love you.
1599
00:59:22,974 --> 00:59:25,194
and so y'know, this is a compelling classic poem
1600
00:59:25,224 --> 00:59:25,704
but
1601
00:59:26,124 --> 00:59:30,954
I think we should mix it up a little bit and create a mad lib for this poem.
1602
00:59:31,404 --> 00:59:32,034
and so
1603
00:59:32,064 --> 00:59:34,884
instead of having this red colour over here,
1604
00:59:35,214 --> 00:59:37,104
I want to have the user answer in
1605
00:59:37,134 --> 00:59:38,034
their own color
1606
00:59:38,964 --> 00:59:40,614
instead of having violets,
1607
00:59:40,824 --> 00:59:42,354
why don't we have them answer in
1608
00:59:42,384 --> 00:59:43,854
a plural noun.
1609
00:59:44,574 --> 00:59:46,494
and instead of saying "I love you"
1610
00:59:46,524 --> 00:59:50,184
why don't we have them say "I love --" and then some celebrity
1611
00:59:50,214 --> 00:59:51,414
so celebrity.
1612
00:59:52,254 --> 00:59:52,764
so
1613
00:59:52,794 --> 00:59:58,944
this is the basic structure for our little madlib. right; it wants you basically have the user answering a color
1614
00:59:59,424 --> 01:00:00,925
enter in a plural noun.
1615
01:00:01,195 --> 01:00:02,785
an answer in a celebrity,
1616
01:00:03,055 --> 01:00:03,775
and I'll take
1617
01:00:03,805 --> 01:00:05,185
all of those words and
1618
01:00:05,334 --> 01:00:08,755
put them inside of our madlib and hopefully we end up with something that's pretty funny.
1619
01:00:09,385 --> 01:00:09,745
so
1620
01:00:09,775 --> 01:00:13,375
how can we actually go about building this in python well
1621
01:00:13,555 --> 01:00:19,226
the first thing we're going to have to do is we're going to have to be able to get these words from the user right that's pretty obvious.
1622
01:00:19,556 --> 01:00:20,276
so
1623
01:00:20,366 --> 01:00:23,456
I think what we should do as we should create three variables
1624
01:00:23,516 --> 01:00:24,386
called color
1625
01:00:24,417 --> 01:00:25,797
plural noun in celebrity
1626
01:00:26,097 --> 01:00:27,057
and will store
1627
01:00:27,087 --> 01:00:27,747
the user's
1628
01:00:27,777 --> 01:00:28,437
inputs.
1629
01:00:28,497 --> 01:00:30,116
inside of those
1630
01:00:30,177 --> 01:00:30,896
variables.
1631
01:00:31,257 --> 01:00:33,266
so up here let's create those variables
1632
01:00:33,296 --> 01:00:35,427
the first very well I'm going to create is going to be called
1633
01:00:35,457 --> 01:00:36,027
color
1634
01:00:36,057 --> 01:00:37,257
so it's a color.
1635
01:00:37,407 --> 01:00:38,187
and I want to set this
1636
01:00:38,217 --> 01:00:39,087
equal to
1637
01:00:39,117 --> 01:00:39,357
the
1638
01:00:39,448 --> 01:00:41,098
inputs are going to say input
1639
01:00:41,518 --> 01:00:44,968
and inside of here I was going to give them a prompts all say answer a
1640
01:00:44,998 --> 01:00:45,628
color.
1641
01:00:46,888 --> 01:00:49,408
and we can basically just copy this line of code.
1642
01:00:49,858 --> 01:00:50,338
and
1643
01:00:50,368 --> 01:00:52,319
I'm going to paste it down below
1644
01:00:52,619 --> 01:00:53,969
and we'll paste one more time.
1645
01:00:54,449 --> 01:00:56,729
so now we're going to create our plural noun
1646
01:00:56,759 --> 01:00:58,949
very also I'll say peoria
1647
01:00:59,069 --> 01:01:00,149
pluralism now
1648
01:01:00,899 --> 01:01:02,760
and want to say answer a
1649
01:01:03,810 --> 01:01:04,470
plural
1650
01:01:04,500 --> 01:01:05,010
now
1651
01:01:06,390 --> 01:01:07,859
and actually over here I want a meager
1652
01:01:07,919 --> 01:01:08,879
coal as well.
1653
01:01:09,509 --> 01:01:11,429
so then finally we'll create our
1654
01:01:11,609 --> 01:01:14,249
celebrity variables they enter a
1655
01:01:14,939 --> 01:01:16,439
celebrity and
1656
01:01:17,009 --> 01:01:19,859
so now basically we're creating three variables called
1657
01:01:19,889 --> 01:01:21,899
color plural noun in celebrity
1658
01:01:22,079 --> 01:01:25,979
and inside of them were storing the color that the user enters
1659
01:01:26,219 --> 01:01:29,609
the plural noun the user enters and the celebrity these adventures.
1660
01:01:29,909 --> 01:01:30,389
so
1661
01:01:30,449 --> 01:01:32,189
the last thing we have to do is
1662
01:01:32,219 --> 01:01:33,029
replace
1663
01:01:33,059 --> 01:01:34,799
these guys with those variables
1664
01:01:34,829 --> 01:01:35,369
so
1665
01:01:35,819 --> 01:01:39,540
I'm basically just going to add in the colour over here
1666
01:01:40,560 --> 01:01:42,930
and we're going to add in the plural noun
1667
01:01:42,960 --> 01:01:43,620
so
1668
01:01:43,650 --> 01:01:44,730
I can just go like
1669
01:01:44,820 --> 01:01:45,810
this.
1670
01:01:50,940 --> 01:01:53,820
and finally what is adding that celebrity.
1671
01:01:56,640 --> 01:01:57,060
so
1672
01:01:57,120 --> 01:01:58,440
now we have a prequel mallet
1673
01:01:58,470 --> 01:02:02,131
and it should be functional everything should work it looks like it's
1674
01:02:02,191 --> 01:02:03,781
good to go so
1675
01:02:04,291 --> 01:02:06,570
let's come over here and we'll run our program
1676
01:02:06,720 --> 01:02:08,610
and then down here in the council.
1677
01:02:09,510 --> 01:02:11,700
we can play are a little mad libs games so
1678
01:02:12,060 --> 01:02:14,160
they enter a color I'm just going to say.
1679
01:02:14,280 --> 01:02:15,030
magenta
1680
01:02:15,960 --> 01:02:18,780
enter a plural now when we say,
1681
01:02:19,560 --> 01:02:20,850
microwaves
1682
01:02:21,150 --> 01:02:24,900
and enter a celebrity you at say Tom Hanks.
1683
01:02:25,170 --> 01:02:25,650
so
1684
01:02:25,710 --> 01:02:29,280
when I click enter what should happen is we should get our mad libs
1685
01:02:29,310 --> 01:02:30,120
printed out some
1686
01:02:30,150 --> 01:02:30,810
good enter
1687
01:02:31,290 --> 01:02:34,560
and now we have our methods was as roses are magenta
1688
01:02:34,590 --> 01:02:36,000
microwaves are blue
1689
01:02:36,030 --> 01:02:37,590
I love Tom Hanks.
1690
01:02:37,920 --> 01:02:39,330
so it's a pretty good madlib
1691
01:02:39,600 --> 01:02:40,890
and obviously you know,
1692
01:02:40,950 --> 01:02:41,880
the more,
1693
01:02:41,970 --> 01:02:44,280
the more print statements we put over here you know
1694
01:02:44,310 --> 01:02:49,260
the better the madlib could be and we could store as many, y'know, variables up here as we wanted.
1695
01:02:49,861 --> 01:02:52,500
this was just a very simple madlib we only took in
1696
01:02:52,531 --> 01:02:58,561
three inputs but you know you could see how you could take something like this and create a little mad libs game so
1697
01:02:59,071 --> 01:03:05,071
your homework for this lesson is to go off and make your own madlib game hopefully one that's a little bit funnier than mine.
1698
01:03:05,551 --> 01:03:06,690
but that's the basics
1699
01:03:06,720 --> 01:03:08,760
of creating a mad libs game in
1700
01:03:08,790 --> 01:03:09,450
python
1701
01:03:13,470 --> 01:03:17,850
in this tutorial on its artsy guys about working with lists in python.
1702
01:03:18,300 --> 01:03:23,041
a lot of times when you're programming in python you're going to be dealing with large amounts of data,
1703
01:03:23,430 --> 01:03:23,850
and
1704
01:03:23,880 --> 01:03:26,851
when you're dealing with large amounts of data you want to make sure that you can
1705
01:03:26,881 --> 01:03:29,281
manage it and organize it properly,
1706
01:03:29,581 --> 01:03:34,111
and the list is essentially just a structure that we can use inside of python
1707
01:03:34,351 --> 01:03:37,501
to store the lists of information so we can take
1708
01:03:37,741 --> 01:03:40,561
a bunch of different data values we can put them inside a list
1709
01:03:40,591 --> 01:03:43,441
and it allows us to organize them and keep track of them
1710
01:03:43,471 --> 01:03:44,011
a lot
1711
01:03:44,071 --> 01:03:44,641
easier.
1712
01:03:45,001 --> 01:03:48,452
so generally you would create a python less than you would put a bunch of
1713
01:03:48,872 --> 01:03:50,102
related values
1714
01:03:50,132 --> 01:03:53,462
inside of that list and then you can use it throughout your program so
1715
01:03:53,732 --> 01:03:58,443
I'm actually eyes are just the basics of using lists we're going to look at some of the common use cases and
1716
01:03:58,713 --> 01:04:02,463
really just get you up to speed with what lists are and why they're useful so
1717
01:04:02,823 --> 01:04:03,903
over here in my program
1718
01:04:03,933 --> 01:04:04,623
I'm actually going to
1719
01:04:04,653 --> 01:04:06,213
create a list and
1720
01:04:06,423 --> 01:04:07,263
we create a list
1721
01:04:07,293 --> 01:04:09,783
a lot might we create a python
1722
01:04:09,813 --> 01:04:11,793
it's like a normal python variable so
1723
01:04:12,033 --> 01:04:13,984
the first thing we want to do and we're making a list
1724
01:04:14,014 --> 01:04:14,823
is give it
1725
01:04:14,854 --> 01:04:17,524
a name so we want to give it a descriptive name
1726
01:04:17,764 --> 01:04:21,484
something that's going to basically describe what's inside the list
1727
01:04:21,844 --> 01:04:22,894
in my case for
1728
01:04:22,924 --> 01:04:24,484
this example let's make a list
1729
01:04:24,514 --> 01:04:28,714
of like friends so we could say here's a list of all my friends so I can say
1730
01:04:29,104 --> 01:04:29,854
friends
1731
01:04:30,244 --> 01:04:31,234
and I'm going to set this
1732
01:04:31,264 --> 01:04:32,224
equal to
1733
01:04:32,314 --> 01:04:34,024
the list of values
1734
01:04:34,084 --> 01:04:35,314
that represent my friends
1735
01:04:35,584 --> 01:04:38,284
and we want to create a list we can use these
1736
01:04:38,344 --> 01:04:40,594
opening closed square brackets.
1737
01:04:40,895 --> 01:04:42,635
so whenever you use these open and closed
1738
01:04:42,665 --> 01:04:44,945
square brackets python basically nose
1739
01:04:44,975 --> 01:04:47,435
okay they want to store a bunch of values
1740
01:04:47,465 --> 01:04:48,755
inside of this list.
1741
01:04:49,205 --> 01:04:53,705
so why don't we go ahead and start adding some values so we can say like my friends are like
1742
01:04:55,115 --> 01:04:56,075
tavern,
1743
01:04:56,825 --> 01:04:57,785
karen
1744
01:04:58,865 --> 01:05:00,275
and say jim.
1745
01:05:00,665 --> 01:05:03,335
so here I have three values
1746
01:05:03,365 --> 01:05:05,675
inside of my friend's array.
1747
01:05:06,035 --> 01:05:11,615
so when we're creating a normal variable in python generally we just give it one value
1748
01:05:11,915 --> 01:05:12,125
right
1749
01:05:12,155 --> 01:05:13,205
now to create a variable
1750
01:05:13,235 --> 01:05:13,745
I would give it
1751
01:05:13,775 --> 01:05:16,925
one value may be a string or a number or a boolean.
1752
01:05:17,375 --> 01:05:18,875
but when we make lists
1753
01:05:18,905 --> 01:05:21,605
were able to store multiple values
1754
01:05:21,906 --> 01:05:23,526
inside of the same like
1755
01:05:23,556 --> 01:05:24,906
little item inside of the same
1756
01:05:24,936 --> 01:05:25,866
object right
1757
01:05:26,227 --> 01:05:29,737
and then what I can do is I can access these individual items
1758
01:05:29,797 --> 01:05:31,387
inside of my program so
1759
01:05:31,747 --> 01:05:33,457
inside of this friends
1760
01:05:33,517 --> 01:05:35,227
list were basically storing
1761
01:05:35,257 --> 01:05:38,707
all of these different values and that can be really useful so
1762
01:05:39,067 --> 01:05:42,067
now that we've stored some values let's talk about what you can put
1763
01:05:42,127 --> 01:05:45,157
inside of a list so you can really put any piece of
1764
01:05:45,367 --> 01:05:46,507
information in python
1765
01:05:46,537 --> 01:05:47,498
we could put things like
1766
01:05:47,798 --> 01:05:49,627
strings, numbers, or booleans
1767
01:05:49,688 --> 01:05:54,127
so if I wanted instead of just putting strings here I could change like one of these to a number
1768
01:05:54,367 --> 01:05:56,647
and I could change one of these to a boolean
1769
01:05:56,887 --> 01:05:57,698
and wouldn't matter
1770
01:05:57,728 --> 01:05:59,588
python's going to be fine with that.
1771
01:06:00,278 --> 01:06:02,198
let's change it back to strings just
1772
01:06:02,288 --> 01:06:03,968
for the sake of the example so
1773
01:06:04,298 --> 01:06:06,518
now that we've created our list
1774
01:06:06,548 --> 01:06:07,958
how can we access
1775
01:06:08,018 --> 01:06:09,278
individual elements
1776
01:06:09,308 --> 01:06:10,388
inside of this list
1777
01:06:10,418 --> 01:06:11,228
it's a good question.
1778
01:06:11,588 --> 01:06:13,899
I'm going to go ahead and print something out to the screen.
1779
01:06:13,959 --> 01:06:15,430
the first thing we can do is we can just
1780
01:06:15,460 --> 01:06:17,620
print out the actual list so
1781
01:06:17,830 --> 01:06:19,750
I can just say print friends
1782
01:06:19,930 --> 01:06:21,550
and then when I run this program.
1783
01:06:21,790 --> 01:06:24,070
if we look down here in the console you can see it's just
1784
01:06:24,100 --> 01:06:26,351
printing out the actual list of friends right,
1785
01:06:26,951 --> 01:06:28,481
but let's say that I wanted to print
1786
01:06:28,511 --> 01:06:29,711
out a specific
1787
01:06:29,741 --> 01:06:31,301
element inside of this list
1788
01:06:31,631 --> 01:06:34,961
where I can actually refer to elements by their
1789
01:06:34,991 --> 01:06:35,561
index
1790
01:06:35,591 --> 01:06:36,101
so
1791
01:06:36,311 --> 01:06:38,261
each one of the elements inside of this list
1792
01:06:38,292 --> 01:06:39,432
has a particular
1793
01:06:39,462 --> 01:06:40,122
index
1794
01:06:40,362 --> 01:06:44,051
and the index is actually started zero so we would say that this
1795
01:06:44,201 --> 01:06:46,151
first element in the list kevin
1796
01:06:46,301 --> 01:06:47,861
has an index of zero,
1797
01:06:48,161 --> 01:06:49,091
we would say that this
1798
01:06:49,121 --> 01:06:49,841
other element
1799
01:06:49,871 --> 01:06:51,761
karen has an index of one.
1800
01:06:52,091 --> 01:06:52,511
and this
1801
01:06:52,541 --> 01:06:55,301
third element jim would have an index of two.
1802
01:06:55,750 --> 01:06:56,531
so even though
1803
01:06:56,561 --> 01:06:59,200
jim is technically the third element
1804
01:06:59,230 --> 01:07:00,461
inside of the list.
1805
01:07:00,791 --> 01:07:02,651
it has an index of two
1806
01:07:02,891 --> 01:07:06,041
and that's because we start indexing at index position
1807
01:07:06,071 --> 01:07:06,521
one.
1808
01:07:07,031 --> 01:07:09,341
and so that is kind of how this work and that's how list
1809
01:07:09,371 --> 01:07:10,181
indexes work
1810
01:07:10,211 --> 01:07:10,751
so
1811
01:07:11,111 --> 01:07:12,221
if I wanted to
1812
01:07:12,251 --> 01:07:15,611
access a specific element inside of my friends list.
1813
01:07:15,851 --> 01:07:17,411
I can just referred to it by its
1814
01:07:17,471 --> 01:07:18,161
index.
1815
01:07:18,431 --> 01:07:21,281
so over here after which I bought friends I'm just going to tape an
1816
01:07:21,342 --> 01:07:23,172
open and closed square bracket,
1817
01:07:23,502 --> 01:07:24,132
and inside
1818
01:07:24,162 --> 01:07:25,602
this open and close square bracket
1819
01:07:25,632 --> 01:07:26,442
I want to put the
1820
01:07:26,472 --> 01:07:27,132
index
1821
01:07:27,162 --> 01:07:28,031
of the element
1822
01:07:28,092 --> 01:07:29,232
inside the list
1823
01:07:29,442 --> 01:07:30,672
that I want to access
1824
01:07:30,912 --> 01:07:32,292
so fallen to access
1825
01:07:32,531 --> 01:07:33,101
this guy right
1826
01:07:33,131 --> 01:07:34,061
here this element.
1827
01:07:34,331 --> 01:07:35,441
I can just put a zero.
1828
01:07:35,651 --> 01:07:36,611
so I can say friends
1829
01:07:36,641 --> 01:07:37,331
zero.
1830
01:07:37,601 --> 01:07:39,131
and now when I run my program,
1831
01:07:39,401 --> 01:07:42,042
it's just going to print out that value it's just going to pronounce
1832
01:07:42,072 --> 01:07:42,552
cabin,
1833
01:07:42,882 --> 01:07:44,292
if only to access this
1834
01:07:44,322 --> 01:07:46,452
gem value over here I can put a
1835
01:07:46,482 --> 01:07:46,992
two
1836
01:07:47,352 --> 01:07:48,852
and that will give us that
1837
01:07:48,942 --> 01:07:49,752
jim value
1838
01:07:49,782 --> 01:07:50,862
you can see right there,
1839
01:07:50,952 --> 01:07:52,632
so we can access elements
1840
01:07:52,662 --> 01:07:53,682
based off of
1841
01:07:53,712 --> 01:07:54,762
their index
1842
01:07:54,792 --> 01:07:55,542
we can also
1843
01:07:55,572 --> 01:07:56,592
access elements
1844
01:07:57,402 --> 01:07:58,482
based off of their index
1845
01:07:58,512 --> 01:08:00,013
from the back of the list
1846
01:08:00,043 --> 01:08:00,493
so
1847
01:08:00,643 --> 01:08:01,783
for example if I said
1848
01:08:01,813 --> 01:08:03,613
negative one inside of here,
1849
01:08:03,913 --> 01:08:05,863
this is going to give me access to this
1850
01:08:05,893 --> 01:08:07,573
value right here for jim.
1851
01:08:07,663 --> 01:08:13,904
and you can see that's what it does so when we use negatives it starts indexing from the back of the list so if I start at negative two,
1852
01:08:14,144 --> 01:08:15,404
this is going to give us
1853
01:08:15,434 --> 01:08:16,124
karen
1854
01:08:16,334 --> 01:08:18,284
so you can use the negatives to access
1855
01:08:18,313 --> 01:08:19,543
items at the back of the list.
1856
01:08:19,994 --> 01:08:22,483
just keep in mind though and this is kind of an
1857
01:08:22,573 --> 01:08:23,203
interesting
1858
01:08:24,283 --> 01:08:28,544
we said we would say this first element here is index position zero
1859
01:08:29,144 --> 01:08:29,534
right
1860
01:08:29,564 --> 01:08:32,294
but we would say the first element at the back of the list
1861
01:08:32,324 --> 01:08:33,434
is index position
1862
01:08:33,463 --> 01:08:34,604
negative one so
1863
01:08:34,633 --> 01:08:35,563
just keep that in mind.
1864
01:08:35,713 --> 01:08:38,594
so there's actually other ways that we can access like just
1865
01:08:38,624 --> 01:08:40,664
portions of this list so for example,
1866
01:08:40,904 --> 01:08:46,124
let's say I just wanted to select the last two elements in this list and I didn't want us like the first one
1867
01:08:46,574 --> 01:08:48,555
will in here I can just say one
1868
01:08:48,584 --> 01:08:49,604
with a colon,
1869
01:08:49,754 --> 01:08:52,965
and this will grab the element at index position one and
1870
01:08:52,995 --> 01:08:53,984
all of the elements
1871
01:08:54,014 --> 01:08:55,935
after that so now we should describe
1872
01:08:55,964 --> 01:08:56,924
jim and karen
1873
01:08:58,004 --> 01:08:59,565
or carrying gym in that order.
1874
01:09:00,045 --> 01:09:01,905
I could also specify a range.
1875
01:09:02,175 --> 01:09:04,845
so actually let me out in a couple other elements,
1876
01:09:04,965 --> 01:09:06,766
just so that we can illustrate this better.
1877
01:09:07,545 --> 01:09:08,956
so are in two more names.
1878
01:09:09,166 --> 01:09:11,446
so if I wanted to I could select like
1879
01:09:11,476 --> 01:09:13,396
the element and exposition one
1880
01:09:13,425 --> 01:09:16,486
up to the element at index position three so
1881
01:09:16,666 --> 01:09:17,477
it's going to grab
1882
01:09:17,506 --> 01:09:19,066
this one says one,
1883
01:09:19,396 --> 01:09:20,086
two
1884
01:09:20,356 --> 01:09:24,407
and it's actually not going to grab the third one so it's it's going to grab all the elements
1885
01:09:24,437 --> 01:09:27,047
up to but not including three so it'll grab
1886
01:09:27,077 --> 01:09:28,007
karen and
1887
01:09:28,037 --> 01:09:28,606
jim,
1888
01:09:29,687 --> 01:09:32,686
let's go ahead and run this and you can see it grabs canon japan so
1889
01:09:33,106 --> 01:09:34,307
you can either just put like
1890
01:09:34,427 --> 01:09:37,127
one with a colon after it and it'll grab that
1891
01:09:37,367 --> 01:09:40,248
in exposition in everything after it or even specify like
1892
01:09:40,277 --> 01:09:41,897
arrange that you want to grab from.
1893
01:09:42,018 --> 01:09:43,548
so that's how we can access
1894
01:09:43,578 --> 01:09:45,438
elements inside of this list
1895
01:09:45,468 --> 01:09:47,718
but we can also a modify elements
1896
01:09:47,748 --> 01:09:48,498
so for example
1897
01:09:48,527 --> 01:09:49,547
I could come down here.
1898
01:09:49,877 --> 01:09:53,298
let's say I want to modify this value right here karen
1899
01:09:53,658 --> 01:09:56,988
we'll all you have to do is just access that elements I could say
1900
01:09:57,408 --> 01:09:58,158
friends
1901
01:09:58,188 --> 01:09:58,547
and
1902
01:09:58,577 --> 01:10:00,557
karen is that at position of one
1903
01:10:01,007 --> 01:10:03,887
and I could change this to whatever I want so I could say friends
1904
01:10:03,917 --> 01:10:05,597
in that position one is equal to
1905
01:10:05,626 --> 01:10:06,227
mike ?
1906
01:10:06,646 --> 01:10:07,217
and now
1907
01:10:07,247 --> 01:10:08,597
when we print out friends
1908
01:10:08,626 --> 01:10:09,827
and at position one
1909
01:10:10,187 --> 01:10:13,067
that value is going to be updated so it's just going to say
1910
01:10:13,097 --> 01:10:14,417
mike instead of saying
1911
01:10:14,446 --> 01:10:14,926
karen
1912
01:10:15,286 --> 01:10:18,976
so it can be really useful to modify values inside of
1913
01:10:19,006 --> 01:10:19,486
arrays
1914
01:10:19,516 --> 01:10:23,355
so it can be really useful to modify values inside of python lists.
1915
01:10:23,415 --> 01:10:25,905
so those are kind of the basics of working with lists
1916
01:10:25,935 --> 01:10:28,935
in python and actually in the next tutorial monastery guys
1917
01:10:28,995 --> 01:10:30,194
even more ways
1918
01:10:30,645 --> 01:10:32,655
that we can use these less we're going to learn how to link
1919
01:10:32,685 --> 01:10:35,295
add elements to a less delete elements from a less
1920
01:10:35,745 --> 01:10:37,846
copy lists and a bunch of cool stuff
1921
01:10:38,386 --> 01:10:38,776
with
1922
01:10:38,836 --> 01:10:41,266
these lists but for now this has just been sort of like
1923
01:10:41,506 --> 01:10:43,787
the basics of working with lists
1924
01:10:47,537 --> 01:10:50,326
in this tutorial I wanna talk to you guys about using
1925
01:10:50,355 --> 01:10:52,155
functions with lists
1926
01:10:52,185 --> 01:10:53,025
in python,
1927
01:10:53,505 --> 01:10:54,135
and python
1928
01:10:54,165 --> 01:10:58,816
a list is one of the most important structures where we can store our information.
1929
01:10:59,206 --> 01:11:03,646
a list basically allows you to take a bunch of different values and organize them and store them
1930
01:11:03,946 --> 01:11:05,687
inside of their own little list
1931
01:11:05,716 --> 01:11:06,526
structure
1932
01:11:06,917 --> 01:11:09,437
so down here my program you can see I have
1933
01:11:09,466 --> 01:11:11,896
two less I have a list of lucky numbers.
1934
01:11:12,106 --> 01:11:13,816
and this is just a bunch of different numbers,
1935
01:11:14,116 --> 01:11:15,706
and then I have a list of friends
1936
01:11:15,735 --> 01:11:17,925
so this could be like a list of somebody's friends
1937
01:11:18,255 --> 01:11:21,135
and it's basically just a bunch of strings with names in them.
1938
01:11:21,405 --> 01:11:22,785
so these two lists
1939
01:11:22,814 --> 01:11:25,515
are storing a bunch of different values and
1940
01:11:25,725 --> 01:11:26,985
what makes this awesome is
1941
01:11:27,015 --> 01:11:29,354
not only can I store like this many values I mean
1942
01:11:29,384 --> 01:11:30,043
I could store
1943
01:11:30,073 --> 01:11:32,923
hundreds or thousands or millions of values.
1944
01:11:33,073 --> 01:11:37,573
and when you're working with a lot of data and a lot of information and python bees lists are
1945
01:11:37,603 --> 01:11:38,593
invaluable.
1946
01:11:38,893 --> 01:11:44,744
so because lists are so important there's actually a bunch of different functions that we can use with lists
1947
01:11:45,014 --> 01:11:48,374
and those functions allow us to do things like modify the lists
1948
01:11:48,554 --> 01:11:51,224
and get information about the list so
1949
01:11:51,974 --> 01:11:52,574
in this tutorial
1950
01:11:52,604 --> 01:11:54,254
I just want to show you a bunch of those
1951
01:11:54,284 --> 01:11:58,064
functions we're going to talk about some of the most common and the most popular functions
1952
01:11:58,334 --> 01:11:59,924
that you would use on lists
1953
01:11:59,954 --> 01:12:03,165
to make them more powerful and make them more easy to use.
1954
01:12:03,524 --> 01:12:03,944
so
1955
01:12:03,974 --> 01:12:06,074
the first thing we can do is obviously just print
1956
01:12:06,104 --> 01:12:09,224
out a list so down here I'm printing out this
1957
01:12:09,254 --> 01:12:10,154
friends list
1958
01:12:10,484 --> 01:12:10,934
when a warm
1959
01:12:10,964 --> 01:12:12,344
and when I run my program,
1960
01:12:13,094 --> 01:12:14,294
you see down here we're just
1961
01:12:14,324 --> 01:12:16,334
printing out all the elements in the list so
1962
01:12:16,575 --> 01:12:17,955
it's always good to be able to print
1963
01:12:17,984 --> 01:12:18,314
out
1964
01:12:18,344 --> 01:12:19,994
all the elements inside of a list,
1965
01:12:20,054 --> 01:12:22,514
but there's a lot of other functions that we can use so
1966
01:12:22,664 --> 01:12:28,695
one function is called the extend function in the extend function will basically allow you to take a list
1967
01:12:29,025 --> 01:12:29,445
and
1968
01:12:29,475 --> 01:12:32,774
append another list onto the end of it so I could say like
1969
01:12:33,524 --> 01:12:34,274
friends
1970
01:12:34,304 --> 01:12:34,874
dot
1971
01:12:34,964 --> 01:12:35,834
extend
1972
01:12:36,284 --> 01:12:37,904
and inside of these parentheses
1973
01:12:37,934 --> 01:12:39,555
I can pass in the list
1974
01:12:39,584 --> 01:12:41,685
that I wanted to add onto the friends list.
1975
01:12:41,955 --> 01:12:42,945
so I could say like
1976
01:12:43,035 --> 01:12:43,965
lucky
1977
01:12:44,115 --> 01:12:44,835
numbers.
1978
01:12:45,076 --> 01:12:47,236
and now when I print out this friends list.
1979
01:12:47,386 --> 01:12:50,056
not only is it going to have all the elements in the friends list
1980
01:12:50,085 --> 01:12:53,265
it's also going to have all the elements inside the lucky numbers list
1981
01:12:53,535 --> 01:12:55,815
you can see down here we have all our friends,
1982
01:12:56,055 --> 01:12:57,015
and we also have
1983
01:12:57,075 --> 01:13:00,586
the numbers overhears that's a really easy way to essentially just like
1984
01:13:00,916 --> 01:13:02,446
add two lists together.
1985
01:13:02,956 --> 01:13:04,246
we can also just add
1986
01:13:04,275 --> 01:13:06,495
individual elements onto a list
1987
01:13:06,525 --> 01:13:07,065
so
1988
01:13:07,305 --> 01:13:09,255
I come down here and I could say friends
1989
01:13:09,375 --> 01:13:10,005
dot
1990
01:13:10,275 --> 01:13:11,055
append
1991
01:13:11,475 --> 01:13:15,136
and this will actually allow me to append another item
1992
01:13:15,166 --> 01:13:16,665
onto the end of this list,
1993
01:13:16,965 --> 01:13:20,025
so over here I could just add another name so we could say
1994
01:13:20,206 --> 01:13:24,646
creed for example and now I'm like adding another friend onto the end of this list
1995
01:13:24,675 --> 01:13:25,995
so when I run the program.
1996
01:13:26,505 --> 01:13:27,915
in addition to having
1997
01:13:28,095 --> 01:13:30,854
the original items that were in the list up here.
1998
01:13:31,064 --> 01:13:33,465
we also have this additional item at the end
1999
01:13:33,675 --> 01:13:37,725
and not a pen function is always going to add the item onto the end of the list,
2000
01:13:38,265 --> 01:13:43,097
but let's say that you wanted to add an item into the middle of the list so like right here right here,
2001
01:13:43,396 --> 01:13:45,197
there's another list function
2002
01:13:45,227 --> 01:13:46,427
called insert
2003
01:13:47,897 --> 01:13:49,157
and insert is going to take
2004
01:13:49,187 --> 01:13:52,157
two parameters the first parameter is going to be the
2005
01:13:52,397 --> 01:13:54,646
index where you want to insert the item so
2006
01:13:54,856 --> 01:13:57,797
why don't we insert it here at index position one.
2007
01:13:58,067 --> 01:13:59,267
I'm just going to say one
2008
01:13:59,687 --> 01:14:03,077
and then I'm going to type in the name of the element that I want to add so
2009
01:14:03,107 --> 01:14:04,038
we can just say like
2010
01:14:04,278 --> 01:14:04,758
kelly,
2011
01:14:05,418 --> 01:14:08,088
and now at index position one we're going to have
2012
01:14:08,118 --> 01:14:09,288
the volume kelly
2013
01:14:09,378 --> 01:14:12,229
and all of these other values are going to get pushed
2014
01:14:12,258 --> 01:14:12,588
up
2015
01:14:12,618 --> 01:14:13,008
they're going to
2016
01:14:13,068 --> 01:14:14,418
get pushed to the right
2017
01:14:15,078 --> 01:14:16,938
one index position so
2018
01:14:16,998 --> 01:14:18,198
now I run the program,
2019
01:14:18,468 --> 01:14:19,968
you can see we have kavin
2020
01:14:20,028 --> 01:14:20,929
this new element
2021
01:14:20,958 --> 01:14:21,559
kelly
2022
01:14:21,799 --> 01:14:24,680
and then all the other elements have been pushed off to the right,
2023
01:14:24,770 --> 01:14:26,450
we can also remove elements
2024
01:14:26,479 --> 01:14:27,529
so for example
2025
01:14:27,559 --> 01:14:29,419
let's say I wanted to remove this
2026
01:14:29,449 --> 01:14:30,499
jim value.
2027
01:14:30,859 --> 01:14:33,589
all I have to do is just a friend's dot remove.
2028
01:14:34,040 --> 01:14:34,430
and
2029
01:14:34,459 --> 01:14:35,720
I can just typing
2030
01:14:35,750 --> 01:14:37,789
whatever element I want to remove so
2031
01:14:38,059 --> 01:14:38,869
I want to remove
2032
01:14:38,899 --> 01:14:40,159
this jim element
2033
01:14:40,429 --> 01:14:42,200
is a now when we run the program
2034
01:14:42,229 --> 01:14:42,680
jim
2035
01:14:42,709 --> 01:14:45,590
is going to be gone from the list and we just have these
2036
01:14:45,830 --> 01:14:47,240
four guys left.
2037
01:14:47,540 --> 01:14:48,500
you can also remove
2038
01:14:48,530 --> 01:14:49,520
all of the elements
2039
01:14:49,549 --> 01:14:51,559
from the list so if I just wanted to
2040
01:14:51,588 --> 01:14:52,578
completely like
2041
01:14:52,608 --> 01:14:54,078
reset the less than get rid of
2042
01:14:54,107 --> 01:14:56,507
everything I could just say friends thought clear.
2043
01:14:56,897 --> 01:14:57,798
and this is going to
2044
01:14:57,828 --> 01:15:00,288
give us an empty list so get rid of
2045
01:15:00,318 --> 01:15:02,448
every single element inside the list.
2046
01:15:02,538 --> 01:15:04,278
there's also another really cool
2047
01:15:04,308 --> 01:15:05,148
nothing which is called
2048
01:15:05,178 --> 01:15:05,748
pop
2049
01:15:05,808 --> 01:15:07,878
and you can just take out pop like that
2050
01:15:08,058 --> 01:15:10,128
and basically what pops is gonna do is it's going to
2051
01:15:10,158 --> 01:15:10,668
pop an
2052
01:15:10,698 --> 01:15:11,148
item
2053
01:15:11,178 --> 01:15:12,738
off of this list so
2054
01:15:13,008 --> 01:15:14,088
when I click the play button,
2055
01:15:14,328 --> 01:15:15,499
you'll see here that
2056
01:15:15,559 --> 01:15:16,729
we're left with
2057
01:15:16,849 --> 01:15:17,509
kevin
2058
01:15:17,569 --> 01:15:18,289
karen
2059
01:15:18,319 --> 01:15:19,909
jim and oscar so
2060
01:15:20,089 --> 01:15:24,498
we basically got rid of the last element inside the list and that's what pop does
2061
01:15:24,588 --> 01:15:25,848
it pops an element
2062
01:15:25,908 --> 01:15:29,718
off of the lists of easily removes the last element in the list.
2063
01:15:29,778 --> 01:15:30,828
so we have our list
2064
01:15:30,858 --> 01:15:32,868
but let's say that we wanted to figure out
2065
01:15:32,898 --> 01:15:33,228
if
2066
01:15:33,258 --> 01:15:35,448
a certain element was in this list
2067
01:15:35,568 --> 01:15:37,758
right if a certain value is in here so let's say
2068
01:15:37,878 --> 01:15:39,708
I wanted to check to see if
2069
01:15:39,769 --> 01:15:40,459
my friend
2070
01:15:40,489 --> 01:15:41,809
kevin was in this list.
2071
01:15:42,049 --> 01:15:43,489
why could say friends
2072
01:15:43,519 --> 01:15:44,239
dot
2073
01:15:44,359 --> 01:15:45,169
index
2074
01:15:45,379 --> 01:15:46,159
and in here
2075
01:15:46,189 --> 01:15:47,389
I can just pass
2076
01:15:47,629 --> 01:15:49,580
a value so I can say like
2077
01:15:50,120 --> 01:15:50,810
kevin.
2078
01:15:51,530 --> 01:15:53,391
and this is going to tell me the index
2079
01:15:53,690 --> 01:15:54,230
of
2080
01:15:54,291 --> 01:15:55,551
caverns are the tell me if
2081
01:15:55,581 --> 01:15:56,631
cabins in the list,
2082
01:15:56,872 --> 01:15:58,102
so I could play
2083
01:15:58,342 --> 01:15:59,632
you can see down here it says
2084
01:15:59,662 --> 01:16:00,322
zero
2085
01:16:00,532 --> 01:16:01,552
if I was to say like
2086
01:16:01,582 --> 01:16:03,142
oscar and here for example
2087
01:16:03,412 --> 01:16:04,731
now would give me the index
2088
01:16:04,761 --> 01:16:05,091
of
2089
01:16:05,151 --> 01:16:05,781
oscar.
2090
01:16:06,111 --> 01:16:07,372
so that's it three
2091
01:16:07,762 --> 01:16:10,643
but if I put a name that wasn't in here so like
2092
01:16:10,823 --> 01:16:11,843
if I put mike
2093
01:16:12,053 --> 01:16:13,223
doth not in the list.
2094
01:16:13,433 --> 01:16:14,843
and so now we're going to get back
2095
01:16:15,023 --> 01:16:15,653
an error
2096
01:16:15,683 --> 01:16:16,523
because it's as
2097
01:16:16,583 --> 01:16:18,293
mike is not in the list
2098
01:16:18,503 --> 01:16:22,463
so that's an easy ways you figure out if a specific element inside of the list.
2099
01:16:22,613 --> 01:16:23,513
and if it is,
2100
01:16:23,573 --> 01:16:25,522
then you know what index its app,
2101
01:16:25,583 --> 01:16:29,453
you can also count the number of similar elements in the list so
2102
01:16:29,723 --> 01:16:31,853
I'm actually going to come down here copy this
2103
01:16:31,883 --> 01:16:32,843
gem element
2104
01:16:33,113 --> 01:16:34,223
and will add another
2105
01:16:34,252 --> 01:16:35,573
jim element into here
2106
01:16:36,083 --> 01:16:38,453
so I could come down here and I could say friends
2107
01:16:38,482 --> 01:16:38,962
dot
2108
01:16:38,992 --> 01:16:39,532
count
2109
01:16:40,552 --> 01:16:41,062
and
2110
01:16:41,092 --> 01:16:42,022
will pass in
2111
01:16:42,052 --> 01:16:42,622
jim
2112
01:16:43,012 --> 01:16:45,231
and this will tell me how many times the value
2113
01:16:45,261 --> 01:16:45,831
jim
2114
01:16:45,920 --> 01:16:46,610
shows up
2115
01:16:46,640 --> 01:16:47,690
inside of this
2116
01:16:47,720 --> 01:16:48,350
list.
2117
01:16:48,680 --> 01:16:51,591
so it should say to which it does down there because
2118
01:16:51,801 --> 01:16:52,581
we have two
2119
01:16:52,610 --> 01:16:53,541
values with
2120
01:16:53,570 --> 01:16:54,170
the
2121
01:16:54,500 --> 01:16:55,010
text
2122
01:16:55,040 --> 01:16:55,610
jim
2123
01:16:55,820 --> 01:16:59,691
and so we have all these values we could also sort this list so
2124
01:16:59,751 --> 01:17:01,221
I could come over here and I could say
2125
01:17:01,551 --> 01:17:03,111
friends.sort()
2126
01:17:03,621 --> 01:17:06,081
and what this will do is it'll sort the list
2127
01:17:06,111 --> 01:17:06,621
in
2128
01:17:06,861 --> 01:17:08,181
ascending order so
2129
01:17:08,391 --> 01:17:09,441
we have a bunch of
2130
01:17:09,501 --> 01:17:11,121
text here and you'll see what it does.
2131
01:17:11,391 --> 01:17:14,841
basically what it's going to do is it's gonna put it in alphabetical order are so
2132
01:17:15,081 --> 01:17:16,822
you see we have j k
2133
01:17:16,882 --> 01:17:18,112
o and t so
2134
01:17:18,382 --> 01:17:23,663
the list went from being just random order like whatever we have up here to now it's in alphabetical order.
2135
01:17:23,873 --> 01:17:27,502
and that's also going to work for lucky numbers so I could say late
2136
01:17:28,192 --> 01:17:29,602
lucky numbers
2137
01:17:29,632 --> 01:17:30,292
dot
2138
01:17:30,382 --> 01:17:32,902
sort and then we'll turn out lucky numbers
2139
01:17:33,742 --> 01:17:36,353
and they should now be in ascending order,
2140
01:17:37,223 --> 01:17:39,623
which I'm realizing they already are up here but if I
2141
01:17:39,653 --> 01:17:41,483
was to take this forty two and
2142
01:17:42,713 --> 01:17:43,913
put it down here.
2143
01:17:45,203 --> 01:17:48,593
now it will figure everything out and put it in ascending order anyway.
2144
01:17:48,653 --> 01:17:49,853
we can also reverse
2145
01:17:49,883 --> 01:17:50,393
a list
2146
01:17:50,423 --> 01:17:52,553
so if I wanted I could reverse this not
2147
01:17:52,583 --> 01:17:54,173
lucky numbers list I could say
2148
01:17:54,203 --> 01:17:55,402
lucky numbers dot
2149
01:17:55,522 --> 01:17:56,302
reverse.
2150
01:17:56,512 --> 01:18:00,713
and now when we printed out instead of being forty to eight fifteen sixteen twenty three.
2151
01:18:00,893 --> 01:18:03,353
it's going to be twenty three sixteen fifteen eight forty two,
2152
01:18:04,223 --> 01:18:06,624
so it's basically just reverse the order of
2153
01:18:06,713 --> 01:18:07,313
the list.
2154
01:18:07,403 --> 01:18:09,204
and finally there's one more
2155
01:18:09,384 --> 01:18:09,534
or
2156
01:18:09,563 --> 01:18:11,874
less functional monetary eyes which is copy.
2157
01:18:12,144 --> 01:18:12,744
so
2158
01:18:12,774 --> 01:18:14,124
I can actually create
2159
01:18:14,184 --> 01:18:15,444
another list.
2160
01:18:15,714 --> 01:18:16,254
and I could
2161
01:18:16,284 --> 01:18:18,774
make it as a copy so I could say like
2162
01:18:19,884 --> 01:18:21,144
friends 2.
2163
01:18:21,354 --> 01:18:22,763
and we could set this equal to
2164
01:18:22,823 --> 01:18:23,603
friends
2165
01:18:23,633 --> 01:18:24,053
dot
2166
01:18:24,083 --> 01:18:24,743
copy
2167
01:18:25,343 --> 01:18:26,333
and now friends
2168
01:18:26,363 --> 01:18:28,042
too is going to have all the same
2169
01:18:28,103 --> 01:18:30,143
attributes as friends,
2170
01:18:30,982 --> 01:18:32,482
because it's basically just like
2171
01:18:32,572 --> 01:18:35,662
copy it basically took a copy of that friends list
2172
01:18:35,692 --> 01:18:36,142
so
2173
01:18:36,382 --> 01:18:37,792
you can see it's the same exact thing and
2174
01:18:37,972 --> 01:18:41,722
copying lists can come in handy in a lot of different situation so
2175
01:18:41,992 --> 01:18:44,812
those are just some basic list functions and just to kind of like
2176
01:18:45,052 --> 01:18:47,482
you know get your feet wet in working with lists
2177
01:18:47,512 --> 01:18:52,612
obviously like the more you work with them the more you practice using these different functions the more comfortable you're going to
2178
01:18:52,642 --> 01:18:53,032
get.
2179
01:18:53,182 --> 01:18:56,243
but that's just kind of like a basic overview of what you can do
2180
01:19:00,683 --> 01:19:01,643
in a sartorial
2181
01:19:01,672 --> 01:19:04,013
talk to you guys bought tuples in
2182
01:19:04,042 --> 01:19:04,822
python.
2183
01:19:05,212 --> 01:19:07,163
now a tupel is a type
2184
01:19:07,192 --> 01:19:07,552
of
2185
01:19:07,582 --> 01:19:08,602
data structure
2186
01:19:08,872 --> 01:19:10,942
which basically means it's a container
2187
01:19:11,242 --> 01:19:12,202
where we can store
2188
01:19:12,232 --> 01:19:13,612
different values.
2189
01:19:14,002 --> 01:19:16,102
now if you're familiar with lists
2190
01:19:16,132 --> 01:19:17,032
in python
2191
01:19:17,062 --> 01:19:20,302
a tupel is actually very similar to a list.
2192
01:19:20,662 --> 01:19:22,642
it's basically a structure where we can store
2193
01:19:22,672 --> 01:19:24,022
multiple pieces of
2194
01:19:24,052 --> 01:19:24,922
information,
2195
01:19:25,402 --> 01:19:25,852
but
2196
01:19:25,942 --> 01:19:29,212
a tupel has a few key differences from lists
2197
01:19:29,242 --> 01:19:30,382
that we're going to talk about
2198
01:19:30,622 --> 01:19:30,982
in
2199
01:19:31,012 --> 01:19:31,852
this tutorial.
2200
01:19:32,151 --> 01:19:34,582
first thing I want to do is I want to show you though how to
2201
01:19:34,612 --> 01:19:35,751
create a tupel.
2202
01:19:36,142 --> 01:19:38,872
so I can come down here and I can create a tupel
2203
01:19:39,112 --> 01:19:39,953
and one of the most
2204
01:19:40,792 --> 01:19:41,302
common
2205
01:19:41,332 --> 01:19:43,912
examples of tupels his coordinates.
2206
01:19:44,122 --> 01:19:47,962
so let's say I had a series of like x y coordinates I could create a variable
2207
01:19:49,282 --> 01:19:50,362
called coordinates
2208
01:19:50,422 --> 01:19:51,532
and I'm gonna set this
2209
01:19:51,562 --> 01:19:52,492
equal to
2210
01:19:52,732 --> 01:19:52,942
an
2211
01:19:52,972 --> 01:19:54,952
open and close parentheses,
2212
01:19:55,252 --> 01:19:57,682
and whenever we want to create a tupel inside of
2213
01:19:57,742 --> 01:19:59,422
python we're going to use these
2214
01:19:59,452 --> 01:20:00,921
open closed parentheses
2215
01:20:01,251 --> 01:20:01,492
and
2216
01:20:01,552 --> 01:20:06,051
inside of here inside these proceeds we're gonna put the values that we want to store
2217
01:20:06,381 --> 01:20:08,812
so I could for example put a list
2218
01:20:08,842 --> 01:20:09,202
of
2219
01:20:09,262 --> 01:20:09,922
numbers,
2220
01:20:10,222 --> 01:20:10,552
so
2221
01:20:10,582 --> 01:20:14,272
this could be like my coordinates I could have like four and five.
2222
01:20:14,572 --> 01:20:17,841
so this would be my tuple with coordinates
2223
01:20:17,871 --> 01:20:18,561
inside of it.
2224
01:20:19,011 --> 01:20:21,832
and one of the things about tuples that makes them unique
2225
01:20:21,861 --> 01:20:23,031
is a tuple is
2226
01:20:23,271 --> 01:20:24,082
immutable,
2227
01:20:24,532 --> 01:20:26,932
and you'll hear that word a lot when we're talking about tuples
2228
01:20:26,992 --> 01:20:28,912
immutable it basically means that
2229
01:20:29,001 --> 01:20:31,432
the tuple can't be changed or modified.
2230
01:20:31,702 --> 01:20:34,132
once we create our tuple up here.
2231
01:20:34,372 --> 01:20:35,872
you cannot modify it
2232
01:20:35,901 --> 01:20:37,371
cannot change it you can't
2233
01:20:37,431 --> 01:20:38,961
add elements to it you can't
2234
01:20:39,351 --> 01:20:41,092
erase elements from it you can't
2235
01:20:41,122 --> 01:20:43,492
change any of the elements inside the tuple.
2236
01:20:43,822 --> 01:20:47,092
what you see is what you get once you create the tuple its
2237
01:20:47,242 --> 01:20:48,652
it does it as it can't change
2238
01:20:48,892 --> 01:20:50,932
so I can come down here and I can
2239
01:20:51,082 --> 01:20:51,952
print out
2240
01:20:52,162 --> 01:20:53,362
some of the
2241
01:20:54,292 --> 01:20:55,792
attributes inside the tuple.
2242
01:20:56,122 --> 01:20:57,861
and the way I can access them
2243
01:20:57,891 --> 01:20:58,641
is
2244
01:20:58,671 --> 01:20:59,601
just by using an
2245
01:20:59,631 --> 01:21:01,491
open and closed square bracket.
2246
01:21:01,731 --> 01:21:03,681
and in here I can pass in
2247
01:21:03,711 --> 01:21:04,131
a
2248
01:21:04,161 --> 01:21:04,821
index
2249
01:21:05,091 --> 01:21:06,411
so troubles are indexed
2250
01:21:06,441 --> 01:21:09,532
starting at zero so technically we would say that four
2251
01:21:09,862 --> 01:21:11,392
is at index position one
2252
01:21:11,452 --> 01:21:12,142
and for --
2253
01:21:12,231 --> 01:21:12,682
sorry
2254
01:21:13,551 --> 01:21:15,231
it is in position zero
2255
01:21:15,291 --> 01:21:16,161
and five of them
2256
01:21:16,191 --> 01:21:18,021
is at index position one, so if I said
2257
01:21:18,051 --> 01:21:19,190
coordinate zero
2258
01:21:19,250 --> 01:21:21,620
now it should print out four
2259
01:21:23,090 --> 01:21:25,340
and down here we're printing out four.
2260
01:21:25,730 --> 01:21:29,960
so if I wanted to print out that five we can just put a one inside of those square brackets
2261
01:21:30,470 --> 01:21:33,080
and now we'll print out that five so I can access
2262
01:21:33,109 --> 01:21:34,160
the elements
2263
01:21:34,580 --> 01:21:35,390
inside of
2264
01:21:35,419 --> 01:21:36,169
a tuple I can
2265
01:21:36,199 --> 01:21:37,549
easily access is at
2266
01:21:37,579 --> 01:21:37,819
each
2267
01:21:37,849 --> 01:21:38,389
entry.
2268
01:21:38,749 --> 01:21:39,139
but
2269
01:21:39,169 --> 01:21:42,020
if I was to come over here and try to change
2270
01:21:42,170 --> 01:21:44,720
one of the elements so if I said coordinates
2271
01:21:45,110 --> 01:21:45,740
and
2272
01:21:45,860 --> 01:21:49,040
coordinate one and I tried to set it equal to something else like
2273
01:21:49,430 --> 01:21:50,090
ten
2274
01:21:50,780 --> 01:21:52,700
python's actually going to give us an
2275
01:21:52,729 --> 01:21:55,219
error when we run this programs often run the program.
2276
01:21:55,429 --> 01:21:57,229
you see we get this error it says
2277
01:21:57,739 --> 01:21:58,129
type
2278
01:21:58,159 --> 01:21:58,668
air
2279
01:21:58,698 --> 01:21:59,928
tuple object
2280
01:21:59,958 --> 01:22:01,128
does not support
2281
01:22:01,218 --> 01:22:01,668
item
2282
01:22:01,698 --> 01:22:02,418
assignment
2283
01:22:02,688 --> 01:22:04,068
because it's immutable
2284
01:22:04,098 --> 01:22:06,438
because we can't change it so
2285
01:22:07,038 --> 01:22:09,168
that's basically what tuples are
2286
01:22:09,198 --> 01:22:10,608
how we can create them
2287
01:22:10,638 --> 01:22:11,298
and
2288
01:22:11,538 --> 01:22:14,658
you know a couple like I said it's very simple you just created and then you have,
2289
01:22:15,048 --> 01:22:15,498
um.
2290
01:22:15,978 --> 01:22:20,868
and now I want to talk to you guys about a common topic in python which is the difference between
2291
01:22:21,108 --> 01:22:21,798
tuples
2292
01:22:21,828 --> 01:22:23,148
and lists.
2293
01:22:23,358 --> 01:22:23,748
so
2294
01:22:23,778 --> 01:22:26,178
remember a list is basically doing the same thing
2295
01:22:26,208 --> 01:22:26,838
a list.
2296
01:22:27,018 --> 01:22:30,739
if one is to create a less we would just use square brackets instead of those parentheses.
2297
01:22:31,189 --> 01:22:32,930
and if I was using a list
2298
01:22:32,959 --> 01:22:33,560
I could
2299
01:22:33,709 --> 01:22:35,810
assign different values to it I could,
2300
01:22:35,930 --> 01:22:36,950
I could basically
2301
01:22:37,459 --> 01:22:40,040
mutate any of the elements I could add delete
2302
01:22:40,760 --> 01:22:43,430
modify change whatever I wanted with the list,
2303
01:22:43,580 --> 01:22:44,810
but with a tuple.
2304
01:22:44,930 --> 01:22:46,669
we can't do that and that's
2305
01:22:46,759 --> 01:22:48,350
sort of the basic difference and
2306
01:22:48,709 --> 01:22:49,640
really python
2307
01:22:49,669 --> 01:22:54,471
doesn't say anything more than that it basically just says like one of them's immutable one of them's not
2308
01:22:54,801 --> 01:22:55,311
but
2309
01:22:55,551 --> 01:23:01,851
in practical use cases generally people will use tuples for data that's never going to change
2310
01:23:02,210 --> 01:23:04,940
so you'll steal stored dna inside of a tuple
2311
01:23:05,121 --> 01:23:07,070
when that data doesn't need to be
2312
01:23:07,130 --> 01:23:09,561
mutated that's why something like coordinates
2313
01:23:09,860 --> 01:23:12,230
is such a good candidate for a couple because
2314
01:23:12,530 --> 01:23:13,880
once you have coordinates like
2315
01:23:13,910 --> 01:23:16,220
we're probably not going to modify them right,
2316
01:23:16,280 --> 01:23:17,150
we might add
2317
01:23:17,180 --> 01:23:18,200
other coordinates.
2318
01:23:18,410 --> 01:23:21,740
so for example if I wanted I could create a list of tunnels.
2319
01:23:21,920 --> 01:23:22,671
so I can say like
2320
01:23:22,731 --> 01:23:23,721
four five
2321
01:23:24,861 --> 01:23:26,061
six seven,
2322
01:23:26,751 --> 01:23:28,431
maybe we have some other coordinates like
2323
01:23:28,521 --> 01:23:29,331
eighty
2324
01:23:29,721 --> 01:23:30,801
thirty four.
2325
01:23:31,221 --> 01:23:32,631
so here I have in uh
2326
01:23:32,661 --> 01:23:33,531
I have a list
2327
01:23:33,591 --> 01:23:35,091
and inside of it we have these
2328
01:23:35,121 --> 01:23:35,781
tunnels.
2329
01:23:36,921 --> 01:23:41,151
but remember these topples can't be modified the values can't be changed so
2330
01:23:41,511 --> 01:23:43,401
really it's just a case by case basis
2331
01:23:43,431 --> 01:23:44,181
I would say
2332
01:23:44,361 --> 01:23:45,921
by a huge majority.
2333
01:23:46,101 --> 01:23:48,231
you're going to be using lists most of the time.
2334
01:23:48,951 --> 01:23:50,991
topples or more of a niche
2335
01:23:51,051 --> 01:23:51,411
you know
2336
01:23:51,440 --> 01:23:53,811
they're using more special situations.
2337
01:23:54,411 --> 01:23:54,831
but
2338
01:23:54,951 --> 01:24:01,400
there are plenty of situations where you want to use tuples so if you're in a situation where you want to store data that can't be changed or mutated
2339
01:24:02,570 --> 01:24:04,041
then tuples are the way to go
2340
01:24:04,101 --> 01:24:08,121
to <...> some basics about tuples some basics about the difference between
2341
01:24:08,301 --> 01:24:09,651
lists and tuples
2342
01:24:09,831 --> 01:24:12,261
and so a tuple is a great thing to add in c or
2343
01:24:12,291 --> 01:24:13,161
python
2344
01:24:13,190 --> 01:24:14,090
repertoire
2345
01:24:18,800 --> 01:24:21,170
in this tutorial I wanna talk to you guys are by using
2346
01:24:21,200 --> 01:24:23,120
functions in python.
2347
01:24:23,660 --> 01:24:25,249
a function is basically just
2348
01:24:25,279 --> 01:24:27,019
a collection of code,
2349
01:24:27,318 --> 01:24:29,599
which performs a specific task
2350
01:24:29,628 --> 01:24:30,588
so I can take
2351
01:24:30,829 --> 01:24:33,949
a bunch of lines of code that are basically doing one thing
2352
01:24:34,189 --> 01:24:35,750
I could put them inside of a function.
2353
01:24:35,990 --> 01:24:37,549
and then when I wanted to
2354
01:24:37,579 --> 01:24:41,479
do that task or do that one thing that the function was doing,
2355
01:24:41,719 --> 01:24:43,819
I can just call the function
2356
01:24:44,270 --> 01:24:48,770
and so functions really help you to organize your code a lot better they allow you to kind of
2357
01:24:48,800 --> 01:24:50,690
break up your code into different
2358
01:24:50,990 --> 01:24:53,570
you know little chunks that are doing different things and
2359
01:24:53,840 --> 01:24:56,900
they're really just awesome so functions are like a very core
2360
01:24:56,930 --> 01:24:59,960
concept when we're talking about programming in python,
2361
01:25:00,290 --> 01:25:02,601
so i'll show how to create an awesome
2362
01:25:02,630 --> 01:25:03,710
function today
2363
01:25:04,101 --> 01:25:07,611
let's say for the purposes of this tutorial we want to create a function
2364
01:25:07,791 --> 01:25:09,921
that says "hi" to the user so
2365
01:25:10,281 --> 01:25:14,421
the one task that our function performs as basically just saying hi to
2366
01:25:14,631 --> 01:25:16,371
whoever is writing the program so
2367
01:25:16,761 --> 01:25:17,391
over here,
2368
01:25:18,111 --> 01:25:20,872
if I want to write a function the first thing I have to use
2369
01:25:20,901 --> 01:25:24,082
is a keyword in python it's called "def" of
2370
01:25:24,112 --> 01:25:25,102
d e f
2371
01:25:25,612 --> 01:25:26,092
and
2372
01:25:26,122 --> 01:25:27,232
basically when
2373
01:25:27,262 --> 01:25:29,752
python sees this keyword it's going to say
2374
01:25:29,812 --> 01:25:30,442
okay
2375
01:25:30,562 --> 01:25:33,352
this person wants to use a function.
2376
01:25:33,802 --> 01:25:35,603
so after we type out "def"
2377
01:25:35,632 --> 01:25:37,282
we need to give this function
2378
01:25:37,312 --> 01:25:37,912
a name,
2379
01:25:38,362 --> 01:25:39,623
so just like when we
2380
01:25:39,652 --> 01:25:40,132
are
2381
01:25:40,162 --> 01:25:43,282
creating variables we give them descriptive names.
2382
01:25:43,462 --> 01:25:46,942
we also want to do the same thing with functions.
2383
01:25:47,182 --> 01:25:52,672
so if I'm creating a function I can just give it a specific name which basically says like what it's doing so
2384
01:25:52,912 --> 01:25:55,882
we're going to create a function that says hi so I'm just gonna
2385
01:25:55,912 --> 01:25:56,842
call this function,
2386
01:25:57,352 --> 01:25:58,162
say hi,
2387
01:25:58,282 --> 01:25:59,062
just like that.
2388
01:25:59,603 --> 01:26:00,172
and
2389
01:26:00,232 --> 01:26:02,183
once we type out the name of the function
2390
01:26:02,212 --> 01:26:05,303
and so also I could type out say high with no
2391
01:26:05,633 --> 01:26:08,783
underscore or I could type out say high with an underscore.
2392
01:26:09,143 --> 01:26:10,673
both are considered like
2393
01:26:10,733 --> 01:26:13,194
good practices and python and a lot of times
2394
01:26:13,344 --> 01:26:14,813
if you just have a simple like
2395
01:26:14,874 --> 01:26:16,553
two word function like this
2396
01:26:16,583 --> 01:26:19,224
you don't need to put an underscore but we can put an underscore there
2397
01:26:19,764 --> 01:26:20,424
if we wanted.
2398
01:26:20,694 --> 01:26:22,314
after we type out the name of the function
2399
01:26:22,344 --> 01:26:24,685
I'm just going to type into open and closed parentheses.
2400
01:26:25,194 --> 01:26:25,584
and
2401
01:26:25,614 --> 01:26:26,334
then I'm going to type
2402
01:26:26,364 --> 01:26:27,294
a colon
2403
01:26:27,685 --> 01:26:31,015
and basically what this is doing is it saying to python lake
2404
01:26:31,345 --> 01:26:31,675
or eye
2405
01:26:31,705 --> 01:26:34,615
all the code that comes after this line
2406
01:26:34,825 --> 01:26:35,665
is going to be
2407
01:26:35,695 --> 01:26:37,135
inside of our function.
2408
01:26:37,555 --> 01:26:39,234
and in order to
2409
01:26:39,294 --> 01:26:43,496
write code that's going to end up being inside the function we actually have to
2410
01:26:43,556 --> 01:26:44,876
indent it sold
2411
01:26:45,236 --> 01:26:45,926
over here.
2412
01:26:46,166 --> 01:26:48,295
you'll notice that when I clicked enter my
2413
01:26:48,325 --> 01:26:50,065
text editor automatically
2414
01:26:50,125 --> 01:26:52,616
indented attacks so it's automatically like
2415
01:26:53,306 --> 01:26:54,836
using this indent here
2416
01:26:55,196 --> 01:26:55,646
and that
2417
01:26:55,676 --> 01:26:57,806
having one of the rules and python is like
2418
01:26:58,436 --> 01:27:00,986
the code that goes inside of this function
2419
01:27:01,016 --> 01:27:02,695
needs to be indented.
2420
01:27:02,905 --> 01:27:04,646
so if I was to write some code
2421
01:27:04,766 --> 01:27:05,696
like out here,
2422
01:27:05,906 --> 01:27:09,446
this is no longer going to be considered inside the function so you can see
2423
01:27:09,746 --> 01:27:11,756
as I type out code and obviously this isn't
2424
01:27:11,786 --> 01:27:12,656
real code but
2425
01:27:12,866 --> 01:27:14,606
as I type text over here that's
2426
01:27:14,636 --> 01:27:15,326
invented
2427
01:27:15,536 --> 01:27:17,786
this little like marker over here
2428
01:27:18,026 --> 01:27:19,196
is basically saying like
2429
01:27:19,286 --> 01:27:19,646
oh yeah
2430
01:27:19,676 --> 01:27:20,905
that's inside the function.
2431
01:27:21,265 --> 01:27:22,735
but then when I write code
2432
01:27:22,765 --> 01:27:24,085
over here that is like
2433
01:27:24,115 --> 01:27:25,285
not at the same
2434
01:27:25,375 --> 01:27:27,145
indentation level as this stuff.
2435
01:27:27,325 --> 01:27:30,295
it's no longer considering it inside the function so
2436
01:27:30,745 --> 01:27:34,436
that is a little thing any code inside this function needs to be indented
2437
01:27:35,096 --> 01:27:39,537
right so our function is just going to say hi to the user so I'm going to have it
2438
01:27:39,567 --> 01:27:40,407
print out
2439
01:27:42,567 --> 01:27:43,887
some text it's going to say
2440
01:27:43,917 --> 01:27:44,577
hello.
2441
01:27:44,727 --> 01:27:45,357
user.
2442
01:27:45,447 --> 01:27:49,587
so this is a very simple function obviously we just have one line of code and
2443
01:27:49,797 --> 01:27:51,057
inside of a function you could have
2444
01:27:51,087 --> 01:27:53,007
you know as many lines of code as you want but
2445
01:27:53,247 --> 01:27:57,268
for our purposes we only need one line in order to perform our function.
2446
01:27:57,598 --> 01:27:58,167
so
2447
01:27:58,197 --> 01:27:59,638
now all we have to do is
2448
01:27:59,667 --> 01:28:01,318
call this function so
2449
01:28:01,408 --> 01:28:05,487
if I want to execute the code inside of this function I have to do something
2450
01:28:05,607 --> 01:28:05,998
called
2451
01:28:06,027 --> 01:28:07,107
calling it so
2452
01:28:07,498 --> 01:28:10,407
if I was to just run my program as it is right now,
2453
01:28:10,527 --> 01:28:11,428
I'm just gonna run it,
2454
01:28:12,088 --> 01:28:14,398
you'll see that nothing happens over here
2455
01:28:14,458 --> 01:28:14,878
right ?
2456
01:28:15,658 --> 01:28:16,858
even though this function is
2457
01:28:16,888 --> 01:28:19,528
printing out hello user when I run the program
2458
01:28:19,558 --> 01:28:20,698
it's not doing it,
2459
01:28:21,088 --> 01:28:23,278
and that's because of the code inside of a function
2460
01:28:23,308 --> 01:28:24,958
isn't going to get executed
2461
01:28:24,988 --> 01:28:26,008
by default.
2462
01:28:26,788 --> 01:28:32,127
the code inside of a function is only going to get executed when we specify that we want to execute it.
2463
01:28:32,458 --> 01:28:37,377
and in order to do that we're going to have to do something called calling the function so in order to call a function,
2464
01:28:37,947 --> 01:28:41,608
you basically just type out the functions name and those open a close parentheses.
2465
01:28:41,968 --> 01:28:43,139
so I'm just gonna type out
2466
01:28:43,168 --> 01:28:44,278
say hi
2467
01:28:44,428 --> 01:28:44,698
and
2468
01:28:44,728 --> 01:28:46,048
opening close parentheses.
2469
01:28:46,348 --> 01:28:46,678
and
2470
01:28:46,708 --> 01:28:47,877
now when we are,
2471
01:28:48,117 --> 01:28:49,647
when we run this program again,
2472
01:28:50,098 --> 01:28:50,998
you'll see that
2473
01:28:51,088 --> 01:28:51,718
it prints out
2474
01:28:51,748 --> 01:28:54,237
hello user so were executing the code
2475
01:28:54,267 --> 01:28:55,437
inside of the function.
2476
01:28:56,097 --> 01:28:58,557
and I want to show you guys just one more thing here
2477
01:28:58,767 --> 01:29:02,158
just talking to you guys about how these functions actively work so
2478
01:29:02,638 --> 01:29:04,289
up here I'm going to print top
2479
01:29:04,708 --> 01:29:05,758
and then down here
2480
01:29:05,788 --> 01:29:06,658
I'm going to print
2481
01:29:07,588 --> 01:29:08,128
bottom.
2482
01:29:08,398 --> 01:29:10,528
so I wanna show you guys the flow of
2483
01:29:10,558 --> 01:29:12,927
these functions inside the program so when I
2484
01:29:12,987 --> 01:29:13,917
run this program
2485
01:29:14,547 --> 01:29:15,237
you'll see
2486
01:29:15,267 --> 01:29:16,737
we print out top
2487
01:29:17,067 --> 01:29:18,208
hello user
2488
01:29:18,507 --> 01:29:19,468
and then bada.
2489
01:29:19,708 --> 01:29:21,418
so essentially what's happening is
2490
01:29:21,479 --> 01:29:22,889
when python goes through and
2491
01:29:22,918 --> 01:29:24,088
executes this
2492
01:29:24,269 --> 01:29:24,869
program,
2493
01:29:25,289 --> 01:29:27,149
it goes over here to this first line it says
2494
01:29:27,179 --> 01:29:27,688
ok
2495
01:29:28,258 --> 01:29:30,389
we want to print out the word top
2496
01:29:30,569 --> 01:29:32,039
and then it goes down here and it says
2497
01:29:32,129 --> 01:29:34,919
ok we want to execute the say high function
2498
01:29:35,279 --> 01:29:37,019
so python actually jumps
2499
01:29:37,049 --> 01:29:37,469
up
2500
01:29:37,739 --> 01:29:40,169
and it goes over this say high function,
2501
01:29:40,289 --> 01:29:41,429
and it's going to execute
2502
01:29:41,459 --> 01:29:42,599
all of the code
2503
01:29:42,659 --> 01:29:44,759
inside of this function so
2504
01:29:45,029 --> 01:29:47,009
it's going to go through execute all this code.
2505
01:29:47,159 --> 01:29:50,309
and then once it's done executing all the code and the function,
2506
01:29:50,519 --> 01:29:51,659
it's going to jump back
2507
01:29:51,688 --> 01:29:57,300
down here and it's going to move onto the next line which is bottom so that's how like the flow of functions,
2508
01:29:57,450 --> 01:29:59,729
again with functions generally when we're
2509
01:29:59,759 --> 01:30:01,169
naming these functions
2510
01:30:01,589 --> 01:30:02,039
and
2511
01:30:02,159 --> 01:30:03,419
you want them to be named
2512
01:30:03,509 --> 01:30:04,890
in all lower case,
2513
01:30:05,130 --> 01:30:05,640
and
2514
01:30:05,700 --> 01:30:07,890
usually when we're naming stuff in python
2515
01:30:07,920 --> 01:30:10,290
if there's two or more words we're going to use an
2516
01:30:10,320 --> 01:30:11,280
under space
2517
01:30:11,460 --> 01:30:13,110
or an underscore in between them.
2518
01:30:13,320 --> 01:30:16,170
so I can write this out as say under score high.
2519
01:30:16,561 --> 01:30:17,041
but
2520
01:30:17,130 --> 01:30:21,181
in a lot of situations though if I have a function like this where the name is really short
2521
01:30:21,421 --> 01:30:22,982
and might just be easier to leave it
2522
01:30:23,012 --> 01:30:24,062
without an underscore but
2523
01:30:24,091 --> 01:30:26,311
why we've spent on scoring now just to be a
2524
01:30:27,121 --> 01:30:28,771
super python official.
2525
01:30:29,581 --> 01:30:30,421
all right so now
2526
01:30:30,571 --> 01:30:37,262
we can actually make these functions a little bit more powerful and what we can do is we can give them information.
2527
01:30:37,592 --> 01:30:42,511
so a lot of times when we write a function we're going to want to have additional information that gets
2528
01:30:42,541 --> 01:30:43,411
passed in.
2529
01:30:43,861 --> 01:30:45,691
and these are called parameters
2530
01:30:45,721 --> 01:30:48,480
so a parameter is a piece of information
2531
01:30:48,720 --> 01:30:50,070
that we give to
2532
01:30:50,100 --> 01:30:50,910
the function,
2533
01:30:51,420 --> 01:30:52,020
so
2534
01:30:52,080 --> 01:30:58,260
over here I can actually specify that this function needs to receive some parameters so I can basically say like
2535
01:30:58,560 --> 01:31:00,450
hey if you're gonna call this function,
2536
01:31:00,630 --> 01:31:02,280
you need to give us some information,
2537
01:31:02,460 --> 01:31:03,781
you need to give us some parameters
2538
01:31:04,261 --> 01:31:10,801
and all I have to do to do that has just type out the name of the parameter that I want to receive so why don't we allow the
2539
01:31:12,031 --> 01:31:15,481
code calling this function to tell it what name to say hi to
2540
01:31:15,901 --> 01:31:17,611
up here I can just say name
2541
01:31:18,241 --> 01:31:22,501
and basically what this means is it means whenever I call this say high function
2542
01:31:22,651 --> 01:31:24,361
we have to give it a name.
2543
01:31:24,721 --> 01:31:26,551
so down here if I was to call this
2544
01:31:26,581 --> 01:31:29,521
I have to include a name in here so I can say like
2545
01:31:30,242 --> 01:31:30,782
mike.
2546
01:31:30,872 --> 01:31:35,701
and what we can do now is we can actually access this parameter or this variable
2547
01:31:36,151 --> 01:31:37,501
inside of our
2548
01:31:37,531 --> 01:31:40,771
function so I could come over here and instead of saying hello user.
2549
01:31:41,071 --> 01:31:42,451
I could say hello
2550
01:31:42,571 --> 01:31:43,201
name
2551
01:31:43,591 --> 01:31:48,992
and basically what this is gonna do is it's just going to say hello to whatever name got passed in here
2552
01:31:49,502 --> 01:31:51,272
so I'm actually gonna copy this
2553
01:31:51,302 --> 01:31:51,812
and
2554
01:31:51,872 --> 01:31:52,622
we will
2555
01:31:53,102 --> 01:31:55,712
do this twice also hello my kilo
2556
01:31:55,742 --> 01:31:56,612
steve
2557
01:31:57,662 --> 01:31:59,731
and now when I run this program
2558
01:31:59,972 --> 01:32:01,082
you'll see that
2559
01:32:01,292 --> 01:32:02,102
instead of just saying
2560
01:32:02,132 --> 01:32:03,152
hello user
2561
01:32:03,272 --> 01:32:05,583
it saying hello to whichever name
2562
01:32:05,612 --> 01:32:07,232
I passed in to the function.
2563
01:32:07,532 --> 01:32:09,842
so that's why this can be really useful right we can
2564
01:32:10,022 --> 01:32:11,643
give the function information
2565
01:32:12,002 --> 01:32:13,833
and depending on the information we give it
2566
01:32:13,922 --> 01:32:15,123
it'll performance task
2567
01:32:15,152 --> 01:32:16,292
a little bit differently.
2568
01:32:16,743 --> 01:32:17,612
I could also
2569
01:32:18,092 --> 01:32:20,192
include more than one parameter so you can I mean
2570
01:32:20,432 --> 01:32:23,013
technically you could have as many parameters as you want
2571
01:32:23,103 --> 01:32:24,692
so I can put another one in here would say
2572
01:32:24,722 --> 01:32:25,322
age.
2573
01:32:25,622 --> 01:32:27,332
and now I'm going to have to pass in an
2574
01:32:27,362 --> 01:32:27,962
age
2575
01:32:27,992 --> 01:32:28,952
along with these,
2576
01:32:29,252 --> 01:32:30,752
so I'm just going to pass in
2577
01:32:30,782 --> 01:32:31,592
age
2578
01:32:31,712 --> 01:32:32,433
and
2579
01:32:32,613 --> 01:32:34,293
passing an age for down here,
2580
01:32:35,733 --> 01:32:36,963
and I'm just going to pass in
2581
01:32:36,993 --> 01:32:37,863
strings,
2582
01:32:39,003 --> 01:32:40,864
so we can say hello name
2583
01:32:43,414 --> 01:32:44,434
you are
2584
01:32:45,574 --> 01:32:46,114
age
2585
01:32:46,384 --> 01:32:48,785
so I'm passing in two pieces of information.
2586
01:32:49,055 --> 01:32:52,055
now when we run this program is going to call the function,
2587
01:32:52,625 --> 01:32:55,625
and it's going to use both of those pieces of information so it's a healthy
2588
01:32:55,654 --> 01:32:58,654
like you are thirty five hello steve you are seventy.
2589
01:32:59,104 --> 01:32:59,644
so
2590
01:32:59,854 --> 01:33:00,724
essentially you
2591
01:33:00,784 --> 01:33:06,004
were writing out this one line of code which just prints out like hello to someone
2592
01:33:06,394 --> 01:33:08,824
and were allowing this function to receive
2593
01:33:08,854 --> 01:33:11,554
two parameter so the name in the age
2594
01:33:11,854 --> 01:33:13,444
and depending on the name in the age,
2595
01:33:13,594 --> 01:33:15,003
the function is going to print out
2596
01:33:15,033 --> 01:33:16,503
hello a little bit
2597
01:33:16,533 --> 01:33:17,193
differently.
2598
01:33:17,434 --> 01:33:20,134
that's kind of the beauty of using function so
2599
01:33:20,404 --> 01:33:23,434
you could pass anything you want into a function so for example,
2600
01:33:23,733 --> 01:33:25,144
I could pass in a
2601
01:33:25,204 --> 01:33:25,894
integer.
2602
01:33:25,954 --> 01:33:27,814
instead of a string for the age.
2603
01:33:28,324 --> 01:33:29,764
so like I could pass in a number.
2604
01:33:30,004 --> 01:33:32,435
the only differences over here we're going to have to
2605
01:33:32,495 --> 01:33:34,115
convert this into a string,
2606
01:33:34,835 --> 01:33:35,856
but it's going to work.
2607
01:33:35,946 --> 01:33:36,816
just the same,
2608
01:33:37,686 --> 01:33:39,036
so you can pass in alm
2609
01:33:39,966 --> 01:33:40,687
strings
2610
01:33:40,716 --> 01:33:41,946
numbers bullion's
2611
01:33:41,976 --> 01:33:43,356
arrays you can really pass
2612
01:33:43,716 --> 01:33:45,065
any type of data
2613
01:33:45,095 --> 01:33:46,145
into a
2614
01:33:46,235 --> 01:33:47,585
function and it's going to work
2615
01:33:47,615 --> 01:33:48,035
so
2616
01:33:48,155 --> 01:33:49,865
you can see here we get the same result.
2617
01:33:50,285 --> 01:33:53,165
so that's the basics of functions and as you go through on
2618
01:33:53,225 --> 01:33:54,815
with python you're gonna you know
2619
01:33:54,845 --> 01:33:56,495
being functions more and more,
2620
01:33:56,765 --> 01:34:03,515
and generally it's a good idea to break your code up into different functions so whenever you have like a grouping of code
2621
01:34:03,785 --> 01:34:04,175
that's
2622
01:34:04,205 --> 01:34:06,514
designed to perform a specific task.
2623
01:34:06,814 --> 01:34:10,353
that's usually a good candidate to be put inside of a function
2624
01:34:14,193 --> 01:34:18,994
in this tutorial I wanna talk to you guys about using the return statement in python,
2625
01:34:19,054 --> 01:34:19,744
functions
2626
01:34:20,284 --> 01:34:22,234
and other python function is basically just
2627
01:34:22,264 --> 01:34:23,434
a collection
2628
01:34:23,463 --> 01:34:26,913
of python code that performs a specific task.
2629
01:34:27,333 --> 01:34:31,894
and when we want to perform that task in our python programs we can call
2630
01:34:32,134 --> 01:34:33,364
a python function
2631
01:34:33,844 --> 01:34:40,145
and a lot of times when we're calling a python function we just gonna call it and it does its thing and then we move on with the program.
2632
01:34:40,535 --> 01:34:44,375
but sometimes when we call a function we're actually going to want to get
2633
01:34:44,405 --> 01:34:45,455
information
2634
01:34:45,484 --> 01:34:46,024
back
2635
01:34:46,054 --> 01:34:47,165
from that function.
2636
01:34:47,555 --> 01:34:50,255
so when I call the function I want to basically
2637
01:34:50,285 --> 01:34:52,805
executes task I wanted to execute all the code
2638
01:34:53,165 --> 01:34:54,125
and then I wanted to like
2639
01:34:54,155 --> 01:34:55,745
give me some information back
2640
01:34:55,775 --> 01:34:57,905
so that can be like a particular value.
2641
01:34:58,205 --> 01:35:00,785
it could be something like telling me how the task went
2642
01:35:01,055 --> 01:35:01,745
basically
2643
01:35:01,805 --> 01:35:02,075
the
2644
01:35:02,105 --> 01:35:04,595
function can just communicate back to us like hey,
2645
01:35:04,775 --> 01:35:05,945
here's some information.
2646
01:35:06,305 --> 01:35:09,305
and that's what the return keyword can allow us to do
2647
01:35:09,695 --> 01:35:11,766
the return keyword can basically allow
2648
01:35:11,795 --> 01:35:14,675
python two return information from
2649
01:35:14,765 --> 01:35:15,365
a function.
2650
01:35:15,965 --> 01:35:17,375
so I'm gonna show you guys how we can
2651
01:35:17,405 --> 01:35:20,464
do this I want to create a very simple function.
2652
01:35:20,794 --> 01:35:22,174
and it's just going to
2653
01:35:22,204 --> 01:35:28,654
cube a number so when we cuba number we take it to the power of three so if I was going to cuba like to
2654
01:35:28,984 --> 01:35:29,375
be like
2655
01:35:29,404 --> 01:35:31,564
two raised to the power of three
2656
01:35:31,894 --> 01:35:32,494
right it's just
2657
01:35:32,523 --> 01:35:33,693
pretty basic math.
2658
01:35:34,144 --> 01:35:36,813
so we're gonna make a function that will cuban number
2659
01:35:36,843 --> 01:35:39,543
and I'll show you guys how we can use that return statement
2660
01:35:39,573 --> 01:35:39,993
so
2661
01:35:40,323 --> 01:35:42,363
first thing we want to do is make a function.
2662
01:35:42,453 --> 01:35:43,323
I'm just going to say
2663
01:35:43,353 --> 01:35:43,923
death
2664
01:35:44,253 --> 01:35:44,883
q,
2665
01:35:44,943 --> 01:35:45,603
we'll call the country
2666
01:35:45,633 --> 01:35:46,623
the function cube.
2667
01:35:47,283 --> 01:35:47,763
and
2668
01:35:47,793 --> 01:35:52,022
over here we can specify any parameters that this function will take.
2669
01:35:52,292 --> 01:35:57,934
so basically any values that we want to give this function so we're going to give it one function which is just going to be
2670
01:35:58,174 --> 01:36:00,304
a number so I'm just going to call it numb.
2671
01:36:00,874 --> 01:36:02,284
and then over here I'm going to
2672
01:36:02,434 --> 01:36:02,974
type out a
2673
01:36:03,003 --> 01:36:03,724
colon
2674
01:36:04,444 --> 01:36:05,584
and then down here,
2675
01:36:05,854 --> 01:36:07,354
we can put any of the code
2676
01:36:07,384 --> 01:36:09,875
that we want to be included in this function.
2677
01:36:10,294 --> 01:36:14,316
so basically this function is just going to keep this number so we could just
2678
01:36:14,346 --> 01:36:15,545
take out numb
2679
01:36:15,875 --> 01:36:16,955
times numb
2680
01:36:17,255 --> 01:36:18,185
times numb
2681
01:36:18,485 --> 01:36:18,875
right
2682
01:36:19,055 --> 01:36:20,345
that's going to give us
2683
01:36:20,405 --> 01:36:21,335
numb cubed.
2684
01:36:21,396 --> 01:36:21,905
so
2685
01:36:22,055 --> 01:36:23,166
that's all well and good.
2686
01:36:23,226 --> 01:36:24,996
and if I come down here I can
2687
01:36:25,026 --> 01:36:28,956
execute this function so I can basically just call it as a cube.
2688
01:36:29,286 --> 01:36:31,236
and why don't we pass it a three.
2689
01:36:31,626 --> 01:36:33,486
so I'm going to go ahead and pass it to three
2690
01:36:33,906 --> 01:36:35,377
and I'm going to save this.
2691
01:36:36,457 --> 01:36:36,967
and
2692
01:36:36,997 --> 01:36:38,617
now let's go ahead and run
2693
01:36:38,646 --> 01:36:39,606
this code,
2694
01:36:40,207 --> 01:36:41,557
so we're on the code
2695
01:36:41,887 --> 01:36:42,517
and
2696
01:36:43,146 --> 01:36:44,767
you'll see down here.
2697
01:36:45,307 --> 01:36:46,267
nothing happened
2698
01:36:46,356 --> 01:36:48,217
right so nothing got printed out
2699
01:36:48,607 --> 01:36:49,537
in our program
2700
01:36:49,567 --> 01:36:50,107
facts
2701
01:36:50,467 --> 01:36:52,387
when we call this cube function
2702
01:36:52,417 --> 01:36:53,917
it didn't really do anything,
2703
01:36:54,007 --> 01:36:54,397
so
2704
01:36:54,427 --> 01:36:57,066
let me try to print this out so immediately prentice
2705
01:36:57,366 --> 01:37:00,696
function out it'll give us back the information that we want so
2706
01:37:01,146 --> 01:37:02,045
what about print
2707
01:37:02,135 --> 01:37:03,095
and will print
2708
01:37:03,125 --> 01:37:05,465
out the value of the function I'm terrific play
2709
01:37:06,186 --> 01:37:08,676
we look down here it says none.
2710
01:37:09,096 --> 01:37:10,686
so when I printed out
2711
01:37:10,715 --> 01:37:13,475
the value of this function it told me none
2712
01:37:14,105 --> 01:37:17,315
but really this function is supposed to be q being the number.
2713
01:37:17,706 --> 01:37:18,125
and
2714
01:37:18,155 --> 01:37:20,765
here's how we can use the return statement and python
2715
01:37:20,795 --> 01:37:22,355
I can come over here and I can just say
2716
01:37:22,385 --> 01:37:23,195
return
2717
01:37:23,885 --> 01:37:24,875
and now
2718
01:37:24,905 --> 01:37:29,135
python is going to return whatever value we put over here to the right.
2719
01:37:29,525 --> 01:37:32,975
so when I call this cube function and I give it a three
2720
01:37:33,665 --> 01:37:36,335
python's going to go off it's going to execute this function
2721
01:37:36,365 --> 01:37:38,315
when it sees this return statement
2722
01:37:38,345 --> 01:37:38,915
it's going to say
2723
01:37:38,945 --> 01:37:39,365
okay,
2724
01:37:39,665 --> 01:37:43,685
I want to give a value back to whatever call of this function.
2725
01:37:43,805 --> 01:37:45,064
and it's going to return
2726
01:37:45,094 --> 01:37:45,994
this value.
2727
01:37:46,474 --> 01:37:48,004
now when I print out
2728
01:37:48,034 --> 01:37:48,514
cube
2729
01:37:48,543 --> 01:37:49,173
three
2730
01:37:49,563 --> 01:37:53,643
it should print out the answer because we get an answer back so
2731
01:37:53,913 --> 01:37:54,693
when I play this
2732
01:37:54,723 --> 01:37:55,503
you'll see
2733
01:37:55,533 --> 01:37:56,343
down here,
2734
01:37:56,673 --> 01:37:57,093
says
2735
01:37:57,123 --> 01:37:59,643
twenty seven so we got the correct answer.
2736
01:37:59,883 --> 01:38:03,273
so I can do this with anything wantonly cube like for something
2737
01:38:04,173 --> 01:38:05,104
as an hour on this
2738
01:38:05,374 --> 01:38:09,213
and you can see we're constantly getting the correct answer back
2739
01:38:09,243 --> 01:38:09,603
so
2740
01:38:09,632 --> 01:38:15,122
that's the basics of using this return statement it allows us to return a value back to
2741
01:38:15,152 --> 01:38:16,472
the caller in other words
2742
01:38:16,712 --> 01:38:18,602
back to whatever's calling the function.
2743
01:38:18,992 --> 01:38:24,001
so I just wanna illustrate this point a little bit further I'm going to go up here I'm actually going to create a variable
2744
01:38:24,091 --> 01:38:26,491
so I'm gonna create a variable called result
2745
01:38:26,521 --> 01:38:27,662
and I'm just going to set it
2746
01:38:27,691 --> 01:38:28,651
equal to
2747
01:38:28,921 --> 01:38:29,642
cube
2748
01:38:29,762 --> 01:38:30,482
for
2749
01:38:30,572 --> 01:38:33,092
this variable result is going to store
2750
01:38:33,122 --> 01:38:34,142
the value
2751
01:38:34,382 --> 01:38:35,702
that gets returned
2752
01:38:36,001 --> 01:38:37,921
from the cube function since
2753
01:38:38,071 --> 01:38:39,091
it's not in a store like
2754
01:38:39,121 --> 01:38:43,890
cube for its going to store the value that gets returned from executing that function.
2755
01:38:44,250 --> 01:38:46,710
so now if I came down here and printed out result.
2756
01:38:47,250 --> 01:38:50,221
it's actually just going to turn out sixty four again because
2757
01:38:50,251 --> 01:38:51,811
that's the value that it's storing
2758
01:38:52,111 --> 01:38:54,721
so this return statement can be really useful for like
2759
01:38:54,901 --> 01:38:56,941
getting information back from a function,
2760
01:38:57,151 --> 01:38:57,871
we can use
2761
01:38:57,901 --> 01:38:59,431
something like a parameter.
2762
01:38:59,701 --> 01:39:01,231
I guess for as a parameter.
2763
01:39:01,441 --> 01:39:03,542
we can give information to a function
2764
01:39:03,841 --> 01:39:07,171
and then we can use the return statement to get information
2765
01:39:07,201 --> 01:39:08,521
back from a function.
2766
01:39:09,001 --> 01:39:11,102
and I do I just want to point out one more thing
2767
01:39:11,432 --> 01:39:14,103
I'm actually not able to put any code.
2768
01:39:14,522 --> 01:39:18,722
after this return statements so if I came down here and try to put like a prince statement.
2769
01:39:19,352 --> 01:39:21,511
this actually isn't going to work so
2770
01:39:21,541 --> 01:39:24,662
this is never going to get printed out so if I just typed out like
2771
01:39:24,722 --> 01:39:25,712
code right here
2772
01:39:26,342 --> 01:39:28,112
when we run this program.
2773
01:39:28,982 --> 01:39:30,633
it's not going to type out
2774
01:39:30,663 --> 01:39:31,232
code
2775
01:39:31,562 --> 01:39:34,203
does because when I used this return keyword,
2776
01:39:34,473 --> 01:39:36,693
it breaks us out of the function so
2777
01:39:36,903 --> 01:39:39,483
python's going to go through it's going to execute the code
2778
01:39:39,693 --> 01:39:42,512
in the function whenever it sees this return keyword.
2779
01:39:42,842 --> 01:39:47,133
it's just going to break back out and we're going to be done so we'll never be able to reach
2780
01:39:47,163 --> 01:39:48,212
this line of code.
2781
01:39:48,692 --> 01:39:52,592
so that's the basics of using return statements and you can return
2782
01:39:52,622 --> 01:39:54,182
any data type you want
2783
01:39:54,212 --> 01:39:58,023
we could easily return like a string or boolean or an array.
2784
01:39:58,293 --> 01:40:00,543
it doesn't really matter you can return whatever you want.
2785
01:40:01,203 --> 01:40:05,073
and a lot of times in a lot of situations you're going to want to get a value back from
2786
01:40:05,133 --> 01:40:05,703
a function
2787
01:40:09,723 --> 01:40:12,243
in this tutorial I wanna talk to you guys about using
2788
01:40:12,272 --> 01:40:14,133
if statements in python.
2789
01:40:14,553 --> 01:40:14,853
now
2790
01:40:14,913 --> 01:40:18,183
if statements are a special structure in python
2791
01:40:18,212 --> 01:40:20,582
where we can actually help our programs to
2792
01:40:20,612 --> 01:40:21,062
make
2793
01:40:21,092 --> 01:40:21,992
decisions.
2794
01:40:22,352 --> 01:40:23,882
so by using an if statement
2795
01:40:23,912 --> 01:40:26,072
I could execute certain code when
2796
01:40:26,102 --> 01:40:27,692
certain conditions are true,
2797
01:40:27,962 --> 01:40:28,742
and I could execute
2798
01:40:28,772 --> 01:40:29,882
other code when
2799
01:40:29,972 --> 01:40:31,171
other conditions are true.
2800
01:40:31,591 --> 01:40:35,402
so basically if statements allow our programs to respond
2801
01:40:35,432 --> 01:40:36,032
to the
2802
01:40:36,062 --> 01:40:37,621
input that they are given so
2803
01:40:37,891 --> 01:40:40,681
depending on the data that we're using in the program
2804
01:40:41,011 --> 01:40:46,771
are programs will be able to respond so when certain data is certain values we can do certain things
2805
01:40:47,191 --> 01:40:48,782
and when other data is,
2806
01:40:48,872 --> 01:40:49,441
other values
2807
01:40:49,471 --> 01:40:50,461
you can do other things so
2808
01:40:50,521 --> 01:40:50,731
you know
2809
01:40:50,761 --> 01:40:52,321
your programs are essentially
2810
01:40:52,351 --> 01:40:53,701
becoming a lot smarter
2811
01:40:54,091 --> 01:40:55,531
and actually if statements
2812
01:40:55,561 --> 01:40:59,490
are things that we as human beings deal with every day so
2813
01:40:59,730 --> 01:41:04,740
you know as you go throughout your day generally you're dealing with if statements all the time so I want to kind of
2814
01:41:05,040 --> 01:41:10,949
give you guys a brief introduction into if statements and we'll talk about some of the common if statements that you'd see in everyday life.
2815
01:41:11,279 --> 01:41:14,791
and now we'll go ahead and do a really awesome example of the kind of like
2816
01:41:14,851 --> 01:41:15,511
sure yeah
2817
01:41:15,541 --> 01:41:17,312
what if statements can do for us.
2818
01:41:17,671 --> 01:41:18,211
so
2819
01:41:18,421 --> 01:41:21,482
over here in my text editor I just have this little text file
2820
01:41:21,512 --> 01:41:23,583
and in here I wrote out a bunch of
2821
01:41:23,612 --> 01:41:24,362
if statements
2822
01:41:24,392 --> 01:41:24,722
that
2823
01:41:24,992 --> 01:41:30,123
a lot of people will encounter on a daily basis so here's the first one it says I wake up
2824
01:41:30,873 --> 01:41:31,982
if I'm hungry.
2825
01:41:32,583 --> 01:41:33,692
I eat breakfast.
2826
01:41:34,112 --> 01:41:36,663
so let's break this down a little bit up here it says
2827
01:41:36,723 --> 01:41:37,683
if I'm hungry.
2828
01:41:38,042 --> 01:41:39,272
and this is a condition.
2829
01:41:39,692 --> 01:41:40,052
right
2830
01:41:40,412 --> 01:41:42,182
this is either going to be true
2831
01:41:42,211 --> 01:41:43,501
or it's going to be false,
2832
01:41:43,562 --> 01:41:43,981
right
2833
01:41:44,281 --> 01:41:45,361
if it's true,
2834
01:41:45,691 --> 01:41:47,042
I'm going to go ahead and
2835
01:41:47,222 --> 01:41:48,632
eat breakfast right
2836
01:41:48,932 --> 01:41:50,342
if it's false
2837
01:41:50,612 --> 01:41:53,342
under skin to skip whatever was in here and move on,
2838
01:41:53,762 --> 01:41:54,422
writes that
2839
01:41:54,452 --> 01:41:55,742
the basics of an if statement.
2840
01:41:55,832 --> 01:41:56,972
we have a condition
2841
01:41:57,302 --> 01:41:57,992
in this case
2842
01:41:58,021 --> 01:41:58,832
if I'm hungry.
2843
01:41:59,102 --> 01:42:00,452
if the condition is true,
2844
01:42:00,692 --> 01:42:02,522
then we do the action so
2845
01:42:02,552 --> 01:42:03,482
we eat breakfast.
2846
01:42:03,812 --> 01:42:05,612
otherwise we just skip it.
2847
01:42:06,452 --> 01:42:07,742
so down here we have another one.
2848
01:42:07,982 --> 01:42:08,672
it says
2849
01:42:08,732 --> 01:42:09,902
I leave my house.
2850
01:42:10,532 --> 01:42:11,612
if it's cloudy.
2851
01:42:12,182 --> 01:42:13,232
I bring an umbrella.
2852
01:42:13,652 --> 01:42:14,612
otherwise
2853
01:42:14,702 --> 01:42:15,152
I bring
2854
01:42:15,182 --> 01:42:16,052
sunglasses.
2855
01:42:16,382 --> 01:42:21,812
and so this one is a little bit more complex than the one we just looked at you'll see we have our condition right says
2856
01:42:21,842 --> 01:42:22,772
if it's cloudy.
2857
01:42:23,372 --> 01:42:24,752
if that conditions true
2858
01:42:24,782 --> 01:42:26,072
we're going to bring the umbrella.
2859
01:42:26,672 --> 01:42:27,032
but
2860
01:42:27,092 --> 01:42:29,462
in this case if the conditions false
2861
01:42:29,492 --> 01:42:31,742
there is something else that we want to do
2862
01:42:32,012 --> 01:42:35,733
so in the case of here if this condition was false we just moved on.
2863
01:42:36,033 --> 01:42:38,223
but now if this conditions false
2864
01:42:38,252 --> 01:42:39,693
then we're gonna go ahead and bring
2865
01:42:39,753 --> 01:42:40,593
sunglasses
2866
01:42:40,623 --> 01:42:41,013
so
2867
01:42:41,312 --> 01:42:44,852
that's another example of an if statement it's a little bit more complex.
2868
01:42:45,182 --> 01:42:49,682
finally I have one more down here and this one's even more complex it says I'm at a restaurant.
2869
01:42:50,222 --> 01:42:51,392
if I want me.
2870
01:42:51,572 --> 01:42:52,651
I order a steak.
2871
01:42:52,951 --> 01:42:54,721
so if this conditions true
2872
01:42:54,751 --> 01:42:55,892
we order the steak,
2873
01:42:56,372 --> 01:42:58,292
but if this condition is false,
2874
01:42:58,352 --> 01:43:00,962
then we're going to move on and we're actually going to check
2875
01:43:00,992 --> 01:43:02,012
another condition.
2876
01:43:02,312 --> 01:43:02,942
so I'm gonna say
2877
01:43:02,972 --> 01:43:03,751
otherwise
2878
01:43:03,781 --> 01:43:05,041
if I want pasta.
2879
01:43:05,371 --> 01:43:07,021
I order spaghetti and meatballs.
2880
01:43:07,471 --> 01:43:09,062
this is another condition.
2881
01:43:09,602 --> 01:43:11,941
if this condition is true we get the spaghetti,
2882
01:43:12,122 --> 01:43:13,381
if it's not true
2883
01:43:13,411 --> 01:43:16,021
then finally we're going to move on down here
2884
01:43:16,231 --> 01:43:19,292
and which is default to ordering the salad so
2885
01:43:19,861 --> 01:43:21,751
all three of these if statements are
2886
01:43:21,812 --> 01:43:22,891
valid if statements
2887
01:43:22,921 --> 01:43:23,431
it's just
2888
01:43:23,460 --> 01:43:26,641
they get more and more complex as we go down the list
2889
01:43:26,670 --> 01:43:27,150
so
2890
01:43:27,420 --> 01:43:28,200
hopefully that's
2891
01:43:28,230 --> 01:43:28,560
you know
2892
01:43:28,590 --> 01:43:32,730
kind of wrap your head around what if statements are we're basically specifying conditions.
2893
01:43:33,120 --> 01:43:35,790
if those conditions are true we're going to do certain things
2894
01:43:36,030 --> 01:43:38,101
and those conditions are false we can do
2895
01:43:38,130 --> 01:43:38,851
other things.
2896
01:43:38,911 --> 01:43:39,301
or
2897
01:43:39,331 --> 01:43:39,960
we can check
2898
01:43:39,990 --> 01:43:41,130
other conditions
2899
01:43:41,250 --> 01:43:45,362
aren't so let's head over to our python file and we'll start writing some actual python.
2900
01:43:46,172 --> 01:43:48,631
so in here in my app dot python file.
2901
01:43:49,201 --> 01:43:50,372
I want to create an
2902
01:43:50,401 --> 01:43:51,091
if statement
2903
01:43:51,121 --> 01:43:54,541
and I'm going to show you guys a very basic if statement in this tutorial.
2904
01:43:54,781 --> 01:43:57,812
and then in the next victoria we're going to look at some more advanced
2905
01:43:57,841 --> 01:43:58,501
if statements.
2906
01:43:58,801 --> 01:44:00,752
so what I want to do is create
2907
01:44:00,782 --> 01:44:02,582
a bully invariable.
2908
01:44:03,001 --> 01:44:07,742
so I'm gonna create a boolean variable that's going to store whether or not the user is a male.
2909
01:44:07,892 --> 01:44:09,002
so it's just going to be called
2910
01:44:09,032 --> 01:44:10,802
is underscored mail
2911
01:44:11,192 --> 01:44:13,651
and I'm gonna set this equal to true
2912
01:44:13,681 --> 01:44:14,761
because I'm a male.
2913
01:44:15,241 --> 01:44:20,251
so we have this boolean variable right and right now we haven't set equal to true.
2914
01:44:21,301 --> 01:44:22,711
I can actually use an
2915
01:44:22,741 --> 01:44:29,250
if statement to check to see what the value of this variable is and if it's true I can do something so
2916
01:44:29,610 --> 01:44:32,191
if I want to use an if statement all I have to do is just type up
2917
01:44:32,251 --> 01:44:32,791
if.
2918
01:44:33,391 --> 01:44:33,991
and then
2919
01:44:34,021 --> 01:44:35,191
I just need to type out
2920
01:44:35,221 --> 01:44:36,391
a condition.
2921
01:44:36,691 --> 01:44:37,141
so
2922
01:44:37,171 --> 01:44:39,301
basically I would have to type out like
2923
01:44:39,781 --> 01:44:42,061
something that's going to be true or false
2924
01:44:42,091 --> 01:44:42,601
like
2925
01:44:42,630 --> 01:44:43,740
for example in
2926
01:44:43,770 --> 01:44:45,870
the other page we are specifying like
2927
01:44:46,170 --> 01:44:48,390
if I'm hungry or if it's cloudy.
2928
01:44:48,570 --> 01:44:50,160
here we're just going to check to see
2929
01:44:50,189 --> 01:44:50,669
if
2930
01:44:51,060 --> 01:44:51,989
is male.
2931
01:44:52,379 --> 01:44:53,489
so in other words
2932
01:44:53,519 --> 01:44:55,169
if the person is male.
2933
01:44:55,439 --> 01:44:57,060
so remember this has to be a
2934
01:44:57,089 --> 01:44:57,419
lake
2935
01:44:57,449 --> 01:45:01,409
it has to be able to be reducible to a true or false value.
2936
01:45:01,649 --> 01:45:02,579
so in our case
2937
01:45:02,639 --> 01:45:04,649
where it is using a boolean because that's like
2938
01:45:04,679 --> 01:45:06,029
the easiest thing we can do.
2939
01:45:06,509 --> 01:45:06,959
so
2940
01:45:06,989 --> 01:45:07,439
I said
2941
01:45:07,469 --> 01:45:07,829
if
2942
01:45:07,858 --> 01:45:09,059
I specify my
2943
01:45:09,088 --> 01:45:10,769
true or false condition.
2944
01:45:11,429 --> 01:45:12,989
now I'm just type a colon.
2945
01:45:13,619 --> 01:45:14,099
and
2946
01:45:14,129 --> 01:45:16,439
what I want to do now is make a new line.
2947
01:45:16,739 --> 01:45:17,459
and so
2948
01:45:17,759 --> 01:45:21,119
anything that I put below this with an indentation
2949
01:45:21,628 --> 01:45:23,249
is actually going to be
2950
01:45:23,339 --> 01:45:26,219
executed when that conditions true so I could put
2951
01:45:26,279 --> 01:45:26,879
print
2952
01:45:27,539 --> 01:45:29,309
and down here I can just put
2953
01:45:29,789 --> 01:45:30,809
you are a male.
2954
01:45:32,249 --> 01:45:35,220
and now you'll see what happens when I run this program.
2955
01:45:35,370 --> 01:45:38,970
it's going to go down here and it's going to say you are a male.
2956
01:45:39,270 --> 01:45:41,940
but if I changed his mail to false
2957
01:45:41,970 --> 01:45:44,669
so instead of this being true I'd just change it to false.
2958
01:45:44,819 --> 01:45:46,499
now all of a sudden it's not going to
2959
01:45:46,528 --> 01:45:47,608
print anything.
2960
01:45:47,789 --> 01:45:49,739
so it's just going to be blank down here.
2961
01:45:50,039 --> 01:45:52,559
that's because this condition wasn't
2962
01:45:52,588 --> 01:45:53,128
true.
2963
01:45:53,369 --> 01:45:55,738
so anything that I put below this
2964
01:45:56,038 --> 01:45:57,568
if declaration and
2965
01:45:57,778 --> 01:45:59,788
that has an indentation like that
2966
01:46:00,088 --> 01:46:02,458
is going to be executed when the if statement
2967
01:46:02,487 --> 01:46:03,447
is true.
2968
01:46:03,807 --> 01:46:06,357
we can also use another keyword in
2969
01:46:06,387 --> 01:46:07,438
python which is called
2970
01:46:07,498 --> 01:46:08,098
else
2971
01:46:08,338 --> 01:46:10,408
and alice is basically going to be like
2972
01:46:10,468 --> 01:46:11,938
otherwise so you remember,
2973
01:46:12,147 --> 01:46:13,138
before we said
2974
01:46:13,408 --> 01:46:14,608
if it's cloudy.
2975
01:46:14,788 --> 01:46:15,988
I'll bring an umbrella,
2976
01:46:16,048 --> 01:46:17,218
otherwise
2977
01:46:17,818 --> 01:46:20,699
I'll bring sunglasses well this is going to be like our otherwise
2978
01:46:20,729 --> 01:46:22,139
so I can say down here.
2979
01:46:22,409 --> 01:46:23,069
else
2980
01:46:23,489 --> 01:46:24,059
and now
2981
01:46:24,088 --> 01:46:26,188
anything that I've put below else
2982
01:46:26,309 --> 01:46:27,539
is going to get printed out when
2983
01:46:27,569 --> 01:46:28,259
that condition
2984
01:46:28,289 --> 01:46:28,829
isn't sure
2985
01:46:28,858 --> 01:46:29,999
so long we just put
2986
01:46:30,358 --> 01:46:31,889
you are not a male.
2987
01:46:32,729 --> 01:46:33,418
so now
2988
01:46:33,628 --> 01:46:37,139
we're able to cover both of these situations for this variable.
2989
01:46:37,199 --> 01:46:39,479
if it's false we can cover that situation.
2990
01:46:39,719 --> 01:46:40,439
so it says
2991
01:46:40,469 --> 01:46:41,699
you are not a male.
2992
01:46:41,999 --> 01:46:43,049
if it's true
2993
01:46:44,039 --> 01:46:46,680
we can cover that situation as well so it'll say
2994
01:46:46,709 --> 01:46:47,790
you are a male,
2995
01:46:48,060 --> 01:46:49,050
so that's pretty cool.
2996
01:46:49,830 --> 01:46:53,130
but we can also make these more complex
2997
01:46:53,160 --> 01:46:58,891
and actually before I talk about that you can put as much code as you want inside an if statement so I could have like
2998
01:46:59,460 --> 01:47:01,410
dozens of lines of code if I wanted.
2999
01:47:02,310 --> 01:47:04,080
I'm just giving you guys are very simple example
3000
01:47:04,110 --> 01:47:04,560
so
3001
01:47:04,740 --> 01:47:08,221
why don't we make this more complex and I'm gonna add another
3002
01:47:08,250 --> 01:47:09,750
variable into the mix
3003
01:47:09,780 --> 01:47:13,500
so I'm going to add another you know boolean attribute into this mix.
3004
01:47:13,770 --> 01:47:15,210
I'm going to make another variable called
3005
01:47:15,240 --> 01:47:16,440
is tall
3006
01:47:16,830 --> 01:47:18,961
and we're gonna set this equal to true as well.
3007
01:47:19,291 --> 01:47:19,741
so
3008
01:47:19,801 --> 01:47:20,671
now I have
3009
01:47:20,701 --> 01:47:22,891
two variables in the mix.
3010
01:47:23,221 --> 01:47:27,931
let's say I wanted to write an if statement that will check both of those variables.
3011
01:47:28,201 --> 01:47:30,181
so I could write an if statement that's like
3012
01:47:30,271 --> 01:47:32,401
if their mail and their tall or
3013
01:47:32,431 --> 01:47:34,321
if they're male and they're not taller
3014
01:47:34,501 --> 01:47:36,122
if they're not mail in their tall like
3015
01:47:36,151 --> 01:47:37,622
I can write out a bunch of
3016
01:47:37,682 --> 01:47:38,522
if statements
3017
01:47:38,732 --> 01:47:39,422
to check
3018
01:47:39,752 --> 01:47:42,211
the combination of these variables
3019
01:47:42,571 --> 01:47:45,451
and so the way I can do that is by using one of
3020
01:47:45,480 --> 01:47:46,590
two key words
3021
01:47:46,620 --> 01:47:47,040
so
3022
01:47:47,220 --> 01:47:49,470
the first keyword I want to show you guys is the
3023
01:47:49,500 --> 01:47:50,460
or keyword.
3024
01:47:50,850 --> 01:47:52,500
so I can come over here and I could say
3025
01:47:52,529 --> 01:47:52,859
if
3026
01:47:52,889 --> 01:47:53,759
is male
3027
01:47:54,239 --> 01:47:54,959
or
3028
01:47:55,529 --> 01:47:56,099
is
3029
01:47:56,159 --> 01:47:56,849
underscore
3030
01:47:56,879 --> 01:47:57,449
tall.
3031
01:47:57,989 --> 01:48:02,459
and what this is basically going to do is it's going to say if the person is either male
3032
01:48:02,819 --> 01:48:03,569
or
3033
01:48:03,809 --> 01:48:05,039
if their tall,
3034
01:48:05,429 --> 01:48:07,829
then we want to do something so
3035
01:48:08,459 --> 01:48:11,880
this is only going to be true when one of these values
3036
01:48:11,940 --> 01:48:12,570
is true
3037
01:48:12,600 --> 01:48:15,209
when one or both of those values is true
3038
01:48:16,140 --> 01:48:21,359
so down here we can actually put instead of you are a male we could put you are a male
3039
01:48:21,419 --> 01:48:22,590
or tall or
3040
01:48:22,650 --> 01:48:23,070
both
3041
01:48:23,100 --> 01:48:23,939
that's going to be
3042
01:48:23,969 --> 01:48:25,139
more appropriate.
3043
01:48:25,589 --> 01:48:28,260
and then down here we would say you are
3044
01:48:30,150 --> 01:48:31,230
neither male
3045
01:48:31,260 --> 01:48:31,860
nor
3046
01:48:31,920 --> 01:48:32,460
tall
3047
01:48:32,820 --> 01:48:33,930
and that's because
3048
01:48:34,110 --> 01:48:36,660
if we execute the code inside of this else
3049
01:48:36,689 --> 01:48:37,559
that means that
3050
01:48:37,589 --> 01:48:39,719
both of these guys are false
3051
01:48:39,989 --> 01:48:40,829
rates I'm saying
3052
01:48:40,858 --> 01:48:42,868
if they're male or their tall,
3053
01:48:43,468 --> 01:48:45,178
we're going to execute whatever isn't here
3054
01:48:45,928 --> 01:48:46,648
otherwise
3055
01:48:46,678 --> 01:48:47,158
that means
3056
01:48:47,188 --> 01:48:48,178
they're neither male
3057
01:48:48,208 --> 01:48:50,608
nor tall we're just going to execute this down here so
3058
01:48:50,878 --> 01:48:52,588
misery as how this works all
3059
01:48:52,618 --> 01:48:53,458
click play.
3060
01:48:53,878 --> 01:48:58,259
and these are both true so it's going to say you are a male or tall or both.
3061
01:48:58,619 --> 01:49:00,809
if I was to set one of these to false
3062
01:49:01,648 --> 01:49:03,149
so let's set his male eagle
3063
01:49:03,179 --> 01:49:03,809
false.
3064
01:49:04,139 --> 01:49:04,799
now,
3065
01:49:05,039 --> 01:49:08,340
it's still going to say you are a male or tall or both.
3066
01:49:08,760 --> 01:49:11,040
but if I set them both equal to false.
3067
01:49:11,700 --> 01:49:13,080
now it's going to
3068
01:49:13,110 --> 01:49:14,700
say you're neither male
3069
01:49:14,760 --> 01:49:15,720
nor tall.
3070
01:49:16,080 --> 01:49:16,530
so
3071
01:49:16,560 --> 01:49:17,880
that's how the basics
3072
01:49:17,910 --> 01:49:19,860
of using the or operator.
3073
01:49:20,280 --> 01:49:22,710
and there's another operator we can use which is called
3074
01:49:22,740 --> 01:49:23,280
and
3075
01:49:23,820 --> 01:49:24,750
and basically a
3076
01:49:24,779 --> 01:49:25,529
similar to
3077
01:49:25,559 --> 01:49:26,519
or accept
3078
01:49:26,549 --> 01:49:27,569
both of these
3079
01:49:27,599 --> 01:49:29,429
conditions have to be true so
3080
01:49:29,699 --> 01:49:30,959
this is basically saying
3081
01:49:30,989 --> 01:49:32,639
if the person is male,
3082
01:49:32,999 --> 01:49:33,509
and
3083
01:49:33,539 --> 01:49:34,859
they're also tall,
3084
01:49:35,069 --> 01:49:39,149
then we're going to execute whatever's in here so we could actually change this text
3085
01:49:39,179 --> 01:49:39,869
to say
3086
01:49:40,019 --> 01:49:40,739
you are
3087
01:49:40,769 --> 01:49:41,338
a
3088
01:49:41,579 --> 01:49:42,539
tall now
3089
01:49:42,568 --> 01:49:44,279
because we know for a fact that
3090
01:49:44,789 --> 01:49:47,849
if this is getting executed that are both male and tall.
3091
01:49:48,269 --> 01:49:49,499
we can also change
3092
01:49:49,529 --> 01:49:51,149
this print statement down here,
3093
01:49:51,330 --> 01:49:53,250
this could say you are
3094
01:49:53,430 --> 01:49:53,939
either
3095
01:49:53,969 --> 01:49:56,369
not mail or not tall,
3096
01:49:56,699 --> 01:49:57,539
or both.
3097
01:49:57,629 --> 01:49:58,109
so
3098
01:49:58,979 --> 01:50:00,689
you can see it's basically just saying that
3099
01:50:00,869 --> 01:50:01,709
you're either
3100
01:50:01,739 --> 01:50:04,499
not one of them or you're not both of them so
3101
01:50:05,909 --> 01:50:07,019
we could the play button
3102
01:50:07,048 --> 01:50:09,238
and you'll see because they're both false
3103
01:50:09,268 --> 01:50:12,629
it's going to say you are either not mail or not tall or both.
3104
01:50:12,869 --> 01:50:14,279
but if I make them both
3105
01:50:14,309 --> 01:50:15,119
true,
3106
01:50:15,628 --> 01:50:16,769
now it's going to say
3107
01:50:16,798 --> 01:50:18,718
you are a tall male.
3108
01:50:20,428 --> 01:50:22,889
if I was going to make one of these faster so let's make
3109
01:50:22,918 --> 01:50:24,479
is tall false.
3110
01:50:24,659 --> 01:50:29,549
now it's not going to execute this first print statement it's going to execute the one inside of the else,
3111
01:50:29,789 --> 01:50:31,169
so to say you are either
3112
01:50:31,199 --> 01:50:32,939
not mail are not tolerable.
3113
01:50:33,299 --> 01:50:33,809
so
3114
01:50:33,838 --> 01:50:35,039
that's the basics of
3115
01:50:35,068 --> 01:50:36,059
and and or
3116
01:50:36,088 --> 01:50:36,688
and you know
3117
01:50:36,718 --> 01:50:39,599
you'll be using those a lot of them as you use your if statements,
3118
01:50:40,019 --> 01:50:41,729
but there's actually one more
3119
01:50:41,938 --> 01:50:45,179
thing we can do we can add in some more conditions
3120
01:50:45,209 --> 01:50:46,679
so up here I'm checking
3121
01:50:46,919 --> 01:50:48,750
if their mail and their tall,
3122
01:50:49,110 --> 01:50:52,650
but what if I wanted to check if their mail and they're not tall
3123
01:50:52,680 --> 01:50:54,510
so they're like a short male
3124
01:50:54,930 --> 01:50:56,160
I can use another
3125
01:50:56,190 --> 01:50:57,720
keyword in python
3126
01:50:57,780 --> 01:50:58,260
called
3127
01:50:58,560 --> 01:50:59,310
else f
3128
01:50:59,790 --> 01:51:01,020
or really it's just typed out
3129
01:51:01,050 --> 01:51:01,530
yes
3130
01:51:01,560 --> 01:51:02,070
I am,
3131
01:51:02,340 --> 01:51:03,690
and it stands for lcds.
3132
01:51:04,080 --> 01:51:06,960
and after this we can put another condition so
3133
01:51:07,320 --> 01:51:09,360
over here I'm going to check to see if their
3134
01:51:09,450 --> 01:51:11,371
male and they're not tall,
3135
01:51:11,880 --> 01:51:13,140
so I'm gonna say else if
3136
01:51:13,350 --> 01:51:13,830
mayor
3137
01:51:13,859 --> 01:51:14,669
ismail,
3138
01:51:15,449 --> 01:51:16,079
and
3139
01:51:16,169 --> 01:51:17,249
now I can type in
3140
01:51:17,279 --> 01:51:18,419
not tall.
3141
01:51:18,479 --> 01:51:20,100
and the way I can do that is by saying
3142
01:51:20,129 --> 01:51:20,790
not
3143
01:51:21,030 --> 01:51:21,150
an
3144
01:51:21,180 --> 01:51:22,590
open and close parentheses
3145
01:51:22,770 --> 01:51:23,250
and saying
3146
01:51:23,280 --> 01:51:24,240
is tall
3147
01:51:24,600 --> 01:51:27,089
and basically when I use this not function,
3148
01:51:27,270 --> 01:51:28,650
it's going to negate
3149
01:51:28,680 --> 01:51:31,679
whatever is inside of here so if this was true,
3150
01:51:31,919 --> 01:51:35,489
it's going to make it false and if this was false it's going to make it true.
3151
01:51:35,789 --> 01:51:38,429
so basically that'll tell us whether or not their tall
3152
01:51:39,659 --> 01:51:41,580
and that I'm going to use a colon and now
3153
01:51:41,609 --> 01:51:42,599
down here
3154
01:51:43,049 --> 01:51:47,819
inside of here were basically just going to type out any of the code that we want to happen
3155
01:51:48,060 --> 01:51:49,529
when this condition is true
3156
01:51:50,309 --> 01:51:52,290
so down here we can just print out
3157
01:51:53,549 --> 01:51:55,229
you are a short
3158
01:51:55,259 --> 01:51:55,919
male,
3159
01:51:56,519 --> 01:51:57,059
and
3160
01:51:57,269 --> 01:52:03,059
there's actually one more condition that we want to check for which would be if they're not mail and their tall,
3161
01:52:03,329 --> 01:52:04,919
so we can make one more
3162
01:52:04,979 --> 01:52:05,759
lcs.
3163
01:52:06,749 --> 01:52:08,489
and I'm actually just gonna copy this guy
3164
01:52:08,879 --> 01:52:10,320
and we'll paste it down here.
3165
01:52:11,070 --> 01:52:12,750
so I want to say,
3166
01:52:13,230 --> 01:52:13,771
if
3167
01:52:14,161 --> 01:52:14,940
not,
3168
01:52:15,090 --> 01:52:15,900
is male
3169
01:52:17,640 --> 01:52:18,270
and
3170
01:52:18,630 --> 01:52:19,560
his tall,
3171
01:52:19,920 --> 01:52:22,110
so now we're checking to see if their mail
3172
01:52:22,170 --> 01:52:22,800
and
3173
01:52:23,250 --> 01:52:25,919
are either not now and their tall so here we could say
3174
01:52:26,250 --> 01:52:26,850
you are
3175
01:52:26,879 --> 01:52:27,389
a
3176
01:52:27,419 --> 01:52:28,229
you are
3177
01:52:28,769 --> 01:52:29,759
not a
3178
01:52:30,029 --> 01:52:30,539
male
3179
01:52:30,899 --> 01:52:31,859
but are tall.
3180
01:52:32,369 --> 01:52:32,969
so
3181
01:52:33,029 --> 01:52:34,619
essentially here we have an
3182
01:52:34,648 --> 01:52:36,059
if statement that's going to cover
3183
01:52:36,088 --> 01:52:37,679
every single condition
3184
01:52:37,949 --> 01:52:39,688
for these two variables so
3185
01:52:40,019 --> 01:52:43,438
in every single situation of the two values of these variables
3186
01:52:43,468 --> 01:52:45,778
were going to be able to print something out for it so
3187
01:52:46,019 --> 01:52:47,669
if I mean both of these true
3188
01:52:48,089 --> 01:52:49,500
it's basically going to tell us.
3189
01:52:49,589 --> 01:52:51,000
you are a tall male
3190
01:52:51,419 --> 01:52:52,049
if I make
3191
01:52:52,109 --> 01:52:53,669
is male false
3192
01:52:54,060 --> 01:52:55,379
it's going to tell us.
3193
01:52:55,949 --> 01:52:57,929
you are not a male butter tall
3194
01:52:58,409 --> 01:53:00,359
if I made is mailed true
3195
01:53:01,349 --> 01:53:03,209
and is tall false,
3196
01:53:04,499 --> 01:53:05,129
then
3197
01:53:05,219 --> 01:53:07,079
it's going to tell us you are a short male
3198
01:53:07,409 --> 01:53:09,538
and if I made both of these false
3199
01:53:10,288 --> 01:53:11,548
it's going to tell us
3200
01:53:11,608 --> 01:53:13,018
you are either not
3201
01:53:13,198 --> 01:53:16,678
male or not taller both and actually we need to change this so this should say
3202
01:53:17,848 --> 01:53:19,918
you are not a male
3203
01:53:19,978 --> 01:53:23,068
and not tall so that would be a better print out
3204
01:53:23,608 --> 01:53:24,868
for that situation so
3205
01:53:25,288 --> 01:53:26,968
you basically see how we can use
3206
01:53:27,028 --> 01:53:27,718
ifs
3207
01:53:27,868 --> 01:53:28,798
osoph's
3208
01:53:28,828 --> 01:53:29,278
and
3209
01:53:29,308 --> 01:53:30,897
else in order to
3210
01:53:31,527 --> 01:53:33,267
how I programmed to make decisions
3211
01:53:33,477 --> 01:53:34,768
and really to respond
3212
01:53:34,797 --> 01:53:36,657
to the different data in our programs.
3213
01:53:36,957 --> 01:53:40,167
so unable to respond to every combination
3214
01:53:40,497 --> 01:53:42,207
of the values for these two
3215
01:53:42,236 --> 01:53:44,307
variables and that's really cool so
3216
01:53:44,727 --> 01:53:48,057
in this example we were just using simple boolean variables
3217
01:53:48,086 --> 01:53:49,646
but in the next tutorial,
3218
01:53:49,946 --> 01:53:54,326
I'll show you guys how you can actually use something called comparison operators.
3219
01:53:54,566 --> 01:53:57,685
so we could compare like two numbers or two strings
3220
01:53:57,955 --> 01:54:00,175
and we could use those as are conditions
3221
01:54:00,205 --> 01:54:00,505
but
3222
01:54:00,685 --> 01:54:04,165
for now I think this is a good introduction into if statements.
3223
01:54:04,555 --> 01:54:06,565
so I'll see you guys in the next tutorial,
3224
01:54:11,036 --> 01:54:13,525
in this tutorial on a talk to you some more about
3225
01:54:13,555 --> 01:54:14,425
if statements
3226
01:54:14,455 --> 01:54:15,416
in python.
3227
01:54:15,746 --> 01:54:19,376
more specifically we're going to be looking at using comparisons
3228
01:54:19,706 --> 01:54:21,416
inside of our if statement so
3229
01:54:21,626 --> 01:54:23,096
if you're following along with the course
3230
01:54:23,126 --> 01:54:24,836
in the last tutorial,
3231
01:54:24,896 --> 01:54:26,096
I talked to you guys about
3232
01:54:26,246 --> 01:54:30,416
just the basics of if statements and we used a couple different boolean variables
3233
01:54:30,686 --> 01:54:34,736
and depending on the diaries of those bullion's we're able to do certain things
3234
01:54:35,156 --> 01:54:40,677
in this tutorial we're going to look at another way to use if statements which is with comparison so,
3235
01:54:41,007 --> 01:54:44,816
instead of just using boolean values we can actually compare
3236
01:54:44,966 --> 01:54:48,026
different value silly I could compare a couple of numbers like
3237
01:54:48,056 --> 01:54:49,556
compare couple strings
3238
01:54:49,976 --> 01:54:53,606
and depending on the results of those comparisons we can do
3239
01:54:53,636 --> 01:54:54,836
certain things so
3240
01:54:55,286 --> 01:55:00,747
this is going to be pretty cool and this is really going to give you guys a full understanding of what you can do with if statements so
3241
01:55:01,347 --> 01:55:03,566
for this tutorial I actually want to create
3242
01:55:03,596 --> 01:55:04,616
a python
3243
01:55:04,646 --> 01:55:05,306
function
3244
01:55:05,696 --> 01:55:07,497
and this function is going to
3245
01:55:07,526 --> 01:55:10,886
give us the maximum number that we pass into it so
3246
01:55:11,276 --> 01:55:14,486
this function is going to take three parameters as input,
3247
01:55:14,726 --> 01:55:15,716
and it's going to print
3248
01:55:15,746 --> 01:55:16,196
out
3249
01:55:16,466 --> 01:55:16,976
the
3250
01:55:17,036 --> 01:55:17,576
biggest
3251
01:55:17,606 --> 01:55:19,196
number that we give it so
3252
01:55:19,886 --> 01:55:21,896
let's create this function I was going to say,
3253
01:55:22,136 --> 01:55:22,796
death.
3254
01:55:23,486 --> 01:55:25,017
and I'm just going to call it max
3255
01:55:25,047 --> 01:55:25,677
numb
3256
01:55:26,247 --> 01:55:26,727
and
3257
01:55:26,907 --> 01:55:32,036
inside of these parentheses I'm going to specify that I want three parameters as input.
3258
01:55:32,336 --> 01:55:33,086
someone to say
3259
01:55:33,116 --> 01:55:33,926
number one,
3260
01:55:34,076 --> 01:55:36,146
number two and number three.
3261
01:55:36,956 --> 01:55:37,646
so basically
3262
01:55:37,675 --> 01:55:39,595
we're passing it three numbers and
3263
01:55:39,625 --> 01:55:40,825
this function will
3264
01:55:40,885 --> 01:55:41,875
return.
3265
01:55:41,965 --> 01:55:42,925
the largest
3266
01:55:42,955 --> 01:55:43,825
of the three.
3267
01:55:44,275 --> 01:55:47,516
so in order to figure out which of these numbers is that the largest
3268
01:55:47,545 --> 01:55:48,716
we're going to have to use an
3269
01:55:48,776 --> 01:55:49,496
if statement.
3270
01:55:49,826 --> 01:55:50,696
so I can say
3271
01:55:50,756 --> 01:55:51,296
if.
3272
01:55:51,776 --> 01:55:52,136
and
3273
01:55:52,166 --> 01:55:54,056
over here I need to specify
3274
01:55:54,085 --> 01:55:55,105
a condition.
3275
01:55:55,226 --> 01:55:57,596
so I need to put like a true or false
3276
01:55:57,625 --> 01:55:58,286
value.
3277
01:55:58,496 --> 01:56:03,535
and so what we can actually do is we can compare these different numbers so I could say if
3278
01:56:03,835 --> 01:56:04,735
num one
3279
01:56:05,335 --> 01:56:07,225
is greater than or equal to
3280
01:56:07,495 --> 01:56:07,885
number
3281
01:56:07,915 --> 01:56:08,395
two,
3282
01:56:09,745 --> 01:56:10,465
and
3283
01:56:10,975 --> 01:56:11,875
number one
3284
01:56:12,116 --> 01:56:13,676
is greater than or equal to
3285
01:56:13,706 --> 01:56:14,815
numb three.
3286
01:56:15,565 --> 01:56:17,545
so basically what I'm doing here
3287
01:56:17,635 --> 01:56:20,456
is I'm comparing these different number so I'm saying if
3288
01:56:20,846 --> 01:56:23,516
the first number is greater than or equal to the second number
3289
01:56:23,876 --> 01:56:24,176
and
3290
01:56:24,206 --> 01:56:25,886
this is a comparison so
3291
01:56:26,126 --> 01:56:27,146
when you think about it
3292
01:56:27,267 --> 01:56:31,917
when we compare these two numbers we're going to end up with a true or false value
3293
01:56:32,157 --> 01:56:32,577
write
3294
01:56:32,667 --> 01:56:36,267
num one is either greater than or equal to numb to or it's not
3295
01:56:36,297 --> 01:56:37,946
it's actually a boolean
3296
01:56:37,976 --> 01:56:38,426
value
3297
01:56:38,456 --> 01:56:39,566
rights either true
3298
01:56:39,807 --> 01:56:40,767
or it's false.
3299
01:56:40,917 --> 01:56:42,207
same thing over here.
3300
01:56:42,477 --> 01:56:44,426
the result of this comparison
3301
01:56:44,606 --> 01:56:45,717
is either true
3302
01:56:45,897 --> 01:56:46,917
or it's false
3303
01:56:47,067 --> 01:56:50,427
so technically I'm putting a true or false value in there.
3304
01:56:50,667 --> 01:56:54,807
I'm just getting that true or false value by using a comparison.
3305
01:56:55,347 --> 01:56:58,827
and you'll notice over here we're using something called a comparison
3306
01:56:58,887 --> 01:56:59,697
operator.
3307
01:57:00,087 --> 01:57:01,527
and basically this is just like
3308
01:57:01,557 --> 01:57:03,296
how we want to compare them so
3309
01:57:03,626 --> 01:57:06,656
we're saying like greater than or equal to in this case
3310
01:57:07,346 --> 01:57:08,336
so down here.
3311
01:57:08,816 --> 01:57:09,207
if
3312
01:57:09,236 --> 01:57:11,366
this whole condition is true
3313
01:57:11,546 --> 01:57:15,206
in other words of the results of these two comparisons end up being true,
3314
01:57:15,686 --> 01:57:17,937
then we know that none one is the biggest
3315
01:57:17,966 --> 01:57:19,286
so I can just return
3316
01:57:19,316 --> 01:57:19,946
num one
3317
01:57:20,006 --> 01:57:21,296
I can say return
3318
01:57:21,356 --> 01:57:21,836
no
3319
01:57:21,866 --> 01:57:22,316
one
3320
01:57:22,346 --> 01:57:25,556
but we also want to check some other condition so I can say
3321
01:57:25,586 --> 01:57:26,186
alef
3322
01:57:26,666 --> 01:57:27,086
and
3323
01:57:27,116 --> 01:57:30,026
now I want to do some other comparison so I'm going to say,
3324
01:57:30,146 --> 01:57:30,956
else if
3325
01:57:31,166 --> 01:57:31,556
none
3326
01:57:31,586 --> 01:57:32,126
too
3327
01:57:32,426 --> 01:57:33,625
is greater than or equal to
3328
01:57:33,655 --> 01:57:34,465
number one
3329
01:57:35,035 --> 01:57:35,605
and
3330
01:57:35,695 --> 01:57:36,055
number
3331
01:57:36,084 --> 01:57:36,504
two
3332
01:57:36,534 --> 01:57:37,884
is greater than or equal to
3333
01:57:37,914 --> 01:57:38,333
number
3334
01:57:38,363 --> 01:57:38,933
three.
3335
01:57:39,503 --> 01:57:44,663
so I'm doing essentially what I did up here except for none too so again I'm comparing
3336
01:57:45,022 --> 01:57:49,223
these different numbers and this is gonna end up being a true or false value,
3337
01:57:49,463 --> 01:57:51,653
depending on the result of the comparison
3338
01:57:52,133 --> 01:57:52,943
so
3339
01:57:53,483 --> 01:57:54,503
down here again
3340
01:57:54,533 --> 01:57:55,192
we can just
3341
01:57:55,433 --> 01:57:56,843
returned home to
3342
01:57:57,083 --> 01:58:00,504
because if all this is true that means we're going to end up returning
3343
01:58:00,594 --> 01:58:01,374
none too.
3344
01:58:01,943 --> 01:58:03,923
and then finally we can just say else
3345
01:58:03,953 --> 01:58:04,583
so
3346
01:58:05,693 --> 01:58:05,933
if
3347
01:58:05,963 --> 01:58:09,114
num one isn't the biggest and numb to isn't the biggest then
3348
01:58:09,144 --> 01:58:10,794
we can pretty much assume that
3349
01:58:11,034 --> 01:58:13,435
number three is the biggest so
3350
01:58:13,675 --> 01:58:14,665
now we have
3351
01:58:14,695 --> 01:58:15,774
our function
3352
01:58:16,074 --> 01:58:16,524
so
3353
01:58:16,584 --> 01:58:17,184
down here
3354
01:58:17,214 --> 01:58:19,075
I'm actually just going to call this function,
3355
01:58:19,945 --> 01:58:21,085
so I'm just going to say,
3356
01:58:21,205 --> 01:58:23,935
actually I'll print out the results I'll say max
3357
01:58:24,025 --> 01:58:24,655
numb
3358
01:58:25,045 --> 01:58:27,265
and will pass in like three four or five
3359
01:58:27,595 --> 01:58:28,225
so
3360
01:58:28,285 --> 01:58:31,435
we're basically calling that new function that we just made.
3361
01:58:33,024 --> 01:58:33,625
and
3362
01:58:33,654 --> 01:58:35,185
I'm going to go ahead and run this program.
3363
01:58:35,694 --> 01:58:37,074
so you can see down here
3364
01:58:37,104 --> 01:58:37,884
in the output
3365
01:58:37,914 --> 01:58:40,494
we printed out five because that was the biggest.
3366
01:58:40,824 --> 01:58:44,334
if I was to change this middle onto the biggest so we make the middle on forty
3367
01:58:44,694 --> 01:58:46,224
now it will be able to
3368
01:58:46,374 --> 01:58:49,854
take on that situation and finally I can make this like three hundred
3369
01:58:50,273 --> 01:58:50,813
and
3370
01:58:50,934 --> 01:58:52,403
it'll be able to handle that so
3371
01:58:52,583 --> 01:58:56,933
no matter which number numb one number two or number three ends up being the biggest
3372
01:58:57,083 --> 01:58:57,293
it's
3373
01:58:57,323 --> 01:58:58,073
able to
3374
01:58:58,103 --> 01:58:59,482
tell us without a problem.
3375
01:59:00,142 --> 01:59:00,622
so
3376
01:59:00,652 --> 01:59:06,652
these comparisons are a really really really common way to make if statements and a lot of times
3377
01:59:06,862 --> 01:59:09,442
you're gonna want to be comparing different values
3378
01:59:09,682 --> 01:59:10,762
inside of python,
3379
01:59:10,972 --> 01:59:12,592
so over here we're comparing
3380
01:59:12,652 --> 01:59:13,552
numbers.
3381
01:59:13,672 --> 01:59:15,862
but we could also compare strings
3382
01:59:15,892 --> 01:59:16,522
so I can
3383
01:59:16,552 --> 01:59:18,232
easily make these both like
3384
01:59:18,562 --> 01:59:19,132
you know I can
3385
01:59:19,162 --> 01:59:20,542
make this like dog
3386
01:59:20,841 --> 01:59:22,551
and I can make this dog
3387
01:59:23,001 --> 01:59:24,082
and I could say
3388
01:59:24,111 --> 01:59:25,731
a different operator so I could say like
3389
01:59:25,761 --> 01:59:29,181
this double equal sign would mean equal so I can basically say like
3390
01:59:29,451 --> 01:59:32,331
if this string is equal to that string.
3391
01:59:32,690 --> 01:59:34,670
you can basically like compare
3392
01:59:34,700 --> 01:59:37,880
all different data types see nike compare in numbers strings.
3393
01:59:38,121 --> 01:59:39,201
you can also compare
3394
01:59:39,230 --> 01:59:40,041
bullion's
3395
01:59:40,880 --> 01:59:41,300
so
3396
01:59:41,541 --> 01:59:42,051
once again
3397
01:59:42,081 --> 01:59:42,891
these are
3398
01:59:42,920 --> 01:59:43,851
comparison
3399
01:59:43,880 --> 01:59:45,020
operators and
3400
01:59:45,200 --> 01:59:49,851
this one is greater than or equal to but there's a bunch of other comparison operators we can use so
3401
01:59:50,601 --> 01:59:53,271
the most basic is just going to be a double equal sign
3402
01:59:53,300 --> 01:59:56,450
and not basically checks to see if the two values are
3403
01:59:56,480 --> 01:59:56,930
equal
3404
01:59:56,960 --> 01:59:57,831
so it'll say like,
3405
01:59:58,101 --> 01:59:58,521
if
3406
01:59:58,670 --> 02:00:00,381
number one is equal to
3407
02:00:00,411 --> 02:00:01,190
number two,
3408
02:00:01,490 --> 02:00:03,530
we can also say not equals
3409
02:00:03,830 --> 02:00:06,770
and this exclamation point will basically mean
3410
02:00:06,950 --> 02:00:08,240
not equal so it's.
3411
02:00:08,510 --> 02:00:10,760
if no one is not equal to
3412
02:00:10,790 --> 02:00:11,600
none too.
3413
02:00:12,350 --> 02:00:13,760
we also have greater than,
3414
02:00:14,030 --> 02:00:14,900
less than,
3415
02:00:15,561 --> 02:00:16,971
greater than or equal to
3416
02:00:17,361 --> 02:00:18,681
less than or equal to.
3417
02:00:18,861 --> 02:00:21,411
and those are kind of all of the operators
3418
02:00:21,441 --> 02:00:22,791
are all the you know the basic
3419
02:00:23,121 --> 02:00:26,241
comparison operators that are going to be using in python so
3420
02:00:26,841 --> 02:00:31,041
using comparisons is really awesome and there's going to be tons and tons of situations
3421
02:00:31,071 --> 02:00:33,951
inside a python where you're going to want to compare different values
3422
02:00:33,980 --> 02:00:34,400
so
3423
02:00:34,820 --> 02:00:36,591
these can be extremely useful
3424
02:00:40,401 --> 02:00:40,701
in this
3425
02:00:40,731 --> 02:00:44,871
tutorial on how to talk to you guys about building a calculator in python.
3426
02:00:45,351 --> 02:00:51,982
now having been fallen along with this course you'll know that in the beginning of the course we actually created a very basic calculator.
3427
02:00:52,462 --> 02:00:59,002
basically the user could just enter into numbers and our calculator would add the numbers together and spit out the answer
3428
02:00:59,572 --> 02:01:04,072
in this is horrible honorary guys how to build a more advanced calculator so
3429
02:01:04,372 --> 02:01:08,843
this calculator is going to be able to perform all of the basic arithmetic
3430
02:01:08,873 --> 02:01:12,113
operations so we can add subtract multiply and divide
3431
02:01:12,593 --> 02:01:16,553
and were actually allow the user to specify which one of those they want to do,
3432
02:01:16,973 --> 02:01:18,684
so the user will enter in a number.
3433
02:01:19,134 --> 02:01:23,094
they'll enter in whatever operator they want to use so plus minus
3434
02:01:23,124 --> 02:01:23,813
divide
3435
02:01:23,963 --> 02:01:24,653
mocked by,
3436
02:01:25,193 --> 02:01:28,523
and then I'll enter in the second number and will perform the operation
3437
02:01:28,553 --> 02:01:30,114
for them says it can be pretty cool.
3438
02:01:30,354 --> 02:01:32,245
and it's going to show you how we can use
3439
02:01:32,995 --> 02:01:33,805
if statements
3440
02:01:33,834 --> 02:01:34,435
in like a
3441
02:01:34,465 --> 02:01:35,755
practical application
3442
02:01:35,785 --> 02:01:36,745
so let's get started.
3443
02:01:37,015 --> 02:01:38,275
the first thing we want to do
3444
02:01:38,305 --> 02:01:39,535
is get
3445
02:01:39,685 --> 02:01:41,695
input from the user so I'm going to create
3446
02:01:41,905 --> 02:01:45,534
three variables one for the first number one for the second number and
3447
02:01:45,774 --> 02:01:46,854
one for the operator
3448
02:01:46,884 --> 02:01:49,853
and will basically store the values that the user inputs
3449
02:01:50,093 --> 02:01:52,854
into those variables so the first one will just be number one
3450
02:01:53,994 --> 02:01:55,615
and I'm gonna set this equal to
3451
02:01:55,645 --> 02:01:56,334
input
3452
02:01:56,725 --> 02:01:58,315
and we're going to give this a prompts also
3453
02:01:58,345 --> 02:01:59,005
enter
3454
02:01:59,455 --> 02:02:00,025
first
3455
02:02:00,085 --> 02:02:00,715
number
3456
02:02:02,065 --> 02:02:05,935
and here's actually the thing is whatever the user
3457
02:02:05,965 --> 02:02:06,685
enters.
3458
02:02:06,925 --> 02:02:07,556
we're going to want to
3459
02:02:07,585 --> 02:02:09,325
convert it into a number
3460
02:02:09,685 --> 02:02:10,105
so
3461
02:02:10,135 --> 02:02:17,035
generally in python when we get input from the user no matter what they put in it just gets converted into a string.
3462
02:02:17,485 --> 02:02:20,036
but we don't want a string because we're going to have to
3463
02:02:20,065 --> 02:02:23,246
be adding or subtracting and multiplying these numbers together ?
3464
02:02:23,666 --> 02:02:25,526
so whenever they enter in
3465
02:02:25,556 --> 02:02:27,866
the number I just want to immediately convert it
3466
02:02:27,896 --> 02:02:28,616
to
3467
02:02:28,706 --> 02:02:31,766
an actual like number data type instead of a string.
3468
02:02:32,156 --> 02:02:34,466
so what I can do is I can actually say float.
3469
02:02:34,736 --> 02:02:36,056
and I can surround
3470
02:02:36,086 --> 02:02:37,976
this entire input tag
3471
02:02:38,216 --> 02:02:39,447
with parentheses.
3472
02:02:39,567 --> 02:02:40,287
and now,
3473
02:02:40,407 --> 02:02:43,796
what this is gonna do is it's going to immediately convert
3474
02:02:43,977 --> 02:02:45,837
whatever the user inputs
3475
02:02:46,017 --> 02:02:46,947
into a float.
3476
02:02:47,247 --> 02:02:51,117
now that's going to mean that they're going to have to insert a number otherwise we'll get an error
3477
02:02:51,146 --> 02:02:51,537
but
3478
02:02:51,896 --> 02:02:55,018
for the most part this should work out for us so I'm actually just going to
3479
02:02:55,047 --> 02:02:56,188
copy their sky
3480
02:02:57,208 --> 02:02:58,587
and we'll go ahead and
3481
02:02:58,828 --> 02:03:00,208
paste it over here,
3482
02:03:00,627 --> 02:03:02,278
and we'll paste it one more time so we
3483
02:03:02,308 --> 02:03:05,218
were basically just try to get three pieces of input from
3484
02:03:05,248 --> 02:03:05,877
the user.
3485
02:03:06,777 --> 02:03:10,048
so the second thing we want to get is the operator so I'm just gonna say
3486
02:03:10,108 --> 02:03:10,888
oh p
3487
02:03:11,368 --> 02:03:14,547
for operator and actually get rid of this flow
3488
02:03:14,577 --> 02:03:15,147
because
3489
02:03:15,177 --> 02:03:16,827
we want to keep this as a string.
3490
02:03:17,277 --> 02:03:18,057
and I'll just say
3491
02:03:18,087 --> 02:03:18,777
enter
3492
02:03:20,097 --> 02:03:21,657
operator so it's going to be like.
3493
02:03:21,717 --> 02:03:22,828
plus minus
3494
02:03:23,127 --> 02:03:24,478
multiplication whatever.
3495
02:03:25,018 --> 02:03:26,967
and then finally down here we'll get numb
3496
02:03:26,997 --> 02:03:27,537
to
3497
02:03:27,567 --> 02:03:30,477
and again we're going to want to convert this to a float,
3498
02:03:30,747 --> 02:03:31,587
so I'll say
3499
02:03:31,828 --> 02:03:33,208
enter second number
3500
02:03:33,478 --> 02:03:33,958
so
3501
02:03:34,138 --> 02:03:37,528
now basically what we're doing is we're getting the first number we're getting the
3502
02:03:37,558 --> 02:03:40,918
operator and we're getting the second number from the user.
3503
02:03:41,218 --> 02:03:41,878
so
3504
02:03:42,148 --> 02:03:45,208
what we need to do now is we need to figure out
3505
02:03:45,237 --> 02:03:46,917
what is inside of this
3506
02:03:47,037 --> 02:03:47,787
o p.
3507
02:03:47,847 --> 02:03:49,467
in other words we need to figure out what
3508
02:03:49,497 --> 02:03:50,336
operator.
3509
02:03:50,577 --> 02:03:51,627
the user was
3510
02:03:51,657 --> 02:03:55,406
trying to do so are they trying to do additional they're trying to do a subtraction like
3511
02:03:55,646 --> 02:03:56,697
we want to figure that out,
3512
02:03:56,757 --> 02:03:57,297
so
3513
02:03:58,047 --> 02:03:58,678
we can use an
3514
02:03:58,708 --> 02:03:59,547
if statement
3515
02:03:59,907 --> 02:04:00,867
in order to
3516
02:04:00,897 --> 02:04:02,908
figure that out so I'm gonna come down here
3517
02:04:02,968 --> 02:04:03,538
and
3518
02:04:03,718 --> 02:04:06,237
I'm basically just going to create an if statement song and say
3519
02:04:06,267 --> 02:04:06,747
if.
3520
02:04:07,437 --> 02:04:07,917
and
3521
02:04:08,007 --> 02:04:13,708
we want to check a condition so I'm basically going to check to see if this operator is equal to
3522
02:04:14,218 --> 02:04:14,998
a plus sign
3523
02:04:15,027 --> 02:04:16,138
so I can say if
3524
02:04:16,288 --> 02:04:17,008
o p
3525
02:04:17,488 --> 02:04:18,328
equals
3526
02:04:18,778 --> 02:04:19,468
plus sign
3527
02:04:20,338 --> 02:04:22,737
and now if the operator is equal to a plus sign.
3528
02:04:22,797 --> 02:04:23,668
I'm just going to print
3529
02:04:23,698 --> 02:04:24,178
out
3530
02:04:25,378 --> 02:04:26,218
number one
3531
02:04:26,248 --> 02:04:26,908
plus
3532
02:04:26,968 --> 02:04:27,748
none too.
3533
02:04:27,838 --> 02:04:31,377
but let's say that instead of a plus sign they entered in something else so we can say
3534
02:04:31,407 --> 02:04:32,367
l f
3535
02:04:32,787 --> 02:04:33,447
o p
3536
02:04:33,477 --> 02:04:34,527
is equal to.
3537
02:04:34,767 --> 02:04:36,688
and now we'll check if it's a minus sign.
3538
02:04:37,558 --> 02:04:38,999
and so here or just print
3539
02:04:39,148 --> 02:04:39,898
num one
3540
02:04:39,928 --> 02:04:40,648
minus
3541
02:04:40,678 --> 02:04:41,398
nothing too.
3542
02:04:42,418 --> 02:04:44,158
and I actually forgot to put a colon here.
3543
02:04:44,728 --> 02:04:47,817
so we can just do these for everything so now we can say.
3544
02:04:47,877 --> 02:04:48,688
lf
3545
02:04:49,288 --> 02:04:50,098
opie
3546
02:04:50,548 --> 02:04:51,688
is equal to
3547
02:04:52,588 --> 02:04:53,488
division
3548
02:04:53,788 --> 02:04:57,297
and here we'll just divide the two numbers so I can print out
3549
02:04:57,597 --> 02:04:59,847
number one divided by numb to it,
3550
02:05:00,597 --> 02:05:04,137
and finally we'll do the same thing for multiplication so I'll say
3551
02:05:04,227 --> 02:05:04,617
l
3552
02:05:04,646 --> 02:05:05,247
if
3553
02:05:05,816 --> 02:05:06,626
opie
3554
02:05:07,077 --> 02:05:07,197
is
3555
02:05:07,227 --> 02:05:08,396
equal to
3556
02:05:08,787 --> 02:05:09,777
astronauts
3557
02:05:10,167 --> 02:05:11,247
and was print
3558
02:05:11,307 --> 02:05:11,937
out
3559
02:05:12,597 --> 02:05:14,097
number one times
3560
02:05:14,127 --> 02:05:14,937
none too.
3561
02:05:15,627 --> 02:05:18,328
so basically over here we have every
3562
02:05:18,357 --> 02:05:19,407
you know condition.
3563
02:05:19,707 --> 02:05:21,117
but I also want to put in an
3564
02:05:21,146 --> 02:05:21,477
else
3565
02:05:21,506 --> 02:05:22,466
statement so
3566
02:05:22,586 --> 02:05:25,556
in the case that the user enters in an operation.
3567
02:05:25,855 --> 02:05:26,365
that's
3568
02:05:26,395 --> 02:05:27,025
not
3569
02:05:27,055 --> 02:05:31,405
like one of the four that we specified up here I just want to throw an error sums usa
3570
02:05:31,465 --> 02:05:32,155
opie
3571
02:05:32,215 --> 02:05:33,055
are actually we just say
3572
02:05:33,085 --> 02:05:33,625
else
3573
02:05:33,925 --> 02:05:35,695
and here with this print out lake
3574
02:05:36,835 --> 02:05:37,735
invalid
3575
02:05:38,425 --> 02:05:39,205
operator.
3576
02:05:40,345 --> 02:05:40,675
so
3577
02:05:40,705 --> 02:05:45,354
this if statement should give us everything we want basically I'm just checking to see
3578
02:05:45,654 --> 02:05:46,314
if it's
3579
02:05:46,374 --> 02:05:50,363
equal to a plus sign a minus sign the division sign or a multiplication sign !
3580
02:05:50,723 --> 02:05:54,204
depending on which one is equal to we'll do a different operation so
3581
02:05:54,233 --> 02:05:56,994
let's go ahead and run this and see how we do so
3582
02:05:57,324 --> 02:05:58,793
I'm going to run this program
3583
02:06:00,233 --> 02:06:03,624
and it says enter first number let's enter five
3584
02:06:04,614 --> 02:06:06,534
enter an operator so why don't we just
3585
02:06:06,563 --> 02:06:07,643
do addition
3586
02:06:08,093 --> 02:06:10,883
and enter a second numbers do twenty three.
3587
02:06:11,363 --> 02:06:11,903
so now
3588
02:06:11,933 --> 02:06:14,244
it prints out the answer twenty eight so
3589
02:06:14,484 --> 02:06:15,954
our calculator actually works
3590
02:06:15,984 --> 02:06:17,454
let's try another
3591
02:06:17,514 --> 02:06:19,075
operator just to make sure.
3592
02:06:19,525 --> 02:06:21,085
so it would be six
3593
02:06:21,115 --> 02:06:23,185
and y we multiply it
3594
02:06:23,214 --> 02:06:25,224
by I don't know five point
3595
02:06:25,254 --> 02:06:26,094
to three.
3596
02:06:27,084 --> 02:06:31,344
so now we go off and we do the multiplication and looks like we got our answer so
3597
02:06:31,614 --> 02:06:33,563
our calculator seems to be working and so
3598
02:06:33,773 --> 02:06:37,224
basically all we did was we got the input from the user.
3599
02:06:37,434 --> 02:06:38,604
and then we used
3600
02:06:38,693 --> 02:06:40,493
if statements to figure out
3601
02:06:40,523 --> 02:06:45,323
what they wanted to do right so we could check to see if they want an edition we could check to see
3602
02:06:45,563 --> 02:06:46,673
if they wanted subtraction
3603
02:06:46,703 --> 02:06:48,053
division and multiplication.
3604
02:06:48,383 --> 02:06:51,083
and we can also check to see if they entered in an invalid
3605
02:06:51,113 --> 02:06:54,022
operator so actually why don't we try that too.
3606
02:06:55,493 --> 02:06:57,233
so enter it in like five
3607
02:06:57,263 --> 02:06:58,973
and now what does enter unlike
3608
02:06:59,633 --> 02:07:01,673
an open or close parentheses and
3609
02:07:01,703 --> 02:07:02,333
four,
3610
02:07:02,603 --> 02:07:03,684
so you can see here it's
3611
02:07:03,713 --> 02:07:04,463
able to
3612
02:07:04,493 --> 02:07:07,104
tell like the program smart enough to know that
3613
02:07:07,374 --> 02:07:09,144
that's not a valid operator so
3614
02:07:09,684 --> 02:07:16,583
these if statements can be really powerful and we can use them in combination with getting the user inputs to create a little calculator.
3615
02:07:20,393 --> 02:07:24,983
in this tutorial on hitachi guys by using dictionaries in python.
3616
02:07:25,403 --> 02:07:30,863
now a dictionary is a special structure in python which allows us to store information
3617
02:07:31,163 --> 02:07:31,883
in what are called
3618
02:07:31,913 --> 02:07:32,542
key
3619
02:07:32,632 --> 02:07:33,982
value pairs.
3620
02:07:34,402 --> 02:07:37,372
so essentially I can just create a bunch of these different
3621
02:07:37,401 --> 02:07:38,721
key value pairs.
3622
02:07:38,991 --> 02:07:39,321
and then
3623
02:07:39,351 --> 02:07:41,241
what I want to access a specific
3624
02:07:41,331 --> 02:07:43,761
piece of information inside of the dictionary.
3625
02:07:44,031 --> 02:07:45,981
I can just refer to it by its
3626
02:07:46,011 --> 02:07:46,581
key,
3627
02:07:47,091 --> 02:07:52,551
so the word dictionary is actually pretty appropriate here if you are familiar with a normal dictionary,
3628
02:07:53,031 --> 02:07:55,311
you know in a normal dictionary you'd have a word,
3629
02:07:55,671 --> 02:07:56,151
and then
3630
02:07:56,181 --> 02:07:59,181
you'd have a definition associated to that word so
3631
02:07:59,511 --> 02:08:01,551
in this situation the word would be the
3632
02:08:01,581 --> 02:08:02,211
key.
3633
02:08:02,541 --> 02:08:05,722
in other words the word is what like uniquely identifies it
3634
02:08:05,751 --> 02:08:07,131
inside of the dictionary,
3635
02:08:07,521 --> 02:08:07,852
and then
3636
02:08:07,881 --> 02:08:11,062
the value would be the actual definition so
3637
02:08:11,272 --> 02:08:14,513
this is going to make more sense once we start working with this but
3638
02:08:15,173 --> 02:08:17,093
I just wanted to give you guys a quick introduction.
3639
02:08:17,633 --> 02:08:18,593
so in this situation
3640
02:08:18,623 --> 02:08:20,723
I want to create a little program
3641
02:08:20,783 --> 02:08:22,463
that will allow us to convert
3642
02:08:22,493 --> 02:08:24,532
a three digit month name
3643
02:08:24,802 --> 02:08:26,632
into the full month name
3644
02:08:26,873 --> 02:08:28,073
so I can convert
3645
02:08:28,103 --> 02:08:29,093
for example like
3646
02:08:29,123 --> 02:08:29,692
jay
3647
02:08:29,722 --> 02:08:30,442
a n
3648
02:08:30,862 --> 02:08:31,462
two
3649
02:08:32,123 --> 02:08:32,843
january
3650
02:08:33,203 --> 02:08:34,313
or I could convert
3651
02:08:34,403 --> 02:08:34,793
an
3652
02:08:34,823 --> 02:08:35,663
a r
3653
02:08:35,753 --> 02:08:36,413
into
3654
02:08:36,503 --> 02:08:37,103
march.
3655
02:08:37,373 --> 02:08:44,274
like I want to be able to have a program that can do that for us and that's actually a pretty good use case for a dictionary so
3656
02:08:44,634 --> 02:08:46,253
we're actually going to create a dictionary.
3657
02:08:46,583 --> 02:08:48,653
and I'm sure you guys how we can do that so,
3658
02:08:48,743 --> 02:08:50,003
the first thing we need to do
3659
02:08:50,033 --> 02:08:52,553
in creating a dictionary is just given a name,
3660
02:08:52,913 --> 02:08:56,633
so I want to give this a specific name so I'm just going to call this
3661
02:08:56,693 --> 02:08:57,503
month
3662
02:08:58,523 --> 02:08:59,633
conversions.
3663
02:09:00,143 --> 02:09:01,673
and now I just want to set this
3664
02:09:01,703 --> 02:09:02,663
equal to an
3665
02:09:02,723 --> 02:09:04,583
open and closed curly bracket
3666
02:09:04,823 --> 02:09:07,373
so whenever we create a dictionary in python.
3667
02:09:07,613 --> 02:09:08,693
we're always going to wanna
3668
02:09:08,723 --> 02:09:11,213
created inside of these open and closed
3669
02:09:11,243 --> 02:09:12,232
curly brackets
3670
02:09:12,532 --> 02:09:12,862
so
3671
02:09:12,922 --> 02:09:17,662
inside of the dictionary now we can start defining what are called key
3672
02:09:17,842 --> 02:09:19,252
value pairs.
3673
02:09:19,312 --> 02:09:22,492
so I can define a key and that I can give it
3674
02:09:22,522 --> 02:09:22,912
a
3675
02:09:22,942 --> 02:09:24,352
corresponding value.
3676
02:09:24,742 --> 02:09:28,131
and the way that we can do that is by typing out the key and then typing out the value so
3677
02:09:28,582 --> 02:09:31,822
in our case we're converting three digit month names
3678
02:09:31,912 --> 02:09:33,442
into the full month names
3679
02:09:33,472 --> 02:09:35,481
so I would want to type out for example
3680
02:09:35,511 --> 02:09:36,621
j n
3681
02:09:37,221 --> 02:09:37,551
and
3682
02:09:37,581 --> 02:09:39,112
then I can type a colon.
3683
02:09:39,202 --> 02:09:39,711
and
3684
02:09:39,741 --> 02:09:40,551
I want to type out
3685
02:09:40,581 --> 02:09:44,211
the value I want to associate with it so we can say in january.
3686
02:09:44,452 --> 02:09:48,083
I could basically do this for every combination so I could say like
3687
02:09:48,712 --> 02:09:49,462
you'd be
3688
02:09:49,762 --> 02:09:50,752
and this would be
3689
02:09:50,902 --> 02:09:51,802
february
3690
02:09:52,222 --> 02:09:55,162
and actually after each one of these we're going to need to put a comma.
3691
02:09:56,092 --> 02:09:59,662
so I could do the same for march soon say and they are.
3692
02:10:02,062 --> 02:10:06,083
so essentially what I can do is I can specify an entry
3693
02:10:06,323 --> 02:10:08,243
inside of this dictionary for
3694
02:10:08,273 --> 02:10:09,683
each one of these so
3695
02:10:09,863 --> 02:10:11,993
this over here would be the key
3696
02:10:12,292 --> 02:10:15,173
in this over here would be the value.
3697
02:10:15,653 --> 02:10:19,703
and here's one thing is all of these keys have to be unique.
3698
02:10:19,943 --> 02:10:23,063
so if I was to come down here and change this to j n,
3699
02:10:23,543 --> 02:10:27,233
this is actually going to give us a little warnings you can see down here it says
3700
02:10:27,503 --> 02:10:28,643
dictionary contains
3701
02:10:28,672 --> 02:10:29,272
duplicate
3702
02:10:29,302 --> 02:10:29,902
keys
3703
02:10:30,172 --> 02:10:32,842
dots they know no one we're creating dictionary so
3704
02:10:33,052 --> 02:10:34,132
you'll want to make sure that
3705
02:10:34,162 --> 02:10:35,842
the keys are unique
3706
02:10:35,992 --> 02:10:37,131
aren't so I'm gonna go ahead and
3707
02:10:37,161 --> 02:10:39,351
create one of these for each one of the months
3708
02:10:39,381 --> 02:10:41,361
and then we'll come back and we'll talk about it.
3709
02:10:42,861 --> 02:10:47,990
all right so I've gone ahead and created an entry for all twelve of the months so now
3710
02:10:48,260 --> 02:10:49,791
we have a bunch of unique
3711
02:10:49,820 --> 02:10:50,450
keys
3712
02:10:50,480 --> 02:10:53,150
and each one of those keys is associated with
3713
02:10:53,180 --> 02:10:54,410
a different value.
3714
02:10:54,860 --> 02:11:00,229
so this is the basics of creating a dictionary is we have a bunch of these different key value pairs.
3715
02:11:00,589 --> 02:11:03,019
and now what we can actually do is we can
3716
02:11:03,079 --> 02:11:04,339
access them from
3717
02:11:04,369 --> 02:11:06,259
inside of this dictionary ?
3718
02:11:06,649 --> 02:11:08,150
so if I wanted to access
3719
02:11:08,180 --> 02:11:08,930
a specific
3720
02:11:08,959 --> 02:11:10,759
key or a specific value.
3721
02:11:11,119 --> 02:11:13,609
all I have to do is come over here and I'm actually just going to
3722
02:11:13,639 --> 02:11:15,739
print it out onto the screen so we can see it.
3723
02:11:16,759 --> 02:11:20,780
all you have to do is referred to the dictionary by name so it's just called
3724
02:11:20,840 --> 02:11:22,250
month conversions.
3725
02:11:22,581 --> 02:11:23,000
and
3726
02:11:23,030 --> 02:11:25,220
there's actually a bunch of different ways
3727
02:11:25,250 --> 02:11:28,100
that I can access these month names,
3728
02:11:28,190 --> 02:11:28,700
so
3729
02:11:29,270 --> 02:11:30,140
I could access
3730
02:11:30,169 --> 02:11:32,329
different entries inside of this
3731
02:11:32,389 --> 02:11:32,959
dictionary ?
3732
02:11:33,199 --> 02:11:34,910
the first way is just by making
3733
02:11:34,939 --> 02:11:35,629
a
3734
02:11:35,750 --> 02:11:37,189
open close square bracket
3735
02:11:37,489 --> 02:11:40,338
inside here I can just type in one of the keys.
3736
02:11:40,579 --> 02:11:42,559
so for example inside here I could type in
3737
02:11:42,619 --> 02:11:42,918
and
3738
02:11:42,948 --> 02:11:43,638
oh thee.
3739
02:11:44,058 --> 02:11:46,789
and what this should do is it should give us back.
3740
02:11:46,849 --> 02:11:47,329
the
3741
02:11:47,358 --> 02:11:48,349
full
3742
02:11:48,438 --> 02:11:50,809
name for november so when I print this out,
3743
02:11:51,589 --> 02:11:53,870
you'll see that we get back down here.
3744
02:11:53,990 --> 02:11:54,770
nov.
3745
02:11:55,160 --> 02:11:56,840
so I can do the same thing for
3746
02:11:57,080 --> 02:11:59,210
any of these we can say like an a r.
3747
02:11:59,630 --> 02:12:01,880
and now we should get marched back so
3748
02:12:02,090 --> 02:12:04,580
I'm able to refer to the key,
3749
02:12:05,030 --> 02:12:06,951
and it's going to go into the dictionary and it's
3750
02:12:06,980 --> 02:12:10,191
going to give me the value that's associated to that qe
3751
02:12:10,821 --> 02:12:13,341
is actually another way we could do this too so I could
3752
02:12:13,401 --> 02:12:13,971
say
3753
02:12:14,001 --> 02:12:16,041
month conversions dot
3754
02:12:16,341 --> 02:12:17,061
get
3755
02:12:17,331 --> 02:12:21,711
an inside of here I could also pass in the name of the key so I could pass in like
3756
02:12:22,041 --> 02:12:23,211
d c
3757
02:12:24,081 --> 02:12:25,940
and now we'll be printing out
3758
02:12:26,000 --> 02:12:26,840
december.
3759
02:12:27,800 --> 02:12:30,021
and what's cool about using this get function
3760
02:12:30,051 --> 02:12:34,521
is I can actually specify a default value that I want to use.
3761
02:12:34,791 --> 02:12:36,651
if this keys not found so
3762
02:12:37,131 --> 02:12:41,122
there's going to be certain cases when we're dealing with dictionaries where you're going to put in a key
3763
02:12:41,151 --> 02:12:43,131
that might not necessarily
3764
02:12:43,191 --> 02:12:44,572
map to a value
3765
02:12:44,752 --> 02:12:47,302
inside of the dictionary you so he put in an invalid
3766
02:12:47,332 --> 02:12:47,752
key.
3767
02:12:48,142 --> 02:12:48,952
so let's just
3768
02:12:48,982 --> 02:12:51,502
try to do that so honest put like aliyu v.
3769
02:12:51,592 --> 02:12:52,372
that's not
3770
02:12:52,462 --> 02:12:53,782
a month abbreviation.
3771
02:12:54,022 --> 02:12:55,402
so when I try to run this,
3772
02:12:56,032 --> 02:12:57,382
you'll see we get this
3773
02:12:57,412 --> 02:12:58,072
none
3774
02:12:58,102 --> 02:12:58,792
down here.
3775
02:12:59,122 --> 02:13:00,232
and in a lot of cases
3776
02:13:00,262 --> 02:13:01,461
you're gonna want to
3777
02:13:01,491 --> 02:13:03,381
create some sort of a default
3778
02:13:03,411 --> 02:13:04,011
value.
3779
02:13:04,401 --> 02:13:07,162
so if I'm in this situation where I have a key
3780
02:13:07,192 --> 02:13:10,492
that's not mappable to any values inside of this
3781
02:13:10,521 --> 02:13:11,361
dictionary ?
3782
02:13:11,661 --> 02:13:14,001
I can actually pass it a default value.
3783
02:13:14,242 --> 02:13:16,491
so inside this dot get function
3784
02:13:16,521 --> 02:13:16,971
I can
3785
02:13:17,151 --> 02:13:17,961
make a comma.
3786
02:13:18,141 --> 02:13:22,461
and I can pass in like a default value to get printed out so I can say like not
3787
02:13:22,491 --> 02:13:23,301
a valid
3788
02:13:23,361 --> 02:13:23,931
key.
3789
02:13:24,531 --> 02:13:25,251
and now
3790
02:13:25,431 --> 02:13:28,582
when I put in the invalid key instead of saying none.
3791
02:13:28,882 --> 02:13:30,263
it's going to go ahead and say
3792
02:13:30,292 --> 02:13:31,552
not a valid
3793
02:13:31,582 --> 02:13:34,613
key and so this is going to give us like a default value
3794
02:13:34,883 --> 02:13:36,563
that we can fall back on so
3795
02:13:36,894 --> 02:13:38,934
these dictionaries are really awesome and
3796
02:13:40,014 --> 02:13:42,534
the keys over here don't have to be
3797
02:13:42,563 --> 02:13:44,634
strings so you could also use numbers
3798
02:13:44,904 --> 02:13:47,004
so for example I can see like zero
3799
02:13:47,484 --> 02:13:48,354
one
3800
02:13:48,685 --> 02:13:52,405
tan like I can put any numbers I want over here as keys
3801
02:13:52,615 --> 02:13:55,796
as long as their unique and that I could access those keys
3802
02:13:55,976 --> 02:13:58,077
just like I normally would down here
3803
02:13:58,317 --> 02:13:58,797
with this
3804
02:13:58,827 --> 02:14:01,587
get function or with those open and closed square brackets
3805
02:14:02,037 --> 02:14:03,297
so that's sort of the basics
3806
02:14:03,327 --> 02:14:05,906
of using dictionaries like me really useful to store
3807
02:14:05,936 --> 02:14:07,256
key value pairs
3808
02:14:07,616 --> 02:14:12,386
and honestly you're going to be using them a lot in python to store different types of data.
3809
02:14:16,856 --> 02:14:20,786
in this tutorial I wanna talk to you guys about wild loops in python,
3810
02:14:21,176 --> 02:14:21,326
and
3811
02:14:21,356 --> 02:14:26,696
a while loop is basically a structure in python which allows us to loop through
3812
02:14:26,937 --> 02:14:27,837
and execute
3813
02:14:27,867 --> 02:14:30,537
a block of code multiple times.
3814
02:14:30,897 --> 02:14:34,647
so I could specify like a few different lines of code and then I could
3815
02:14:34,677 --> 02:14:35,637
put that code
3816
02:14:35,697 --> 02:14:37,076
inside of a while loop
3817
02:14:37,586 --> 02:14:44,816
and it would basically you loop through that code executing it repeatedly until a certain condition was false.
3818
02:14:45,146 --> 02:14:51,537
so our lives can be awesome and there's a lot of situations in python where we're going to want to loop through specific lines of code,
3819
02:14:51,957 --> 02:14:54,657
so in this tutorial I just want to show you guys the healing
3820
02:14:54,717 --> 02:14:56,997
bare basics of how wildebeests work
3821
02:14:57,267 --> 02:15:01,797
and then in future tutorial is we're going to use while leaps to create little games and stuff like that so
3822
02:15:02,577 --> 02:15:04,408
let's talk about wild sum
3823
02:15:05,158 --> 02:15:06,448
when I create my wild loop.
3824
02:15:06,868 --> 02:15:08,907
the first thing I want to do actually
3825
02:15:09,207 --> 02:15:10,407
is create an
3826
02:15:10,437 --> 02:15:10,977
integer.
3827
02:15:11,157 --> 02:15:15,626
I'm basically creating a variable that's a number and you don't have to do this for a while
3828
02:15:15,656 --> 02:15:17,786
but just for our demonstration I'm going to.
3829
02:15:18,085 --> 02:15:19,046
so I'm going to call this,
3830
02:15:19,106 --> 02:15:19,646
I
3831
02:15:19,676 --> 02:15:21,416
am going to set it equal to one.
3832
02:15:22,166 --> 02:15:25,165
now what I wanna do is I want to create a while loop
3833
02:15:25,195 --> 02:15:26,784
so I'm basically just going to say.
3834
02:15:26,934 --> 02:15:27,744
while
3835
02:15:28,554 --> 02:15:29,064
and
3836
02:15:29,274 --> 02:15:31,284
over here I want to specify
3837
02:15:31,313 --> 02:15:31,854
a
3838
02:15:32,003 --> 02:15:32,843
condition,
3839
02:15:33,323 --> 02:15:36,924
and this is what's called our loop condition or you can also
3840
02:15:36,984 --> 02:15:38,245
refer to it as a loop
3841
02:15:38,274 --> 02:15:38,844
guard
3842
02:15:38,964 --> 02:15:42,265
and basically we are going to keep looping through the code
3843
02:15:42,354 --> 02:15:43,794
inside of the while loop.
3844
02:15:44,154 --> 02:15:46,705
as long as this condition is true.
3845
02:15:47,035 --> 02:15:50,245
so whatever condition I put in here as long as it's true
3846
02:15:50,485 --> 02:15:54,055
we're going to keep looping through the code inside the wild is I'm just going to say while
3847
02:15:54,745 --> 02:15:55,255
I
3848
02:15:55,735 --> 02:15:56,635
is less than
3849
02:15:56,665 --> 02:15:56,875
or
3850
02:15:56,904 --> 02:15:57,714
equal to
3851
02:15:57,984 --> 02:15:58,554
ten
3852
02:15:59,844 --> 02:16:01,164
and now I'm gonna put a
3853
02:16:01,344 --> 02:16:01,974
colon
3854
02:16:02,694 --> 02:16:04,044
and I'm gonna make a new line.
3855
02:16:04,314 --> 02:16:04,705
and so
3856
02:16:04,734 --> 02:16:08,634
anything that's below this while loop declaration and that's
3857
02:16:08,694 --> 02:16:09,564
indented
3858
02:16:09,864 --> 02:16:10,645
like this
3859
02:16:10,825 --> 02:16:12,595
is going to be considered code that's
3860
02:16:12,625 --> 02:16:14,875
inside the while loop and so that code
3861
02:16:15,115 --> 02:16:17,456
is going to get repeatedly executed
3862
02:16:17,696 --> 02:16:20,306
while this condition up here is true.
3863
02:16:20,696 --> 02:16:24,027
so I'm just gonna put a very simple line of code here where it's going to print
3864
02:16:24,057 --> 02:16:24,986
out the value of
3865
02:16:25,016 --> 02:16:25,556
I,
3866
02:16:26,126 --> 02:16:28,045
and then down here I'm going to actually
3867
02:16:28,075 --> 02:16:28,615
increment
3868
02:16:28,645 --> 02:16:30,145
eyes I'm going to add one
3869
02:16:30,175 --> 02:16:31,286
to eyes I must say
3870
02:16:31,346 --> 02:16:31,826
I
3871
02:16:32,126 --> 02:16:32,456
is
3872
02:16:32,516 --> 02:16:33,056
equal to
3873
02:16:33,086 --> 02:16:33,536
I
3874
02:16:33,596 --> 02:16:34,136
plus
3875
02:16:34,195 --> 02:16:34,766
one,
3876
02:16:35,006 --> 02:16:38,666
so basically I'm taking this I value and I'm adding one to it
3877
02:16:39,086 --> 02:16:42,057
is actually a shorthand that we can use in
3878
02:16:42,207 --> 02:16:44,577
python to do something like this though I could just say
3879
02:16:44,607 --> 02:16:45,207
I
3880
02:16:45,537 --> 02:16:46,018
plus
3881
02:16:46,048 --> 02:16:47,008
equals one
3882
02:16:47,368 --> 02:16:49,619
and not automatically going to add one
3883
02:16:49,649 --> 02:16:50,369
to
3884
02:16:50,459 --> 02:16:50,819
I
3885
02:16:50,850 --> 02:16:52,408
so this is like a little shorthand and
3886
02:16:52,618 --> 02:16:54,778
you'll see people in pipe on using that a lot.
3887
02:16:55,469 --> 02:16:55,919
so
3888
02:16:56,219 --> 02:16:58,348
over here we basically have
3889
02:16:58,378 --> 02:17:00,088
our wild lives I have
3890
02:17:00,778 --> 02:17:04,198
the outline for a while lives we're defining this variable up here
3891
02:17:04,528 --> 02:17:06,989
and we're going to keep looping through the code
3892
02:17:07,049 --> 02:17:08,399
inside the while loop.
3893
02:17:08,669 --> 02:17:11,280
as long as this condition up here
3894
02:17:11,431 --> 02:17:12,151
is true.
3895
02:17:12,392 --> 02:17:15,031
so if this condition is false for example if
3896
02:17:15,062 --> 02:17:15,602
I
3897
02:17:15,752 --> 02:17:16,622
is equal to
3898
02:17:16,682 --> 02:17:17,401
eleven,
3899
02:17:17,731 --> 02:17:21,061
then we're not going to loop through this company more than just going to move on.
3900
02:17:21,421 --> 02:17:23,520
so down here I'm actually just going to print
3901
02:17:25,140 --> 02:17:26,430
done with loop.
3902
02:17:27,000 --> 02:17:29,011
so this was kind of illustrate this for us.
3903
02:17:29,730 --> 02:17:33,240
so let's go ahead and run this program I'm just gonna run it
3904
02:17:34,110 --> 02:17:34,561
and
3905
02:17:34,591 --> 02:17:36,479
you'll see down here we get some
3906
02:17:36,510 --> 02:17:37,710
output so
3907
02:17:38,400 --> 02:17:39,690
we're actually going to get
3908
02:17:39,900 --> 02:17:41,670
numbers printed out one
3909
02:17:41,700 --> 02:17:42,749
all the way down
3910
02:17:42,779 --> 02:17:43,619
through
3911
02:17:43,739 --> 02:17:44,459
ten
3912
02:17:44,759 --> 02:17:46,949
and then were printing out done with loop
3913
02:17:47,279 --> 02:17:50,669
so basically what's happening is we're printing out
3914
02:17:50,909 --> 02:17:52,559
every time we go through this loop
3915
02:17:52,589 --> 02:17:52,949
so
3916
02:17:53,129 --> 02:17:55,078
initially I is equal to one right.
3917
02:17:55,348 --> 02:17:58,317
the first thing that python's going to do when it gets to this while loop
3918
02:17:58,348 --> 02:18:00,057
is it's going to check this condition.
3919
02:18:00,236 --> 02:18:01,915
so before it does anything else,
3920
02:18:02,095 --> 02:18:04,074
it's going to check this condition and it's going to say
3921
02:18:04,104 --> 02:18:04,524
okay,
3922
02:18:04,914 --> 02:18:05,395
is
3923
02:18:05,425 --> 02:18:06,145
one
3924
02:18:06,175 --> 02:18:07,556
less than or equal to ten.
3925
02:18:08,006 --> 02:18:08,937
and that's true.
3926
02:18:09,116 --> 02:18:10,795
so as long as this guy is
3927
02:18:10,825 --> 02:18:11,365
true
3928
02:18:11,396 --> 02:18:13,976
we're going to go through and loop through all the code inside of here.
3929
02:18:14,186 --> 02:18:15,175
so we're going to print out
3930
02:18:15,205 --> 02:18:15,625
I
3931
02:18:15,655 --> 02:18:16,975
which has the value of one
3932
02:18:17,574 --> 02:18:18,175
and then we're going to
3933
02:18:18,205 --> 02:18:19,015
add one
3934
02:18:19,045 --> 02:18:21,386
to I so now I'm going to go from one
3935
02:18:21,416 --> 02:18:22,166
to two.
3936
02:18:22,616 --> 02:18:23,876
now what we're going to do
3937
02:18:24,116 --> 02:18:26,396
is we're going to go all the way back up here
3938
02:18:26,426 --> 02:18:27,565
to this while loop
3939
02:18:27,865 --> 02:18:30,086
declaration and we're gonna check the condition
3940
02:18:30,116 --> 02:18:30,776
again.
3941
02:18:31,526 --> 02:18:33,086
so remember I checked the condition
3942
02:18:33,116 --> 02:18:33,776
first time
3943
02:18:33,807 --> 02:18:35,188
and then I looped through all the code,
3944
02:18:35,338 --> 02:18:36,987
then I'd go back up to the top
3945
02:18:37,018 --> 02:18:38,729
and I check it again so I'm gonna say
3946
02:18:38,760 --> 02:18:39,149
ok
3947
02:18:39,510 --> 02:18:41,460
is I less than or equal to ten
3948
02:18:41,880 --> 02:18:42,839
at this point
3949
02:18:42,959 --> 02:18:44,069
I is equal to two
3950
02:18:44,459 --> 02:18:46,168
so I is less than or equal to tenant.
3951
02:18:46,498 --> 02:18:48,147
so now we're going to go through and will
3952
02:18:48,178 --> 02:18:50,217
execute all this code again so I'm going to
3953
02:18:50,247 --> 02:18:50,787
print out
3954
02:18:50,817 --> 02:18:52,106
I so it's going to be too
3955
02:18:52,496 --> 02:18:53,847
and I'm going to add one to eye
3956
02:18:53,877 --> 02:18:55,076
so now we have three
3957
02:18:55,616 --> 02:18:56,066
then
3958
02:18:56,097 --> 02:18:58,677
python's going to go all the way back up to the top
3959
02:18:58,707 --> 02:18:59,607
and it's going to check
3960
02:18:59,667 --> 02:19:01,018
the condition again
3961
02:19:01,287 --> 02:19:01,797
so
3962
02:19:02,037 --> 02:19:03,988
on every iteration through the loop
3963
02:19:04,019 --> 02:19:05,278
before python
3964
02:19:05,368 --> 02:19:06,957
does what's inside of this loop
3965
02:19:06,987 --> 02:19:08,427
it's going to check that condition.
3966
02:19:08,937 --> 02:19:11,307
and as long as the condition remains true.
3967
02:19:11,366 --> 02:19:11,877
we're going to
3968
02:19:11,907 --> 02:19:13,886
keep executing the code inside the loop
3969
02:19:14,366 --> 02:19:15,896
eventually though in this program
3970
02:19:15,956 --> 02:19:18,057
I is going to end up being eleven
3971
02:19:18,326 --> 02:19:18,716
right
3972
02:19:18,806 --> 02:19:19,615
so I'm the last
3973
02:19:19,646 --> 02:19:21,806
iteration it's going to end up being levin,
3974
02:19:22,075 --> 02:19:23,455
we're going to come back up here,
3975
02:19:23,635 --> 02:19:24,504
and we're going to say
3976
02:19:24,534 --> 02:19:24,895
hum
3977
02:19:24,925 --> 02:19:26,726
is eleven less than or equal to ten
3978
02:19:27,025 --> 02:19:27,535
nope
3979
02:19:27,955 --> 02:19:29,245
and so sense it's nope
3980
02:19:29,275 --> 02:19:30,386
we're going to come down here
3981
02:19:30,416 --> 02:19:35,785
and we'll print out this done with loop line so that's the basics of how these wildebeests work
3982
02:19:36,085 --> 02:19:38,156
we're specifying a loop condition.
3983
02:19:38,396 --> 02:19:40,106
as long as that conditions true
3984
02:19:40,376 --> 02:19:41,875
will keep executing the code
3985
02:19:41,905 --> 02:19:43,046
inside of the loop,
3986
02:19:43,226 --> 02:19:45,385
and after every execution of the loop,
3987
02:19:45,444 --> 02:19:47,635
we're going to come back up and check the condition again so
3988
02:19:47,904 --> 02:19:49,613
that's how we end up with
3989
02:19:49,644 --> 02:19:50,424
this.
3990
02:19:50,574 --> 02:19:51,444
printing out
3991
02:19:51,475 --> 02:19:52,195
down here,
3992
02:19:52,646 --> 02:19:53,785
so that's the basics
3993
02:19:53,815 --> 02:19:54,176
of
3994
02:19:54,206 --> 02:19:54,866
a while loop
3995
02:19:54,896 --> 02:19:55,286
and
3996
02:19:55,946 --> 02:19:57,387
we can use these volumes to do
3997
02:19:57,417 --> 02:20:00,806
all sorts of things like wild fruits are very very powerful
3998
02:20:04,706 --> 02:20:07,587
in this tutorial on a show he eyes how to build a basic
3999
02:20:07,617 --> 02:20:09,387
guessing game in python,
4000
02:20:09,896 --> 02:20:15,090
and in this guessing game we're actually going to be using all sorts of cool programming structures that we've
4001
02:20:15,120 --> 02:20:16,859
learned up to this point in the course.
4002
02:20:17,159 --> 02:20:18,539
so we're going to be using things like
4003
02:20:18,599 --> 02:20:21,208
if statements and wild loops and variables and
4004
02:20:21,268 --> 02:20:22,258
all these cool things
4005
02:20:22,588 --> 02:20:24,537
in order to build this game so,
4006
02:20:24,597 --> 02:20:28,437
the basic idea is we will specify lake a secret word.
4007
02:20:28,677 --> 02:20:31,707
so we'll have a secret word that we store inside of our program
4008
02:20:32,127 --> 02:20:35,428
and then the user can interact with the program and try to guess
4009
02:20:35,458 --> 02:20:36,509
the secret word.
4010
02:20:36,839 --> 02:20:41,038
and so what we want to be able to happen is we want the user to be able to keep guessing
4011
02:20:41,068 --> 02:20:44,188
what the secret where it is and keep typing in different responses.
4012
02:20:44,607 --> 02:20:46,947
until they get the secret word right.
4013
02:20:47,188 --> 02:20:48,358
so that's the basics
4014
02:20:48,389 --> 02:20:50,158
of what this game is going to be.
4015
02:20:50,668 --> 02:20:51,088
and
4016
02:20:51,118 --> 02:20:54,449
now let's go ahead and create it so the first thing we want to do is
4017
02:20:54,479 --> 02:20:57,871
create a variable to store our secret word.
4018
02:20:58,171 --> 02:20:59,220
so I can say
4019
02:20:59,399 --> 02:21:00,119
secret
4020
02:21:00,149 --> 02:21:00,779
word.
4021
02:21:01,199 --> 02:21:04,920
and we're just going to set this equal to a secret word so why don't we make it a draft.
4022
02:21:04,979 --> 02:21:06,149
that's a pretty good secret word.
4023
02:21:06,899 --> 02:21:10,859
and now what we wanna do is want to create a variable that will store
4024
02:21:10,890 --> 02:21:12,750
the user's response
4025
02:21:13,020 --> 02:21:15,931
so I want a variable that will store like all the guesses
4026
02:21:15,961 --> 02:21:17,131
that the user makes
4027
02:21:17,161 --> 02:21:18,062
so I'm just gonna
4028
02:21:18,093 --> 02:21:18,813
call this
4029
02:21:18,873 --> 02:21:19,653
guess
4030
02:21:20,043 --> 02:21:20,433
and
4031
02:21:20,463 --> 02:21:21,062
I'm just going to set it
4032
02:21:21,093 --> 02:21:23,312
equal to an empty string right now.
4033
02:21:23,433 --> 02:21:23,793
so
4034
02:21:23,823 --> 02:21:25,202
now we have a secret word
4035
02:21:25,232 --> 02:21:25,893
and we have
4036
02:21:25,923 --> 02:21:28,744
a variable to store the user's guess
4037
02:21:29,014 --> 02:21:31,473
and what we need to do is we need to be able to prompt
4038
02:21:31,503 --> 02:21:32,343
the user
4039
02:21:32,493 --> 02:21:33,933
to input the secret were.
4040
02:21:34,383 --> 02:21:35,612
but here's the catch.
4041
02:21:36,032 --> 02:21:39,331
what we want to happen is we want them to enter the secret word.
4042
02:21:39,571 --> 02:21:41,671
and if they don't guess it correctly
4043
02:21:41,701 --> 02:21:44,072
we want to prompt them to enter it again.
4044
02:21:44,553 --> 02:21:47,162
so we can't just use a single
4045
02:21:47,192 --> 02:21:49,593
input statement we actually have to use
4046
02:21:49,772 --> 02:21:51,482
something called a while loop.
4047
02:21:51,843 --> 02:21:53,251
and we can use a while loop
4048
02:21:53,281 --> 02:21:56,161
in order to continually ask the person
4049
02:21:56,341 --> 02:21:57,361
to guess the word
4050
02:21:57,541 --> 02:21:59,371
until they guess it correctly.
4051
02:21:59,791 --> 02:22:03,060
so let's go ahead and create our while loop so I'm gonna say while
4052
02:22:03,449 --> 02:22:03,810
and
4053
02:22:03,899 --> 02:22:08,879
after a while I need to specify a looping condition or a looping guard.
4054
02:22:09,209 --> 02:22:10,709
basically this is something
4055
02:22:10,739 --> 02:22:12,449
that as long as it's true
4056
02:22:12,479 --> 02:22:14,431
we're going to keep looping through
4057
02:22:14,490 --> 02:22:15,061
this loop.
4058
02:22:15,301 --> 02:22:17,131
so basically I want to say
4059
02:22:17,161 --> 02:22:19,382
I want to keep looping as long as
4060
02:22:19,622 --> 02:22:21,092
the user's gas
4061
02:22:21,242 --> 02:22:22,772
is not equal to
4062
02:22:23,223 --> 02:22:24,304
the secret word.
4063
02:22:24,604 --> 02:22:26,674
so as long as they haven't guessed
4064
02:22:26,704 --> 02:22:27,814
the secret word.
4065
02:22:28,114 --> 02:22:30,214
I'm going to keep going through this loop,
4066
02:22:30,634 --> 02:22:32,194
and inside this loop.
4067
02:22:32,314 --> 02:22:35,796
what we're going to do is we're going to ask them to input the secret word
4068
02:22:36,246 --> 02:22:37,415
so I can take this
4069
02:22:37,445 --> 02:22:38,795
gas variable
4070
02:22:39,035 --> 02:22:39,995
and I can set it
4071
02:22:40,025 --> 02:22:40,865
equal to
4072
02:22:41,436 --> 02:22:42,155
input.
4073
02:22:42,995 --> 02:22:44,016
and I'm just going to say.
4074
02:22:44,586 --> 02:22:45,276
enter
4075
02:22:45,517 --> 02:22:46,207
guess.
4076
02:22:47,438 --> 02:22:51,518
and so over here we're basically telling the user to enter in their guests.
4077
02:22:51,938 --> 02:22:54,008
I'm storing whenever they enter
4078
02:22:54,248 --> 02:22:55,808
inside of this guess
4079
02:22:55,867 --> 02:22:56,707
variable
4080
02:22:57,007 --> 02:22:59,467
and then what's going to happen is that we're going to come back up here
4081
02:22:59,677 --> 02:23:00,066
we're going to
4082
02:23:00,097 --> 02:23:01,508
check to see if the gas
4083
02:23:01,538 --> 02:23:03,158
is equal to the secret word
4084
02:23:03,578 --> 02:23:04,179
if the guests
4085
02:23:04,209 --> 02:23:05,708
isn't equal to the secret word,
4086
02:23:05,888 --> 02:23:06,997
then we're going to do it again.
4087
02:23:07,567 --> 02:23:08,617
but if the guests
4088
02:23:08,647 --> 02:23:10,087
is equal to the secret word,
4089
02:23:10,146 --> 02:23:11,436
then we're just going to break
4090
02:23:11,466 --> 02:23:12,485
out of this loop.
4091
02:23:13,205 --> 02:23:14,945
and so we can come down here
4092
02:23:15,815 --> 02:23:17,225
and we can just print out
4093
02:23:17,675 --> 02:23:19,445
a success message so I could say
4094
02:23:19,806 --> 02:23:20,616
you win
4095
02:23:20,946 --> 02:23:22,746
because they got the secret were
4096
02:23:23,016 --> 02:23:25,086
since they have very very simple program
4097
02:23:25,116 --> 02:23:25,566
but
4098
02:23:25,956 --> 02:23:30,037
this is essentially all of the code that we need to be able to build a game
4099
02:23:30,067 --> 02:23:31,117
like this so
4100
02:23:31,297 --> 02:23:33,877
let's go ahead and play our game we can run it and
4101
02:23:33,907 --> 02:23:35,617
see how he did so I'm gonna
4102
02:23:35,647 --> 02:23:36,397
click play.
4103
02:23:37,298 --> 02:23:42,067
and down here you can see it's prompting us to enter a guest's so I'm just going to type in some
4104
02:23:42,098 --> 02:23:43,238
you know random texts
4105
02:23:43,568 --> 02:23:44,888
we can type in whatever you want.
4106
02:23:45,218 --> 02:23:49,867
and as long as we're not entering that secret word it's going to keep prompting us to
4107
02:23:49,897 --> 02:23:51,607
enter different information.
4108
02:23:52,058 --> 02:23:52,567
but
4109
02:23:52,598 --> 02:23:54,066
if I enter in the secret word
4110
02:23:54,097 --> 02:23:55,416
so if I enter in draft.
4111
02:23:55,986 --> 02:23:56,526
now
4112
02:23:56,586 --> 02:23:59,467
all of a sudden the programs can terminate and it's going to say,
4113
02:23:59,677 --> 02:24:00,066
hey
4114
02:24:00,097 --> 02:24:00,757
you win
4115
02:24:01,057 --> 02:24:02,857
because we were able to guess
4116
02:24:02,917 --> 02:24:03,847
the secret word.
4117
02:24:04,087 --> 02:24:04,807
so that's like
4118
02:24:04,866 --> 02:24:07,807
a really cool way for us to be able to do this.
4119
02:24:07,957 --> 02:24:10,927
and we actually have a fully functional guessing game.
4120
02:24:11,437 --> 02:24:11,977
but
4121
02:24:12,246 --> 02:24:16,116
I think this guessing game could actually be improved quite a bit.
4122
02:24:16,446 --> 02:24:18,006
a lot of times when
4123
02:24:18,036 --> 02:24:20,736
we're making a guessing game we want to set a limit
4124
02:24:20,767 --> 02:24:23,347
so in other words I want to set a limit for
4125
02:24:23,497 --> 02:24:26,498
the number of times that the user can try to guess the word.
4126
02:24:26,918 --> 02:24:28,509
so let's say that the user has
4127
02:24:28,539 --> 02:24:31,868
three tries right they have three guesses in order to guess the word.
4128
02:24:32,168 --> 02:24:34,628
and if they can't guess the word after three tries.
4129
02:24:34,838 --> 02:24:36,278
then they're going to lose the game.
4130
02:24:36,519 --> 02:24:36,938
but
4131
02:24:37,028 --> 02:24:38,048
if they can guess the word
4132
02:24:38,078 --> 02:24:39,697
inside of three tries then
4133
02:24:39,728 --> 02:24:40,987
they'll win the game right.
4134
02:24:41,197 --> 02:24:44,346
I think that will be a little bit more of a fun game so
4135
02:24:44,376 --> 02:24:45,666
why don't we try to program
4136
02:24:45,696 --> 02:24:46,446
that game,
4137
02:24:46,716 --> 02:24:48,726
basically we're going to set a limit
4138
02:24:48,966 --> 02:24:49,596
on the number of
4139
02:24:49,626 --> 02:24:50,286
guesses
4140
02:24:50,316 --> 02:24:51,756
that the user can have
4141
02:24:51,996 --> 02:24:57,096
in order to do this and we're going to have to create a couple more variables down here.
4142
02:24:57,396 --> 02:24:57,995
in other words
4143
02:24:58,025 --> 02:25:01,054
we're going to have to store a couple more pieces of information.
4144
02:25:01,504 --> 02:25:04,294
the first piece of information I want to keep track of is
4145
02:25:04,474 --> 02:25:06,063
how many times the user
4146
02:25:06,094 --> 02:25:07,174
has guessed
4147
02:25:07,264 --> 02:25:07,653
right,
4148
02:25:07,894 --> 02:25:10,234
so we can just make a variable called guests
4149
02:25:10,265 --> 02:25:10,774
cao
4150
02:25:11,164 --> 02:25:13,653
and we'll just set this equal to zero because initially
4151
02:25:13,983 --> 02:25:15,033
the user won't have
4152
02:25:15,063 --> 02:25:15,634
guest
4153
02:25:15,784 --> 02:25:17,434
down in this while loop.
4154
02:25:17,644 --> 02:25:19,833
every time we go through the loop,
4155
02:25:20,253 --> 02:25:22,263
I want to increment that gas can
4156
02:25:22,743 --> 02:25:24,963
write so every time we've gone through this while loop
4157
02:25:24,993 --> 02:25:25,593
I want to
4158
02:25:25,623 --> 02:25:27,452
increment that count because that means
4159
02:25:27,632 --> 02:25:29,252
the user will have guessed
4160
02:25:29,552 --> 02:25:31,262
so down here I'm going to say.
4161
02:25:31,712 --> 02:25:32,252
guess
4162
02:25:32,282 --> 02:25:32,792
count
4163
02:25:34,382 --> 02:25:34,892
plus
4164
02:25:34,922 --> 02:25:36,062
equals one
4165
02:25:36,302 --> 02:25:37,473
and this is just going to add
4166
02:25:37,503 --> 02:25:39,812
one to the gasket actually whips.
4167
02:25:41,191 --> 02:25:41,611
so
4168
02:25:42,092 --> 02:25:45,812
after each iteration of this loop we're going to go ahead and add one
4169
02:25:45,843 --> 02:25:46,953
to the gas count
4170
02:25:47,104 --> 02:25:50,374
right so that's the first variable that we're going to need we're also going to want to
4171
02:25:50,434 --> 02:25:52,383
store another variable
4172
02:25:52,413 --> 02:25:54,273
and this is going to be called guess
4173
02:25:54,304 --> 02:25:54,903
limit
4174
02:25:55,233 --> 02:26:01,145
and basically this is going to tell us how many times the user can guess the words on it it's going to be guests
4175
02:26:01,744 --> 02:26:02,254
limit
4176
02:26:02,284 --> 02:26:02,794
and
4177
02:26:03,334 --> 02:26:06,995
will basically just say three so let's say that the user has three tries
4178
02:26:07,205 --> 02:26:09,935
to guess the word three strikes and you're out so
4179
02:26:10,564 --> 02:26:13,025
the user if they can't get it in three tries
4180
02:26:13,056 --> 02:26:13,565
then
4181
02:26:13,596 --> 02:26:14,046
we're going to
4182
02:26:14,076 --> 02:26:15,968
basically say that they lose the game.
4183
02:26:16,208 --> 02:26:18,428
and I'm also going to need one more
4184
02:26:18,487 --> 02:26:19,837
variable here,
4185
02:26:20,317 --> 02:26:20,647
which
4186
02:26:20,678 --> 02:26:21,428
we're going to call
4187
02:26:21,458 --> 02:26:21,938
out
4188
02:26:22,419 --> 02:26:22,959
of
4189
02:26:23,649 --> 02:26:24,399
gases.
4190
02:26:24,789 --> 02:26:25,149
and
4191
02:26:25,180 --> 02:26:27,850
I'm just going to set this equal to false initially.
4192
02:26:28,119 --> 02:26:28,629
so this
4193
02:26:28,659 --> 02:26:31,300
out of gases variable is going to be a boolean.
4194
02:26:31,540 --> 02:26:34,780
and it's gonna tell us whether or not the user is out of gases.
4195
02:26:34,990 --> 02:26:36,790
so if out of gases is true
4196
02:26:36,820 --> 02:26:40,239
that means they have no more guesses right they basically lost the game
4197
02:26:40,810 --> 02:26:42,039
and if out of guesses
4198
02:26:42,099 --> 02:26:46,601
is false that means that they still have some guesses left so they can keep playing.
4199
02:26:47,320 --> 02:26:50,711
so let's use these different variables in order to
4200
02:26:50,741 --> 02:26:52,871
make our program or functional so
4201
02:26:53,381 --> 02:26:55,151
the first thing I want to do is
4202
02:26:55,722 --> 02:26:57,281
when I go through this loop.
4203
02:26:57,371 --> 02:27:00,911
I want to check to make sure that the user has more guesses,
4204
02:27:01,301 --> 02:27:01,661
right
4205
02:27:01,871 --> 02:27:04,363
in other words before I let the user
4206
02:27:04,394 --> 02:27:05,563
enter a gasp.
4207
02:27:05,833 --> 02:27:09,401
I want to check to see that they haven't already used up all their guesses.
4208
02:27:09,701 --> 02:27:10,691
so down here
4209
02:27:10,722 --> 02:27:12,281
I can make an if statement I can say
4210
02:27:12,312 --> 02:27:12,792
if
4211
02:27:13,302 --> 02:27:15,972
and inside of the condition I want to check to see that
4212
02:27:16,302 --> 02:27:16,901
guess
4213
02:27:16,961 --> 02:27:17,501
count
4214
02:27:18,611 --> 02:27:19,751
is less then
4215
02:27:20,201 --> 02:27:20,951
guess
4216
02:27:21,041 --> 02:27:21,551
limit
4217
02:27:22,661 --> 02:27:25,031
if gas count is less than guess limit.
4218
02:27:25,301 --> 02:27:26,651
that means that they haven't
4219
02:27:26,711 --> 02:27:27,341
guessed
4220
02:27:27,371 --> 02:27:27,761
the
4221
02:27:27,791 --> 02:27:31,333
total number of guesses that they have so they have some guesses left.
4222
02:27:31,873 --> 02:27:32,263
and
4223
02:27:32,293 --> 02:27:34,212
if that's the case and if that's true,
4224
02:27:34,602 --> 02:27:36,282
then I'm going to go ahead and
4225
02:27:37,572 --> 02:27:40,094
give them a guess and then we'll increment the guest count.
4226
02:27:40,724 --> 02:27:43,153
if this isn't true in other words,
4227
02:27:43,213 --> 02:27:43,992
if they
4228
02:27:44,022 --> 02:27:45,763
have reached their guests limit,
4229
02:27:46,213 --> 02:27:47,593
then I'm going to want to set
4230
02:27:47,652 --> 02:27:48,162
out
4231
02:27:48,492 --> 02:27:48,973
of
4232
02:27:49,423 --> 02:27:50,232
guesses
4233
02:27:50,652 --> 02:27:51,373
equal to
4234
02:27:51,403 --> 02:27:51,974
true
4235
02:27:52,334 --> 02:27:55,153
because there are guesses right they have no more guesses because
4236
02:27:55,333 --> 02:27:58,005
the gas count wasn't less than the guest limit.
4237
02:27:58,425 --> 02:28:01,334
and so that means that there are two gases so they have no more gases.
4238
02:28:01,394 --> 02:28:02,473
so there's actually
4239
02:28:02,683 --> 02:28:05,023
one more thing we need to do inside of this while loop
4240
02:28:05,054 --> 02:28:05,863
we need to
4241
02:28:05,894 --> 02:28:07,333
add another condition
4242
02:28:07,603 --> 02:28:08,863
onto this loop guard.
4243
02:28:09,104 --> 02:28:12,283
so right now we're going to keep looping as long as the guest
4244
02:28:12,313 --> 02:28:14,113
is not equal to the secret word
4245
02:28:14,533 --> 02:28:15,674
but remember
4246
02:28:15,914 --> 02:28:20,175
if the users out of gases in other words if they've reached their gas limit
4247
02:28:20,505 --> 02:28:22,185
we don't want them to guess anymore,
4248
02:28:22,274 --> 02:28:24,283
right so if they ran out of gas is then
4249
02:28:24,493 --> 02:28:28,603
we want to basically break out of this loop and not give them anymore guesses so
4250
02:28:28,633 --> 02:28:30,941
I'm going to go ahead and add another condition onto here
4251
02:28:31,331 --> 02:28:32,230
and I'm gonna say
4252
02:28:32,320 --> 02:28:32,801
wow
4253
02:28:32,831 --> 02:28:34,722
they haven't guessed the secret word
4254
02:28:34,781 --> 02:28:35,411
and
4255
02:28:35,471 --> 02:28:36,610
they're not
4256
02:28:37,120 --> 02:28:37,660
out
4257
02:28:38,021 --> 02:28:40,061
of gases so it's going to be not
4258
02:28:40,091 --> 02:28:40,811
out
4259
02:28:41,261 --> 02:28:42,011
of
4260
02:28:42,221 --> 02:28:43,001
guesses,
4261
02:28:43,661 --> 02:28:44,291
then
4262
02:28:44,891 --> 02:28:50,920
we're going to keep looping so as long as they haven't guessed the word and as long as they still have some guesses laugh we're going to keep looping
4263
02:28:51,010 --> 02:28:51,460
but
4264
02:28:51,940 --> 02:28:52,750
otherwise
4265
02:28:52,780 --> 02:28:54,011
we're going to break out of the loop.
4266
02:28:54,280 --> 02:28:55,571
and so down here
4267
02:28:55,812 --> 02:28:57,672
we're printing out you win,
4268
02:28:58,122 --> 02:29:00,792
but actually when we break out of this loop,
4269
02:29:00,852 --> 02:29:02,021
there's going to be two
4270
02:29:02,051 --> 02:29:03,461
possible scenarios.
4271
02:29:03,671 --> 02:29:04,331
so again,
4272
02:29:04,541 --> 02:29:07,780
there's two possible ways that this loop could andrei
4273
02:29:08,050 --> 02:29:10,210
either the gas is equal to the secret word.
4274
02:29:10,420 --> 02:29:13,060
so either the user guests of the word correctly,
4275
02:29:13,359 --> 02:29:14,050
or
4276
02:29:14,109 --> 02:29:16,180
the user ran out of guesses
4277
02:29:16,479 --> 02:29:17,020
and so
4278
02:29:17,199 --> 02:29:19,238
there's two situations down here
4279
02:29:19,479 --> 02:29:20,769
that we need to account for.
4280
02:29:21,129 --> 02:29:23,348
and so I'm going to use an if statement to figure out
4281
02:29:23,438 --> 02:29:23,857
which
4282
02:29:23,888 --> 02:29:24,967
is which I'm going to say
4283
02:29:24,997 --> 02:29:25,507
if.
4284
02:29:25,927 --> 02:29:26,856
and we're just going to say,
4285
02:29:26,946 --> 02:29:27,456
out
4286
02:29:27,876 --> 02:29:28,476
of
4287
02:29:28,716 --> 02:29:29,525
gases,
4288
02:29:30,726 --> 02:29:31,115
and,
4289
02:29:31,175 --> 02:29:32,796
if the user is out of guesses
4290
02:29:32,826 --> 02:29:33,845
that I want to print,
4291
02:29:36,545 --> 02:29:37,385
you lose
4292
02:29:37,415 --> 02:29:38,494
so we're basically going to be like
4293
02:29:38,524 --> 02:29:39,574
you lost the game.
4294
02:29:40,324 --> 02:29:41,435
otherwise though
4295
02:29:41,494 --> 02:29:42,154
if they're not
4296
02:29:42,185 --> 02:29:43,294
out of gases.
4297
02:29:43,534 --> 02:29:45,845
that means that they guessed the word correctly
4298
02:29:45,875 --> 02:29:46,955
so we're just going to pronounce
4299
02:29:46,985 --> 02:29:47,525
you win.
4300
02:29:48,695 --> 02:29:52,535
all right so now we have all the logic for this little guessing game set up
4301
02:29:52,565 --> 02:29:55,534
and let's see if we can run it and play through it so
4302
02:29:56,374 --> 02:29:57,755
I'm just going to run this program.
4303
02:29:58,564 --> 02:30:00,635
and now it's going to tell us to enter a guess
4304
02:30:00,665 --> 02:30:01,835
so why don't we
4305
02:30:01,895 --> 02:30:05,944
enter more guesses than we have so we're going to try to lose the game so I'm going to enter one gas
4306
02:30:06,274 --> 02:30:07,114
two guesses.
4307
02:30:07,324 --> 02:30:10,805
and now I'm on my final guess so if I don't get it here,
4308
02:30:11,135 --> 02:30:12,725
we should actually lose the game.
4309
02:30:13,295 --> 02:30:14,435
and you can see it says
4310
02:30:14,465 --> 02:30:15,995
out of guesses you lose.
4311
02:30:16,115 --> 02:30:17,766
so we were able to guess it
4312
02:30:17,796 --> 02:30:19,716
in the number of trials that we had.
4313
02:30:20,346 --> 02:30:21,636
let's run the program again
4314
02:30:21,666 --> 02:30:23,046
and we'll try to win the game.
4315
02:30:23,105 --> 02:30:23,766
so
4316
02:30:23,825 --> 02:30:25,114
we'll get a couple wrong.
4317
02:30:25,475 --> 02:30:27,456
let's say we're on our last gas and unlike
4318
02:30:27,486 --> 02:30:28,777
okay I can do this
4319
02:30:29,107 --> 02:30:30,817
so I type in the word and
4320
02:30:31,087 --> 02:30:31,687
bam
4321
02:30:31,717 --> 02:30:33,066
we won the game so,
4322
02:30:33,876 --> 02:30:36,516
that's how we can basically create a game where we have
4323
02:30:36,546 --> 02:30:37,536
a guess limit
4324
02:30:37,566 --> 02:30:38,017
so
4325
02:30:38,557 --> 02:30:39,605
this is a lot of code
4326
02:30:39,636 --> 02:30:41,885
let me walk you guys through this one more time
4327
02:30:41,915 --> 02:30:44,555
so you can just get a full understanding of what we're doing
4328
02:30:45,064 --> 02:30:47,434
up here I created a few different variables
4329
02:30:47,464 --> 02:30:49,504
we created this secret word variable
4330
02:30:49,714 --> 02:30:51,574
and we created this guests variable.
4331
02:30:52,024 --> 02:30:52,624
then
4332
02:30:52,894 --> 02:30:54,124
we also created
4333
02:30:54,154 --> 02:30:56,405
some more variable so we created this guests
4334
02:30:56,436 --> 02:30:57,455
count variable.
4335
02:30:57,725 --> 02:31:00,935
and this just keeps track of how many times the user has
4336
02:31:01,085 --> 02:31:01,745
guessed
4337
02:31:01,805 --> 02:31:02,495
the word.
4338
02:31:02,825 --> 02:31:04,296
and you can see down here.
4339
02:31:04,656 --> 02:31:05,557
every time
4340
02:31:05,587 --> 02:31:07,086
we give them a gas
4341
02:31:07,956 --> 02:31:08,946
were incremental
4342
02:31:08,977 --> 02:31:09,727
the guest count.
4343
02:31:10,536 --> 02:31:11,706
we also have guests
4344
02:31:11,736 --> 02:31:12,276
limit
4345
02:31:12,576 --> 02:31:16,688
and gas limit is telling the program how many times the user can guess.
4346
02:31:17,197 --> 02:31:22,178
so before I go through this while loop the first thing I'm doing is I'm checking to see that the guest
4347
02:31:22,208 --> 02:31:22,718
count
4348
02:31:23,048 --> 02:31:24,487
is less than the guests limit.
4349
02:31:24,787 --> 02:31:25,628
in other words
4350
02:31:25,778 --> 02:31:27,759
do they still have some guesses
4351
02:31:27,789 --> 02:31:28,389
left
4352
02:31:28,599 --> 02:31:29,679
if they do,
4353
02:31:30,009 --> 02:31:32,169
then we're going to get the input from the user.
4354
02:31:32,559 --> 02:31:33,639
otherwise,
4355
02:31:33,698 --> 02:31:34,388
we have this
4356
02:31:34,418 --> 02:31:36,158
other variable up here called
4357
02:31:36,188 --> 02:31:37,328
out of gases
4358
02:31:37,628 --> 02:31:41,347
and out of gases is going to tell us whether or not they have some guesses left.
4359
02:31:41,707 --> 02:31:43,237
so this is equal to false.
4360
02:31:43,297 --> 02:31:45,037
that means they have some guesses,
4361
02:31:45,397 --> 02:31:47,648
if it's equal to true however it means
4362
02:31:47,979 --> 02:31:48,849
no more dice
4363
02:31:48,879 --> 02:31:50,889
no more guesses they are done
4364
02:31:50,919 --> 02:31:52,059
so they lost the game.
4365
02:31:52,479 --> 02:31:56,558
the last thing we needed to do is specify an additional condition up here.
4366
02:31:57,038 --> 02:31:57,488
so
4367
02:31:57,519 --> 02:31:59,708
we are going to keep looping through the code
4368
02:31:59,738 --> 02:32:01,028
inside of this loop,
4369
02:32:01,418 --> 02:32:03,878
as long as the conditions up here
4370
02:32:04,088 --> 02:32:04,808
are true.
4371
02:32:05,527 --> 02:32:07,928
so as long as they haven't guessed the word.
4372
02:32:08,408 --> 02:32:08,979
and
4373
02:32:09,248 --> 02:32:10,598
as long as they're not
4374
02:32:10,657 --> 02:32:11,978
out of guesses.
4375
02:32:12,487 --> 02:32:13,718
we are going to keep
4376
02:32:13,748 --> 02:32:14,978
looping through.
4377
02:32:15,277 --> 02:32:15,968
and so
4378
02:32:16,027 --> 02:32:18,697
when eventually the user does break out of this loop,
4379
02:32:18,817 --> 02:32:23,319
there's going to be two possible situations the first situation is that they ran out of guesses
4380
02:32:23,350 --> 02:32:26,048
and so we want to check to see if that's the situation.
4381
02:32:26,408 --> 02:32:28,479
I want to check to see if they're out of guesses.
4382
02:32:28,748 --> 02:32:29,498
if they are
4383
02:32:29,528 --> 02:32:31,089
will print out a lose message,
4384
02:32:31,299 --> 02:32:32,079
if they're not,
4385
02:32:32,289 --> 02:32:34,208
then they must have guessed it correctly so
4386
02:32:34,268 --> 02:32:34,778
they win.
4387
02:32:34,929 --> 02:32:37,149
and so that is how we can use while loops
4388
02:32:37,180 --> 02:32:37,569
and
4389
02:32:37,600 --> 02:32:38,319
if statements
4390
02:32:38,350 --> 02:32:39,400
and also variables
4391
02:32:39,610 --> 02:32:42,762
in combination with each other to build a pretty awesome
4392
02:32:42,792 --> 02:32:43,542
guessing game
4393
02:32:47,922 --> 02:32:50,384
in this tutorial on a talk show guys by using
4394
02:32:50,414 --> 02:32:52,395
for loops in python.
4395
02:32:52,814 --> 02:32:53,654
now a for loop
4396
02:32:53,685 --> 02:32:57,256
is a special type of loop in python which allows us
4397
02:32:57,286 --> 02:33:00,076
to loop over a different collections
4398
02:33:00,376 --> 02:33:00,706
of
4399
02:33:00,736 --> 02:33:01,276
items.
4400
02:33:01,517 --> 02:33:06,194
so a lot of times will use for loops in python to like loop through different arrays
4401
02:33:06,464 --> 02:33:07,185
or we can loop
4402
02:33:07,215 --> 02:33:10,034
over like the letters inside of a string or
4403
02:33:10,214 --> 02:33:11,504
we could just loop through like
4404
02:33:11,534 --> 02:33:11,864
a
4405
02:33:12,194 --> 02:33:13,455
series of numbers
4406
02:33:13,635 --> 02:33:16,453
so for lives provide a very specific purpose.
4407
02:33:16,663 --> 02:33:18,973
and the easiest way to kind of wrap your head around
4408
02:33:19,003 --> 02:33:21,372
why four lives are useful as it is for me to show you guys
4409
02:33:21,672 --> 02:33:23,021
a bunch of different examples so
4410
02:33:23,052 --> 02:33:24,672
that's exactly what I'm going to do,
4411
02:33:25,062 --> 02:33:29,291
we're going to look at why four lives are awesome so down here in my
4412
02:33:29,561 --> 02:33:30,790
text file and my a
4413
02:33:30,820 --> 02:33:31,751
python file.
4414
02:33:31,841 --> 02:33:33,160
I'm going to write out a couple different
4415
02:33:33,190 --> 02:33:33,851
for lives.
4416
02:33:34,271 --> 02:33:35,740
so the way that we create a for loop
4417
02:33:35,771 --> 02:33:37,270
is just by saying four.
4418
02:33:37,930 --> 02:33:40,749
and now what I want to do is specify
4419
02:33:40,779 --> 02:33:41,199
a
4420
02:33:41,229 --> 02:33:42,189
variable
4421
02:33:42,609 --> 02:33:44,979
and this variable is going to
4422
02:33:45,009 --> 02:33:46,239
essentially represent
4423
02:33:46,270 --> 02:33:46,689
a
4424
02:33:46,720 --> 02:33:48,100
different value
4425
02:33:48,489 --> 02:33:51,250
every time we go through this for loop
4426
02:33:51,520 --> 02:33:52,539
and you guys will see
4427
02:33:52,569 --> 02:33:56,109
how that works in a second but just know that this variable is going to
4428
02:33:56,319 --> 02:33:58,390
be used on every iteration
4429
02:33:58,420 --> 02:33:59,410
of our for loop,
4430
02:33:59,860 --> 02:34:00,221
and
4431
02:34:00,251 --> 02:34:01,031
each time
4432
02:34:01,062 --> 02:34:03,221
it will most likely have a different
4433
02:34:03,251 --> 02:34:04,211
value so
4434
02:34:04,811 --> 02:34:06,849
in our case I'm just going to call this letter.
4435
02:34:07,059 --> 02:34:08,889
and I'm going to save four letter
4436
02:34:09,278 --> 02:34:09,908
inn.
4437
02:34:10,628 --> 02:34:13,326
and now what I wanna do is I want to specify
4438
02:34:13,356 --> 02:34:14,377
a collection
4439
02:34:14,407 --> 02:34:15,728
that I want to loop over.
4440
02:34:15,938 --> 02:34:16,418
one
4441
02:34:16,478 --> 02:34:18,669
example of this would be like a string
4442
02:34:18,699 --> 02:34:21,279
so I can put a string in here I can just put like draft
4443
02:34:21,640 --> 02:34:22,420
academy.
4444
02:34:22,990 --> 02:34:24,490
and now I can just put a colon
4445
02:34:24,760 --> 02:34:28,029
and so basically what this is gonna say it so it's going to say for
4446
02:34:28,089 --> 02:34:29,169
every letter
4447
02:34:29,499 --> 02:34:31,239
inside of draft academy.
4448
02:34:31,569 --> 02:34:32,770
I want to do something
4449
02:34:33,250 --> 02:34:35,800
and so down here inside of this for loop
4450
02:34:35,830 --> 02:34:37,630
and again we need to indent this
4451
02:34:38,500 --> 02:34:40,358
we can put what we want to do with
4452
02:34:40,389 --> 02:34:45,158
each letter so let me just show you guys like basically what this is going to do so I can print out
4453
02:34:46,148 --> 02:34:48,817
letters I can print out this letter variable.
4454
02:34:49,117 --> 02:34:52,056
and it's actually going to print out a different letter
4455
02:34:52,086 --> 02:34:54,306
inside of this dropoff academy string
4456
02:34:54,575 --> 02:34:56,556
on every single iteration
4457
02:34:56,586 --> 02:34:57,665
of this loop.
4458
02:34:57,935 --> 02:34:58,415
so
4459
02:34:58,445 --> 02:34:59,706
I'm gonna run this program.
4460
02:35:00,576 --> 02:35:00,996
and
4461
02:35:01,266 --> 02:35:05,347
down here inside of my counsel you'll see that I'm basically printing out
4462
02:35:05,646 --> 02:35:07,297
draff academy so
4463
02:35:07,566 --> 02:35:09,517
on the first iteration of the loop.
4464
02:35:09,637 --> 02:35:13,026
I printed out the first letter in draft academy which was g
4465
02:35:13,477 --> 02:35:15,097
on the second iteration of the loop
4466
02:35:15,127 --> 02:35:15,847
I printed out
4467
02:35:15,906 --> 02:35:16,446
I
4468
02:35:16,626 --> 02:35:18,516
third was our fourth with
4469
02:35:18,546 --> 02:35:18,936
a.
4470
02:35:19,205 --> 02:35:19,715
so
4471
02:35:19,774 --> 02:35:22,023
I'm essentially just looping through
4472
02:35:22,054 --> 02:35:23,224
all of the letters
4473
02:35:23,283 --> 02:35:24,062
inside of
4474
02:35:24,093 --> 02:35:25,113
draff academy.
4475
02:35:25,503 --> 02:35:26,254
so I'm saying
4476
02:35:26,284 --> 02:35:27,004
for
4477
02:35:27,034 --> 02:35:27,874
each letter
4478
02:35:27,904 --> 02:35:29,165
in dropoff academy.
4479
02:35:29,345 --> 02:35:30,034
I want to print
4480
02:35:30,064 --> 02:35:30,364
out
4481
02:35:30,395 --> 02:35:30,845
that
4482
02:35:30,875 --> 02:35:31,325
letter.
4483
02:35:31,625 --> 02:35:33,035
and so this is kind of like
4484
02:35:33,065 --> 02:35:36,395
how for loops can be used we can define a variable
4485
02:35:36,755 --> 02:35:38,914
and that variable will change
4486
02:35:39,094 --> 02:35:39,634
on each
4487
02:35:39,664 --> 02:35:42,604
iteration of the loop right so on the first iteration of the loop.
4488
02:35:42,904 --> 02:35:45,213
this letter variable represented a g.
4489
02:35:45,423 --> 02:35:46,952
on the second iteration of the loop.
4490
02:35:47,162 --> 02:35:48,453
the letter variable stores
4491
02:35:48,483 --> 02:35:49,054
the value
4492
02:35:49,113 --> 02:35:49,623
I
4493
02:35:49,683 --> 02:35:50,253
excited
4494
02:35:50,283 --> 02:35:51,482
right so we went through
4495
02:35:51,872 --> 02:35:53,913
this entire string we were able to print
4496
02:35:53,943 --> 02:35:54,304
out
4497
02:35:54,394 --> 02:35:55,264
each letter.
4498
02:35:55,533 --> 02:36:02,011
so in addition to using this with strings we can also use this with other collections for example like an array.
4499
02:36:02,280 --> 02:36:04,261
so if I created in array up here,
4500
02:36:04,320 --> 02:36:05,160
let's call it
4501
02:36:05,190 --> 02:36:05,940
friends.
4502
02:36:06,091 --> 02:36:06,931
I'm gonna set this
4503
02:36:06,961 --> 02:36:09,362
equal to a bunch of different values so we can
4504
02:36:09,452 --> 02:36:11,462
put like a list of our friends in hearings zelig
4505
02:36:11,492 --> 02:36:12,062
jim
4506
02:36:12,872 --> 02:36:13,742
karen
4507
02:36:13,982 --> 02:36:14,522
and
4508
02:36:14,643 --> 02:36:15,183
kevin
4509
02:36:15,692 --> 02:36:18,092
instead of saying the letter why don't we call this
4510
02:36:18,122 --> 02:36:18,932
friend,
4511
02:36:19,622 --> 02:36:21,272
and I could say for friend
4512
02:36:21,303 --> 02:36:21,933
in
4513
02:36:23,463 --> 02:36:24,303
friends
4514
02:36:24,723 --> 02:36:26,223
and now will print out
4515
02:36:26,763 --> 02:36:27,423
the friend
4516
02:36:27,963 --> 02:36:28,503
so
4517
02:36:28,533 --> 02:36:29,942
over here I'm saying for
4518
02:36:29,973 --> 02:36:30,812
each friend
4519
02:36:30,843 --> 02:36:32,463
inside of this friends
4520
02:36:32,493 --> 02:36:33,184
array.
4521
02:36:33,363 --> 02:36:35,434
I want to print out the friend so now
4522
02:36:35,613 --> 02:36:37,174
we'll actually be able to print out
4523
02:36:37,233 --> 02:36:37,533
each
4524
02:36:37,563 --> 02:36:40,172
element inside of that array so not here you'll see
4525
02:36:40,472 --> 02:36:41,731
we're printing out gym
4526
02:36:41,972 --> 02:36:46,503
and then on the second iteration were putting out karen and on the third would bring up kevin tso,
4527
02:36:46,833 --> 02:36:48,871
and he was a loop through all of the values
4528
02:36:48,931 --> 02:36:50,460
inside of the array.
4529
02:36:50,970 --> 02:36:51,359
and
4530
02:36:51,390 --> 02:36:52,709
just so you guys know like
4531
02:36:52,829 --> 02:36:55,858
you can name this variable whatever you want so I could name
4532
02:36:55,889 --> 02:36:58,049
I could give this like any random name,
4533
02:36:58,949 --> 02:37:02,309
and if I want to access it though I have to access it using that
4534
02:37:02,339 --> 02:37:02,969
same
4535
02:37:02,999 --> 02:37:03,599
name
4536
02:37:03,688 --> 02:37:08,040
so we can loop through asking me like an array we can also just loop through
4537
02:37:08,070 --> 02:37:09,510
a series of numbers
4538
02:37:09,540 --> 02:37:10,770
so I could say
4539
02:37:10,829 --> 02:37:12,029
index over here
4540
02:37:12,299 --> 02:37:14,818
and again this can be anything I'm just gonna call index
4541
02:37:15,238 --> 02:37:16,947
so we could say for index
4542
02:37:16,978 --> 02:37:17,548
in
4543
02:37:17,998 --> 02:37:18,718
range
4544
02:37:18,748 --> 02:37:22,228
and then in here I can pass in a number so I can pass in like
4545
02:37:22,258 --> 02:37:23,368
ten for example.
4546
02:37:24,028 --> 02:37:26,308
and down here I'm just going to print out the index.
4547
02:37:26,397 --> 02:37:27,627
when I run this program,
4548
02:37:27,837 --> 02:37:28,946
you guys will see that
4549
02:37:29,456 --> 02:37:32,575
it's basically going to print out every number in the range
4550
02:37:32,605 --> 02:37:34,105
from zero to ten,
4551
02:37:34,256 --> 02:37:35,636
not including ten
4552
02:37:35,936 --> 02:37:40,495
so starting with zero it's going to put out zero one two three four five six seven eight
4553
02:37:40,525 --> 02:37:41,006
nine.
4554
02:37:41,546 --> 02:37:43,136
but notice that it didn't print
4555
02:37:43,166 --> 02:37:43,526
out
4556
02:37:43,586 --> 02:37:44,126
ten
4557
02:37:44,156 --> 02:37:47,035
so it's essentially just printing out all the numbers between
4558
02:37:47,485 --> 02:37:48,626
zero and
4559
02:37:48,836 --> 02:37:49,316
ten
4560
02:37:49,347 --> 02:37:50,456
not including ton.
4561
02:37:51,236 --> 02:37:52,376
you can also specify
4562
02:37:52,406 --> 02:37:52,826
a
4563
02:37:53,156 --> 02:37:55,767
a range of numbers so I can say for example like
4564
02:37:56,156 --> 02:37:57,686
three and ten.
4565
02:37:57,955 --> 02:38:01,555
and now this will print out all the numbers between three and ten
4566
02:38:01,705 --> 02:38:03,235
not including ten
4567
02:38:03,596 --> 02:38:05,097
so run this program,
4568
02:38:06,537 --> 02:38:07,467
and you can see we print
4569
02:38:07,497 --> 02:38:08,966
out three four five six seven
4570
02:38:08,996 --> 02:38:09,775
eight nine
4571
02:38:09,865 --> 02:38:10,915
ten not ten
4572
02:38:11,365 --> 02:38:13,436
so whatever value that you put
4573
02:38:14,365 --> 02:38:16,075
here in this second position
4574
02:38:16,135 --> 02:38:18,295
is not gonna get included in the range
4575
02:38:18,564 --> 02:38:19,555
and ranges can be
4576
02:38:19,734 --> 02:38:22,134
really is also for example I could use a range
4577
02:38:22,374 --> 02:38:25,854
to loop through an array just like we did before.
4578
02:38:25,975 --> 02:38:28,556
so if I wanted I could say something like for
4579
02:38:28,586 --> 02:38:29,246
index
4580
02:38:29,306 --> 02:38:30,415
in range
4581
02:38:30,475 --> 02:38:31,164
and now
4582
02:38:31,194 --> 02:38:32,693
inside of this range
4583
02:38:32,724 --> 02:38:33,863
I can pass in
4584
02:38:33,894 --> 02:38:34,703
the length
4585
02:38:34,733 --> 02:38:35,214
of
4586
02:38:35,273 --> 02:38:36,113
the array.
4587
02:38:36,533 --> 02:38:37,014
so
4588
02:38:37,044 --> 02:38:40,824
just so you guys know if I wanted to get the length of this array.
4589
02:38:41,214 --> 02:38:44,845
in other words if I wanted to figure out how many elements were inside of it.
4590
02:38:45,145 --> 02:38:46,374
I could just type out
4591
02:38:46,464 --> 02:38:47,214
alli end
4592
02:38:47,273 --> 02:38:48,714
and then inside parentheses.
4593
02:38:49,104 --> 02:38:50,663
the name of the array and so
4594
02:38:50,903 --> 02:38:54,803
this is going to spit out three because there's three elements
4595
02:38:54,833 --> 02:38:55,673
inside of here
4596
02:38:55,703 --> 02:38:56,033
right
4597
02:38:56,394 --> 02:38:57,264
kind of make sense.
4598
02:38:57,863 --> 02:39:01,854
so what I can do is I can say down here inside of this range function
4599
02:39:01,884 --> 02:39:02,934
I can just type in
4600
02:39:03,023 --> 02:39:03,804
eliane
4601
02:39:04,193 --> 02:39:04,854
and then
4602
02:39:05,094 --> 02:39:05,844
friends.
4603
02:39:06,144 --> 02:39:09,505
and so what this is gonna do is it's going to essentially give me
4604
02:39:09,865 --> 02:39:10,525
a range
4605
02:39:10,556 --> 02:39:13,316
between zero and the number of friends.
4606
02:39:13,376 --> 02:39:14,606
inside of this list
4607
02:39:14,637 --> 02:39:16,735
so down here I could actually type out
4608
02:39:17,426 --> 02:39:18,416
friends
4609
02:39:19,376 --> 02:39:20,096
index.
4610
02:39:20,396 --> 02:39:21,866
and this will allow me to access
4611
02:39:21,896 --> 02:39:22,257
each
4612
02:39:22,316 --> 02:39:24,656
individual friend inside of this list.
4613
02:39:24,836 --> 02:39:27,086
just like we did before but now I'm doing it with
4614
02:39:27,116 --> 02:39:27,836
a range,
4615
02:39:28,166 --> 02:39:29,396
so you can see I'm
4616
02:39:29,996 --> 02:39:32,126
typing out jim care and kevin so
4617
02:39:32,396 --> 02:39:33,115
actually
4618
02:39:33,385 --> 02:39:33,924
for each
4619
02:39:33,954 --> 02:39:35,334
iteration through this loop
4620
02:39:35,364 --> 02:39:37,344
it's basically going to be printing out
4621
02:39:37,584 --> 02:39:38,544
friends
4622
02:39:38,634 --> 02:39:39,474
zero
4623
02:39:40,283 --> 02:39:41,273
friends one
4624
02:39:41,543 --> 02:39:42,594
and then friends
4625
02:39:42,653 --> 02:39:43,583
too because
4626
02:39:43,913 --> 02:39:46,192
in heater were passing in a three
4627
02:39:46,702 --> 02:39:50,062
and remember whenever I pass in there it's going to range from zero
4628
02:39:50,151 --> 02:39:51,620
all the way up to that number
4629
02:39:51,650 --> 02:39:53,540
but not including that number so
4630
02:39:53,930 --> 02:39:56,780
that's another way that we can print out all the elements in the array
4631
02:39:56,960 --> 02:39:57,380
and
4632
02:39:57,439 --> 02:40:02,720
looping through something like an array is actually a very very common use case
4633
02:40:02,750 --> 02:40:03,830
for four loops.
4634
02:40:04,130 --> 02:40:08,510
but like I said we can you spoil hopes to loop through essentially any collection that we have so
4635
02:40:08,720 --> 02:40:11,630
we can loop through like a string that we could also loop through
4636
02:40:12,260 --> 02:40:13,790
you know something like an array so
4637
02:40:14,180 --> 02:40:17,179
this can be really useful and bats are the basics
4638
02:40:17,209 --> 02:40:18,409
of for loops
4639
02:40:18,439 --> 02:40:18,829
in
4640
02:40:18,859 --> 02:40:19,459
python.
4641
02:40:19,789 --> 02:40:22,787
and I also want to show you guys one more example just while we're here
4642
02:40:22,817 --> 02:40:23,478
so
4643
02:40:23,987 --> 02:40:25,877
why don't we go ahead and print out a range
4644
02:40:25,907 --> 02:40:26,867
up to
4645
02:40:26,927 --> 02:40:27,617
five
4646
02:40:27,647 --> 02:40:29,388
brace this would just be a simple program
4647
02:40:29,808 --> 02:40:31,787
you can use all sorts of logic
4648
02:40:31,817 --> 02:40:33,137
inside of these four lives.
4649
02:40:33,287 --> 02:40:37,787
so let's say that I wanted to do something special on the first iteration of the loop.
4650
02:40:38,087 --> 02:40:39,106
so I could say
4651
02:40:39,467 --> 02:40:39,977
if
4652
02:40:40,366 --> 02:40:41,026
index
4653
02:40:41,057 --> 02:40:42,316
is equal to zero
4654
02:40:43,217 --> 02:40:43,637
and
4655
02:40:43,667 --> 02:40:48,943
if the index to zero than we know it's the first iteration of the loop so I could do something special I could like print out
4656
02:40:49,063 --> 02:40:49,754
first
4657
02:40:49,813 --> 02:40:50,594
iteration.
4658
02:40:51,044 --> 02:40:52,993
and then otherwise we could just
4659
02:40:53,474 --> 02:40:54,374
print lake
4660
02:40:56,414 --> 02:40:58,845
not first so this would be an example of like
4661
02:40:59,055 --> 02:41:01,725
maybe you want to do something on the first iteration of the loop
4662
02:41:01,965 --> 02:41:03,164
and do something else on
4663
02:41:03,404 --> 02:41:05,563
subsequent iteration so if I play this
4664
02:41:05,983 --> 02:41:08,323
you'll see only on the first iteration is it
4665
02:41:08,354 --> 02:41:11,146
printing this out and otherwise it's printing out other stuff so
4666
02:41:11,415 --> 02:41:11,655
you
4667
02:41:11,686 --> 02:41:12,976
don't be afraid to
4668
02:41:13,006 --> 02:41:14,625
put some complex logic
4669
02:41:14,655 --> 02:41:16,004
inside of these four lives
4670
02:41:16,304 --> 02:41:16,754
because
4671
02:41:16,784 --> 02:41:19,305
it can really make your programs more powerful
4672
02:41:23,564 --> 02:41:25,753
in this tutorial I'll show you guys how to build an
4673
02:41:25,783 --> 02:41:27,043
exponent function
4674
02:41:27,073 --> 02:41:29,983
are an exponent function is basically going to allow us
4675
02:41:30,014 --> 02:41:30,464
to
4676
02:41:30,494 --> 02:41:33,972
take a certain number and raise it to a specific power.
4677
02:41:34,332 --> 02:41:38,651
so in python there's actually a really easy way to do this I can come down here and I could print.
4678
02:41:39,281 --> 02:41:40,092
we could say like
4679
02:41:40,122 --> 02:41:40,962
too.
4680
02:41:41,231 --> 02:41:42,012
and we can just do
4681
02:41:42,042 --> 02:41:43,662
two multiplication signs
4682
02:41:43,992 --> 02:41:45,192
and I could say three
4683
02:41:45,492 --> 02:41:47,742
and this is basically just going to be two
4684
02:41:47,802 --> 02:41:49,632
raised to the third power.
4685
02:41:50,142 --> 02:41:50,892
so
4686
02:41:51,012 --> 02:41:51,461
you can
4687
02:41:51,491 --> 02:41:53,172
see here I can just print this out and
4688
02:41:53,202 --> 02:41:53,772
we get a
4689
02:41:53,803 --> 02:41:54,433
cassettes
4690
02:41:54,492 --> 02:41:55,212
to cube
4691
02:41:55,242 --> 02:41:55,662
so
4692
02:41:55,902 --> 02:41:58,603
it's really easy to do exponents in python.
4693
02:41:59,202 --> 02:42:00,401
but I want to show you guys,
4694
02:42:00,461 --> 02:42:07,060
how we can use something like a for loop in order to create a function like this of our own sun will actually create an
4695
02:42:07,119 --> 02:42:07,839
exponent
4696
02:42:07,869 --> 02:42:08,619
function
4697
02:42:08,919 --> 02:42:11,320
that will basically do this and we'll use
4698
02:42:11,351 --> 02:42:12,311
for loops to do it
4699
02:42:12,461 --> 02:42:12,941
so
4700
02:42:13,541 --> 02:42:14,741
let's create a function.
4701
02:42:14,801 --> 02:42:16,030
something as a death
4702
02:42:16,061 --> 02:42:17,261
and now we need to give this
4703
02:42:17,291 --> 02:42:19,330
function a name so why don't we call it
4704
02:42:19,420 --> 02:42:20,229
raise
4705
02:42:20,260 --> 02:42:21,010
two
4706
02:42:21,340 --> 02:42:21,910
power
4707
02:42:22,780 --> 02:42:23,860
and inside of here,
4708
02:42:24,221 --> 02:42:27,610
I'm going to accept two parameters the first parameter is going to be the
4709
02:42:27,641 --> 02:42:28,780
base number.
4710
02:42:29,290 --> 02:42:30,040
and then the second
4711
02:42:30,070 --> 02:42:31,571
parameter is going to be the
4712
02:42:31,661 --> 02:42:34,631
power number so we're going to take the base number
4713
02:42:34,811 --> 02:42:35,980
and raise it to
4714
02:42:36,011 --> 02:42:37,031
the power number.
4715
02:42:37,512 --> 02:42:38,172
so
4716
02:42:38,202 --> 02:42:39,012
over here we can just
4717
02:42:39,042 --> 02:42:39,912
make a colon
4718
02:42:40,182 --> 02:42:40,662
now
4719
02:42:41,172 --> 02:42:44,473
inside of this function when you start writing some code.
4720
02:42:44,742 --> 02:42:45,461
here's the thing
4721
02:42:46,031 --> 02:42:48,701
inside the function we don't necessarily know
4722
02:42:48,731 --> 02:42:50,862
the value of this poem,
4723
02:42:51,252 --> 02:42:51,612
right
4724
02:42:51,792 --> 02:42:53,142
for them why have we knew
4725
02:42:53,172 --> 02:42:56,921
that we were just trying to like square this number or cube this number.
4726
02:42:57,131 --> 02:42:58,541
I could just return
4727
02:42:59,021 --> 02:43:00,102
like bass
4728
02:43:00,161 --> 02:43:00,852
num
4729
02:43:01,182 --> 02:43:02,052
times
4730
02:43:02,231 --> 02:43:02,861
basal cell
4731
02:43:02,921 --> 02:43:03,221
right
4732
02:43:03,251 --> 02:43:05,771
now it's square the number or I could keep the number
4733
02:43:06,252 --> 02:43:06,972
bass num
4734
02:43:07,031 --> 02:43:08,891
so right so this would be like the number cubed.
4735
02:43:09,131 --> 02:43:11,981
the problem is though we don't know like right off the bat
4736
02:43:12,012 --> 02:43:13,661
what this value is going to be
4737
02:43:13,991 --> 02:43:16,632
right this could change like the user can decide that.
4738
02:43:17,021 --> 02:43:21,433
so in order to write this function we're actually going to need to use a for loop.
4739
02:43:21,763 --> 02:43:23,412
and I'm sure you guys how it can use a for loop
4740
02:43:23,442 --> 02:43:25,333
to basically figured this out so
4741
02:43:25,693 --> 02:43:28,902
the first thing I want to do is create a variable and I'm just going to call it
4742
02:43:28,933 --> 02:43:29,713
result.
4743
02:43:30,373 --> 02:43:31,633
and we're just going to set the result
4744
02:43:31,663 --> 02:43:34,364
equal to one so we're gonna start this off at one.
4745
02:43:34,814 --> 02:43:36,074
now I want to create
4746
02:43:36,104 --> 02:43:37,334
a for loop,
4747
02:43:37,394 --> 02:43:38,953
so I'm basically just gonna say
4748
02:43:38,983 --> 02:43:39,674
four
4749
02:43:40,574 --> 02:43:41,564
and over here,
4750
02:43:41,834 --> 02:43:43,663
I don't want to specify like
4751
02:43:43,693 --> 02:43:44,144
a
4752
02:43:44,233 --> 02:43:46,123
index on aug eight index
4753
02:43:46,363 --> 02:43:46,903
in
4754
02:43:47,023 --> 02:43:48,824
and now want to specify a range
4755
02:43:48,884 --> 02:43:50,324
and arrange will basically
4756
02:43:50,354 --> 02:43:51,044
range us
4757
02:43:51,074 --> 02:43:51,584
through
4758
02:43:51,614 --> 02:43:52,124
a
4759
02:43:52,184 --> 02:43:53,623
collection of numbers.
4760
02:43:53,923 --> 02:43:55,183
so basically I want to
4761
02:43:55,272 --> 02:43:56,863
multiply the bass num
4762
02:43:56,894 --> 02:43:57,974
by itself,
4763
02:43:58,544 --> 02:44:01,064
as many times as the pound numb
4764
02:44:01,095 --> 02:44:02,114
specifies
4765
02:44:02,174 --> 02:44:02,624
right
4766
02:44:02,954 --> 02:44:04,483
over here I can just make this
4767
02:44:04,514 --> 02:44:05,443
a range
4768
02:44:05,503 --> 02:44:06,163
of
4769
02:44:06,283 --> 02:44:06,883
power
4770
02:44:06,913 --> 02:44:07,453
numb
4771
02:44:07,843 --> 02:44:10,512
right and so we'll basically a loop through
4772
02:44:10,542 --> 02:44:11,652
this for loop
4773
02:44:11,952 --> 02:44:15,281
as many times as pound them so eponymous two
4774
02:44:15,551 --> 02:44:16,750
will loop through it twice.
4775
02:44:16,900 --> 02:44:19,301
economists for will luther at four times
4776
02:44:19,570 --> 02:44:23,170
and every time through the loop will multiply bass num by itself
4777
02:44:23,200 --> 02:44:25,631
or actually you'll see we're going to multiply it by this result,
4778
02:44:26,111 --> 02:44:27,191
and so down here inside
4779
02:44:27,222 --> 02:44:27,972
this for loop
4780
02:44:28,002 --> 02:44:29,262
I can basically say
4781
02:44:29,622 --> 02:44:30,342
result
4782
02:44:30,372 --> 02:44:31,481
is equal to
4783
02:44:31,901 --> 02:44:32,651
result
4784
02:44:32,802 --> 02:44:33,762
times,
4785
02:44:34,332 --> 02:44:35,082
pacing up
4786
02:44:35,262 --> 02:44:38,772
this should actually give us everything we need to take this number
4787
02:44:38,982 --> 02:44:40,723
to the specific power so
4788
02:44:40,933 --> 02:44:42,162
the actual like
4789
02:44:42,192 --> 02:44:42,942
result
4790
02:44:43,212 --> 02:44:44,501
of doing the math
4791
02:44:44,531 --> 02:44:45,762
is going to get stored
4792
02:44:45,792 --> 02:44:46,872
inside of this
4793
02:44:46,902 --> 02:44:47,622
result
4794
02:44:47,652 --> 02:44:48,643
variable so
4795
02:44:49,123 --> 02:44:50,293
the first time through the loop,
4796
02:44:50,353 --> 02:44:52,692
we're just multiplying basin on by one
4797
02:44:52,752 --> 02:44:53,292
right.
4798
02:44:53,832 --> 02:44:54,912
and so now result
4799
02:44:54,942 --> 02:44:55,933
is going to become
4800
02:44:55,992 --> 02:44:57,432
the same value is based on
4801
02:44:57,731 --> 02:45:01,422
the second time through the loop so this would be if we were squaring the number.
4802
02:45:01,632 --> 02:45:05,383
we're basically multiplying resort by basin um again so it's essentially just
4803
02:45:05,413 --> 02:45:07,184
based on long times based on
4804
02:45:07,573 --> 02:45:08,864
the third time through the loop
4805
02:45:08,895 --> 02:45:10,904
we're multiplying result times bass num
4806
02:45:10,935 --> 02:45:12,314
so we're essentially just like
4807
02:45:12,345 --> 02:45:13,695
keeping the number so
4808
02:45:13,905 --> 02:45:15,586
that's essentially what this for loop
4809
02:45:15,616 --> 02:45:16,727
is doing for us.
4810
02:45:16,937 --> 02:45:18,586
so the last thing I want to do is
4811
02:45:18,676 --> 02:45:20,506
right here below this for loop
4812
02:45:20,536 --> 02:45:21,047
I'm just going to
4813
02:45:21,077 --> 02:45:21,827
return
4814
02:45:22,308 --> 02:45:22,998
the result
4815
02:45:23,028 --> 02:45:23,568
so
4816
02:45:23,748 --> 02:45:28,369
we'll be able to return whatever the result of raising the number to the power was
4817
02:45:29,060 --> 02:45:29,961
so let's come down
4818
02:45:29,991 --> 02:45:33,681
after this function and we're just going to call it so I'm just going to say,
4819
02:45:34,490 --> 02:45:36,170
actually will print out the answer so
4820
02:45:36,320 --> 02:45:38,301
save raise to power
4821
02:45:38,751 --> 02:45:41,961
and the inside of these pregnancies member we can pass two numbers so let's
4822
02:45:42,021 --> 02:45:43,400
raise three
4823
02:45:43,910 --> 02:45:47,479
to the second power so we're just going to square three and we'll see how this works
4824
02:45:47,510 --> 02:45:47,960
so
4825
02:45:48,350 --> 02:45:49,249
from the program
4826
02:45:49,639 --> 02:45:53,028
and you can see down here in the console were getting nine.
4827
02:45:53,088 --> 02:45:54,197
let's try something a little bit
4828
02:45:54,527 --> 02:45:55,157
crazier
4829
02:45:55,397 --> 02:45:56,508
drive three
4830
02:45:56,538 --> 02:45:57,738
to the fourth power
4831
02:45:58,309 --> 02:45:59,509
and will run this
4832
02:45:59,568 --> 02:46:00,049
aggregate
4833
02:46:00,079 --> 02:46:01,428
eighty one so that's
4834
02:46:01,458 --> 02:46:02,657
three to the fourth power.
4835
02:46:03,138 --> 02:46:05,718
let's try two to the third power
4836
02:46:05,897 --> 02:46:06,767
and were getting eight
4837
02:46:06,797 --> 02:46:07,667
yeah so that makes us
4838
02:46:07,697 --> 02:46:08,087
so
4839
02:46:08,807 --> 02:46:10,787
our raised the power function is working
4840
02:46:10,817 --> 02:46:13,906
just as expected and that is what he has to do it one more time.
4841
02:46:14,176 --> 02:46:14,836
so
4842
02:46:14,956 --> 02:46:19,426
inside of this function were taking in two pieces of input were taken in a base number.
4843
02:46:19,695 --> 02:46:21,854
we're taking it a pow number so that's like
4844
02:46:22,305 --> 02:46:24,944
the base number is going to be taken to the power number
4845
02:46:25,334 --> 02:46:27,824
I'm defining a variable here called result
4846
02:46:28,124 --> 02:46:30,313
and result is where we're going to store
4847
02:46:30,373 --> 02:46:32,594
the actual result of doing the math.
4848
02:46:33,014 --> 02:46:34,754
now we specify this
4849
02:46:34,784 --> 02:46:35,414
for loop,
4850
02:46:35,474 --> 02:46:37,305
and I'm basically saying that
4851
02:46:37,395 --> 02:46:39,974
I want to loop through this range of numbers.
4852
02:46:40,033 --> 02:46:40,543
when I put
4853
02:46:40,573 --> 02:46:43,123
pounha um here is basically going to range from zero
4854
02:46:43,423 --> 02:46:46,633
all the way up to but not including the power number silk
4855
02:46:46,783 --> 02:46:49,724
we'll basically loop through power number of times
4856
02:46:49,754 --> 02:46:50,413
that makes sense.
4857
02:46:50,894 --> 02:46:54,223
and then every time through the loop we're just multiplying result by
4858
02:46:54,282 --> 02:46:54,942
base numb.
4859
02:46:55,272 --> 02:46:57,073
and then we're just returning results so
4860
02:46:57,253 --> 02:46:59,052
that's the basics of building a
4861
02:46:59,082 --> 02:46:59,922
power function
4862
02:46:59,952 --> 02:47:00,192
and
4863
02:47:00,252 --> 02:47:01,062
obviously like
4864
02:47:01,093 --> 02:47:04,391
if you're just trying to take a number to a power in python it's really easy but
4865
02:47:04,570 --> 02:47:07,180
this kind of shows you like the internal workings right
4866
02:47:07,420 --> 02:47:10,269
for a function like that to work we would have to actually
4867
02:47:10,358 --> 02:47:12,218
type something out just like this,
4868
02:47:16,208 --> 02:47:19,957
and this tutorial I wanna talk to you guys about two different concepts
4869
02:47:19,987 --> 02:47:20,407
in
4870
02:47:20,438 --> 02:47:21,098
python.
4871
02:47:21,487 --> 02:47:22,717
it's going be a pretty cool lesson.
4872
02:47:23,047 --> 02:47:24,845
first thing I want to show you guys though are
4873
02:47:24,875 --> 02:47:27,784
two dimensional lists so down here in our
4874
02:47:27,964 --> 02:47:28,983
python file.
4875
02:47:29,163 --> 02:47:30,242
I just want to create
4876
02:47:30,632 --> 02:47:31,262
a
4877
02:47:31,292 --> 02:47:32,012
basic list
4878
02:47:32,042 --> 02:47:33,632
so I'm just going to call this
4879
02:47:33,722 --> 02:47:34,652
number grid.
4880
02:47:35,522 --> 02:47:37,232
and I'm going to set this equal to
4881
02:47:37,263 --> 02:47:39,152
a normal let strangers like this
4882
02:47:40,172 --> 02:47:46,112
now normally if we were creating a list I could just put in a bunch attributes and bunch elements right,
4883
02:47:46,532 --> 02:47:50,190
and now all of these elements are inside of this number grid lists everybody's happy.
4884
02:47:50,671 --> 02:47:51,211
but
4885
02:47:51,601 --> 02:47:52,980
another thing I can do
4886
02:47:53,011 --> 02:47:54,240
is I can make
4887
02:47:54,271 --> 02:47:55,561
all of the elements
4888
02:47:55,591 --> 02:47:58,052
inside of this number grid list
4889
02:47:58,622 --> 02:47:59,492
lists
4890
02:47:59,522 --> 02:48:00,062
so
4891
02:48:00,093 --> 02:48:00,723
the first
4892
02:48:00,753 --> 02:48:01,203
item
4893
02:48:01,233 --> 02:48:03,334
in the numbered list is going to be a list.
4894
02:48:03,574 --> 02:48:06,032
the second item and the number grew less is going to be a list
4895
02:48:06,062 --> 02:48:06,692
etc.
4896
02:48:07,112 --> 02:48:08,401
so I'm going to show you guys have to do that
4897
02:48:08,432 --> 02:48:10,382
I can basically just come down here and
4898
02:48:10,412 --> 02:48:12,241
why would normally put the first
4899
02:48:12,571 --> 02:48:13,531
element in the list
4900
02:48:13,562 --> 02:48:15,332
I can just create another array
4901
02:48:15,632 --> 02:48:18,392
someone's going to make an open closed square bracket,
4902
02:48:18,691 --> 02:48:19,411
and now
4903
02:48:19,711 --> 02:48:22,172
I'm just going to say one two three
4904
02:48:23,102 --> 02:48:25,111
and I can create the next item in my list
4905
02:48:25,142 --> 02:48:26,011
I can say
4906
02:48:26,610 --> 02:48:28,380
four five six,
4907
02:48:28,710 --> 02:48:30,780
and then let's make another item in this list.
4908
02:48:30,840 --> 02:48:31,590
I can say
4909
02:48:32,160 --> 02:48:32,730
seven
4910
02:48:32,761 --> 02:48:33,001
eight
4911
02:48:33,031 --> 02:48:33,602
nine
4912
02:48:33,871 --> 02:48:37,800
and finally we're going to put one more list inside of the number grid list
4913
02:48:38,010 --> 02:48:39,089
and it's just going to have
4914
02:48:39,119 --> 02:48:40,648
zero in it so
4915
02:48:41,129 --> 02:48:43,769
inside of this numbered red lips write this
4916
02:48:43,828 --> 02:48:45,808
high level overall list,
4917
02:48:46,048 --> 02:48:46,798
we have
4918
02:48:46,828 --> 02:48:48,298
four elements
4919
02:48:48,448 --> 02:48:48,658
in
4920
02:48:48,688 --> 02:48:49,888
all of those elements
4921
02:48:49,918 --> 02:48:50,308
are
4922
02:48:50,338 --> 02:48:51,418
themselves
4923
02:48:51,568 --> 02:48:52,559
lists.
4924
02:48:52,679 --> 02:48:55,948
so essentially what we're doing is we're creating a grid right
4925
02:48:56,099 --> 02:49:00,059
this grid has one two three four rows
4926
02:49:00,269 --> 02:49:01,108
and one
4927
02:49:01,139 --> 02:49:03,147
two three carbons
4928
02:49:03,417 --> 02:49:03,807
right
4929
02:49:03,837 --> 02:49:04,616
for rose
4930
02:49:04,646 --> 02:49:06,446
three columns and that's kind of like
4931
02:49:06,927 --> 02:49:10,077
why these can be useful as we can create a grid like
4932
02:49:10,107 --> 02:49:11,997
structure inside of python
4933
02:49:12,057 --> 02:49:12,717
using
4934
02:49:12,747 --> 02:49:14,547
two dimensional lists.
4935
02:49:14,787 --> 02:49:17,007
so this is a pretty cool list structure.
4936
02:49:17,487 --> 02:49:18,657
and I wanna show you guys,
4937
02:49:18,808 --> 02:49:19,888
how it can access
4938
02:49:19,918 --> 02:49:21,447
individual elements
4939
02:49:21,657 --> 02:49:23,698
inside of this list structure so
4940
02:49:24,358 --> 02:49:29,430
for example let's say I wanted to print out one of these values if they wanted to print out this one right here,
4941
02:49:29,790 --> 02:49:31,681
the way I can access it is by saying
4942
02:49:32,431 --> 02:49:33,361
number grid.
4943
02:49:34,352 --> 02:49:34,832
and
4944
02:49:34,892 --> 02:49:37,952
the first thing I want to do is make an open and closed square brackets
4945
02:49:38,132 --> 02:49:39,122
and in here
4946
02:49:39,152 --> 02:49:40,953
I want to put the
4947
02:49:41,223 --> 02:49:43,562
index of the row that I want to access.
4948
02:49:43,742 --> 02:49:45,782
so this would be like row zero
4949
02:49:45,962 --> 02:49:48,152
because it's the zero of element in the array.
4950
02:49:48,422 --> 02:49:50,942
this would be row on its it and exposition one
4951
02:49:51,122 --> 02:49:54,002
this would be row to row three etc so I could put
4952
02:49:54,212 --> 02:49:55,172
roses grow
4953
02:49:56,012 --> 02:49:56,821
and now
4954
02:49:56,911 --> 02:49:59,610
right next to this I'm going to make another square bracket,
4955
02:49:59,880 --> 02:50:01,229
and I want to put the
4956
02:50:01,439 --> 02:50:03,300
index of the column so
4957
02:50:03,510 --> 02:50:04,979
this would be like column one
4958
02:50:05,009 --> 02:50:06,269
column to column three.
4959
02:50:06,389 --> 02:50:06,869
so
4960
02:50:06,899 --> 02:50:08,188
I'm going to put it another zero
4961
02:50:08,219 --> 02:50:09,779
because this is at the
4962
02:50:09,810 --> 02:50:10,350
zero
4963
02:50:10,380 --> 02:50:10,979
index
4964
02:50:11,039 --> 02:50:12,209
of this first
4965
02:50:12,239 --> 02:50:13,079
array so
4966
02:50:13,439 --> 02:50:13,529
I've
4967
02:50:13,560 --> 02:50:14,819
been zero zero here.
4968
02:50:15,149 --> 02:50:17,459
now we can print this guy out to the screen
4969
02:50:18,299 --> 02:50:19,349
and you'll see down here
4970
02:50:19,589 --> 02:50:20,969
that we get that one
4971
02:50:21,329 --> 02:50:25,318
so I can also do this for like for this eight for example so this is going to be
4972
02:50:25,349 --> 02:50:26,699
zero one two
4973
02:50:27,119 --> 02:50:28,858
can be row two and
4974
02:50:29,368 --> 02:50:30,538
column one
4975
02:50:30,928 --> 02:50:32,848
and now we should be able to print out that
4976
02:50:32,907 --> 02:50:33,207
e.
4977
02:50:34,407 --> 02:50:37,557
so that's basically how we can access elements inside of this
4978
02:50:37,587 --> 02:50:38,517
two d
4979
02:50:38,547 --> 02:50:39,237
list.
4980
02:50:39,718 --> 02:50:40,888
the next thing I want to show you guys
4981
02:50:40,918 --> 02:50:41,188
is
4982
02:50:41,218 --> 02:50:41,938
a
4983
02:50:41,997 --> 02:50:43,437
nested for loop
4984
02:50:43,467 --> 02:50:46,137
nested poorly with the situation in mega said well we have
4985
02:50:46,167 --> 02:50:47,098
a for loop
4986
02:50:47,128 --> 02:50:48,267
inside of a for loop.
4987
02:50:48,566 --> 02:50:51,415
and I'll show you how we can use this nested for loop
4988
02:50:51,835 --> 02:50:57,834
in order to print out all the elements inside of this array so I've basically shown you guys on a parse through
4989
02:50:57,864 --> 02:50:58,284
a
4990
02:50:58,645 --> 02:50:59,755
two dimensional
4991
02:50:59,905 --> 02:51:01,706
list or a two dimensional array.
4992
02:51:02,066 --> 02:51:05,514
so basically we're going to create a normal for loop so I'm going to say four
4993
02:51:05,754 --> 02:51:07,644
and I'm just going to say row
4994
02:51:08,063 --> 02:51:08,604
in
4995
02:51:08,663 --> 02:51:09,533
number grid.
4996
02:51:10,253 --> 02:51:12,322
and I'm using the word row here because
4997
02:51:12,353 --> 02:51:13,583
I'm kind of seeing
4998
02:51:13,613 --> 02:51:17,094
these guys as rows right these are sort of horizontal rows
4999
02:51:17,574 --> 02:51:18,895
in our little grid
5000
02:51:19,194 --> 02:51:22,074
so for each of those rows for each of the
5001
02:51:22,134 --> 02:51:22,794
elements
5002
02:51:22,854 --> 02:51:24,144
inside of number grid.
5003
02:51:24,203 --> 02:51:26,844
I want to loop through so I could actually just print out
5004
02:51:27,113 --> 02:51:28,403
each row right now
5005
02:51:28,613 --> 02:51:31,015
and it's going to print out all the rows inside of this
5006
02:51:31,045 --> 02:51:32,486
list you can see down here
5007
02:51:32,756 --> 02:51:35,335
we basically just get exactly what we have up there.
5008
02:51:35,815 --> 02:51:37,285
but I want to be able to access
5009
02:51:37,345 --> 02:51:39,084
each of these individual
5010
02:51:39,114 --> 02:51:39,864
attributes
5011
02:51:39,924 --> 02:51:41,635
inside of each of these
5012
02:51:41,694 --> 02:51:42,685
array elements
5013
02:51:42,715 --> 02:51:43,225
so
5014
02:51:43,585 --> 02:51:47,994
we can actually create another for loop and am I put that for loop inside of here,
5015
02:51:48,624 --> 02:51:50,514
so now I'm going to say four
5016
02:51:51,204 --> 02:51:51,954
column
5017
02:51:52,224 --> 02:51:52,854
in a
5018
02:51:53,273 --> 02:51:53,964
row.
5019
02:51:54,864 --> 02:51:56,604
and basically what this is going to give us is
5020
02:51:56,904 --> 02:51:57,265
each
5021
02:51:57,295 --> 02:51:58,345
individual
5022
02:51:58,404 --> 02:52:00,114
column or each individual
5023
02:52:00,145 --> 02:52:02,035
element inside of these
5024
02:52:02,095 --> 02:52:02,694
arrays
5025
02:52:02,725 --> 02:52:04,824
so for example inside of the arrays that are
5026
02:52:04,884 --> 02:52:06,384
the elements of the number grid
5027
02:52:07,254 --> 02:52:08,214
over that makes sense
5028
02:52:08,244 --> 02:52:08,754
so
5029
02:52:08,784 --> 02:52:09,474
down here.
5030
02:52:09,863 --> 02:52:10,433
now we can just
5031
02:52:10,463 --> 02:52:10,823
print
5032
02:52:10,854 --> 02:52:11,304
out
5033
02:52:11,483 --> 02:52:12,203
column
5034
02:52:12,263 --> 02:52:13,823
and this should actually print out
5035
02:52:14,093 --> 02:52:15,113
every single
5036
02:52:15,144 --> 02:52:17,304
value inside of this two dimensional array.
5037
02:52:17,363 --> 02:52:19,163
so let's go ahead and run this program.
5038
02:52:20,063 --> 02:52:23,005
and down here you'll see that we're basically printing out
5039
02:52:23,274 --> 02:52:24,744
one all the way down
5040
02:52:24,774 --> 02:52:25,225
to
5041
02:52:25,255 --> 02:52:25,675
zero
5042
02:52:25,705 --> 02:52:27,656
so we're printing out all of the
5043
02:52:27,716 --> 02:52:28,286
elements
5044
02:52:28,586 --> 02:52:29,396
inside of
5045
02:52:29,455 --> 02:52:31,944
all of the arrays inside of the number grid.
5046
02:52:32,034 --> 02:52:34,523
so that's how we can use two dimensional lists and
5047
02:52:34,554 --> 02:52:37,193
nested for loops together in both of those things
5048
02:52:37,253 --> 02:52:39,533
are actually pretty handy in python
5049
02:52:44,093 --> 02:52:48,264
in this tutorial I'm going to show you how to build a basic translator in
5050
02:52:48,294 --> 02:52:48,984
python.
5051
02:52:49,314 --> 02:52:50,454
so essentially we can
5052
02:52:50,484 --> 02:52:51,265
take in
5053
02:52:51,295 --> 02:52:54,596
a strings we can take him like a phrase or a word
5054
02:52:54,985 --> 02:52:58,676
and will be able to translate it into a different language.
5055
02:52:59,096 --> 02:52:59,485
so
5056
02:52:59,516 --> 02:53:01,135
over here I have this little file
5057
02:53:01,165 --> 02:53:03,476
and it basically specifies this language
5058
02:53:03,506 --> 02:53:06,175
that I made up so I'm calling it the draft language
5059
02:53:06,564 --> 02:53:06,925
and
5060
02:53:06,955 --> 02:53:08,305
in the draft language
5061
02:53:08,335 --> 02:53:09,564
all vowels
5062
02:53:09,595 --> 02:53:10,285
become
5063
02:53:10,315 --> 02:53:11,096
g
5064
02:53:11,456 --> 02:53:14,096
so if I was going to translate an english word into
5065
02:53:14,126 --> 02:53:15,326
a draft word
5066
02:53:15,926 --> 02:53:17,517
for example the word dog,
5067
02:53:17,606 --> 02:53:19,256
I would look through the word dog
5068
02:53:19,315 --> 02:53:19,525
and
5069
02:53:19,556 --> 02:53:21,746
any instances where there was a vowel
5070
02:53:21,776 --> 02:53:22,316
so
5071
02:53:22,406 --> 02:53:23,397
in our case let's just say
5072
02:53:23,428 --> 02:53:24,777
a e I o u.
5073
02:53:25,258 --> 02:53:27,028
I would convert that vowel
5074
02:53:27,088 --> 02:53:27,987
into a g
5075
02:53:28,167 --> 02:53:29,906
so dog would map to
5076
02:53:30,026 --> 02:53:31,076
ddg
5077
02:53:31,346 --> 02:53:32,456
cat would get mapped
5078
02:53:32,486 --> 02:53:33,177
into
5079
02:53:33,236 --> 02:53:34,347
c g t.
5080
02:53:34,616 --> 02:53:36,206
so those are the basic translation rules.
5081
02:53:36,266 --> 02:53:38,425
obviously this is a pretty simple language but
5082
02:53:38,665 --> 02:53:41,185
you get the point any vowel is going to become a
5083
02:53:41,215 --> 02:53:42,476
g and then we'll get
5084
02:53:42,506 --> 02:53:43,556
the draft language.
5085
02:53:43,706 --> 02:53:44,395
so we're going to build
5086
02:53:44,425 --> 02:53:45,205
a draft
5087
02:53:45,235 --> 02:53:46,045
translator
5088
02:53:46,615 --> 02:53:48,054
over here in our
5089
02:53:48,084 --> 02:53:49,074
python file.
5090
02:53:49,164 --> 02:53:49,584
let's
5091
02:53:49,614 --> 02:53:54,865
start making this translator the first thing I'm going to do is just define a translate function.
5092
02:53:55,375 --> 02:53:57,864
so I'm going to make a function here and I'm just going to call it
5093
02:53:58,914 --> 02:53:59,604
translate
5094
02:54:00,204 --> 02:54:00,714
and
5095
02:54:00,773 --> 02:54:02,094
inside of these parentheses
5096
02:54:02,124 --> 02:54:03,385
we want this to take
5097
02:54:03,415 --> 02:54:03,985
one
5098
02:54:04,016 --> 02:54:05,664
piece of information which is going to be
5099
02:54:05,904 --> 02:54:06,925
the phrase
5100
02:54:07,075 --> 02:54:09,024
that we want to translate so I'm gonna say
5101
02:54:09,055 --> 02:54:09,774
phrase
5102
02:54:10,524 --> 02:54:13,403
and now inside of this function we need to figure out like
5103
02:54:13,493 --> 02:54:13,793
ok
5104
02:54:13,823 --> 02:54:15,594
how can we translate
5105
02:54:16,014 --> 02:54:19,284
english into our draft language well remember
5106
02:54:19,314 --> 02:54:21,115
the rules is basically just
5107
02:54:21,325 --> 02:54:22,704
any vowels become
5108
02:54:22,734 --> 02:54:23,454
jeez.
5109
02:54:23,874 --> 02:54:26,303
so the first thing I want to do is create a variable
5110
02:54:26,393 --> 02:54:32,305
and this variable is going to be the translation so this will be like the final result that we're going to return to the user.
5111
02:54:32,665 --> 02:54:33,566
so I can say
5112
02:54:33,896 --> 02:54:34,887
translation
5113
02:54:35,127 --> 02:54:36,567
for now I'm just going to set it
5114
02:54:36,598 --> 02:54:37,647
equal to
5115
02:54:37,827 --> 02:54:39,807
the empty string so this is just going to be like
5116
02:54:40,076 --> 02:54:42,087
a completely empty string it's not gonna
5117
02:54:42,117 --> 02:54:43,137
be doing anything.
5118
02:54:43,736 --> 02:54:44,336
and
5119
02:54:44,696 --> 02:54:47,516
now what we want to do is we basically want to
5120
02:54:47,546 --> 02:54:48,026
loop
5121
02:54:48,057 --> 02:54:48,776
through
5122
02:54:49,166 --> 02:54:51,656
every letter inside of this phrase.
5123
02:54:51,956 --> 02:54:52,376
and
5124
02:54:52,436 --> 02:54:54,806
if it's a vowel we want to change it to g
5125
02:54:54,836 --> 02:54:57,086
and if it's not avowal we want to leave it alone
5126
02:54:57,355 --> 02:54:57,806
and
5127
02:54:57,896 --> 02:54:58,105
we're
5128
02:54:58,165 --> 02:55:00,055
essentially going to be looping through phrase.
5129
02:55:00,175 --> 02:55:02,094
and we're going to be adding the letters
5130
02:55:02,244 --> 02:55:04,193
onto this translation
5131
02:55:04,313 --> 02:55:07,044
one by one so make sure you guys how we can do this.
5132
02:55:07,104 --> 02:55:09,443
I'm going to make a for loop somewhere safe for
5133
02:55:10,014 --> 02:55:11,543
and I'm just going to say a letter
5134
02:55:12,173 --> 02:55:12,743
in
5135
02:55:13,133 --> 02:55:14,033
phrase.
5136
02:55:14,783 --> 02:55:15,503
and so now
5137
02:55:16,193 --> 02:55:18,533
when I looped through here I can access
5138
02:55:18,593 --> 02:55:18,982
each
5139
02:55:19,013 --> 02:55:20,272
individual letter
5140
02:55:20,362 --> 02:55:22,644
inside of the phrase that they passed in.
5141
02:55:23,063 --> 02:55:26,094
so what I wanna do is I want to check to see if
5142
02:55:26,273 --> 02:55:28,042
the letter is a vowel or not
5143
02:55:28,072 --> 02:55:28,433
right.
5144
02:55:28,612 --> 02:55:30,264
if it's a vowel than we can
5145
02:55:30,294 --> 02:55:30,684
add
5146
02:55:30,714 --> 02:55:32,604
a g onto translation.
5147
02:55:32,934 --> 02:55:34,104
if it's not available
5148
02:55:34,134 --> 02:55:35,994
then we can just add on whatever
5149
02:55:36,114 --> 02:55:37,913
letter it was onto translation
5150
02:55:37,973 --> 02:55:38,903
anyway so
5151
02:55:39,354 --> 02:55:39,863
many users
5152
02:55:39,894 --> 02:55:40,974
if statement I'm going to say
5153
02:55:41,063 --> 02:55:41,453
if.
5154
02:55:42,113 --> 02:55:47,634
and there's actually this special thing we can do in python we can check to see if something is in
5155
02:55:47,664 --> 02:55:48,505
something else
5156
02:55:48,805 --> 02:55:49,854
so I can say if
5157
02:55:50,604 --> 02:55:51,295
letter
5158
02:55:51,535 --> 02:55:52,105
inn.
5159
02:55:52,945 --> 02:55:57,296
and over here I'm just going to take out all the vowels that was a e I o u.
5160
02:55:57,355 --> 02:55:57,655
and
5161
02:55:57,686 --> 02:55:58,375
a e
5162
02:55:58,555 --> 02:55:58,795
I
5163
02:55:58,854 --> 02:55:59,364
o to you.
5164
02:56:00,055 --> 02:56:02,125
I'm basically checking to see if the letter
5165
02:56:02,305 --> 02:56:03,324
is inside of
5166
02:56:03,354 --> 02:56:04,645
this string
5167
02:56:04,854 --> 02:56:06,774
and if the letter is inside of here,
5168
02:56:06,984 --> 02:56:08,154
then we know that it's
5169
02:56:08,185 --> 02:56:09,115
a vowel so
5170
02:56:09,146 --> 02:56:11,097
down here we can handle that case
5171
02:56:11,127 --> 02:56:12,026
so I can say.
5172
02:56:12,687 --> 02:56:13,677
translation
5173
02:56:14,637 --> 02:56:15,597
is equal to
5174
02:56:16,167 --> 02:56:17,037
translation
5175
02:56:17,247 --> 02:56:18,117
plus
5176
02:56:18,598 --> 02:56:19,138
g
5177
02:56:19,888 --> 02:56:20,697
because
5178
02:56:21,147 --> 02:56:21,598
if
5179
02:56:21,928 --> 02:56:25,619
this letter is a vowel we just wanted to convert it into a g.
5180
02:56:26,459 --> 02:56:27,629
otherwise though
5181
02:56:28,739 --> 02:56:30,301
I can basically just say
5182
02:56:31,201 --> 02:56:32,102
translation
5183
02:56:32,132 --> 02:56:32,972
is equal to
5184
02:56:33,542 --> 02:56:34,322
translation
5185
02:56:34,382 --> 02:56:35,102
plus
5186
02:56:35,552 --> 02:56:36,092
letter.
5187
02:56:36,452 --> 02:56:40,261
so in the case where we have a vowel I'm adding a g onto
5188
02:56:40,291 --> 02:56:40,981
translation
5189
02:56:41,012 --> 02:56:42,571
and the case where we don't have a vowel.
5190
02:56:42,812 --> 02:56:43,802
I'm just adding on
5191
02:56:43,832 --> 02:56:46,622
whatever letter it was on to translation so
5192
02:56:47,042 --> 02:56:49,621
finally down below this for loop
5193
02:56:49,651 --> 02:56:51,481
we just want to return
5194
02:56:51,541 --> 02:56:53,521
the translation so I'm just going to say
5195
02:56:54,002 --> 02:56:54,752
return
5196
02:56:54,902 --> 02:56:55,742
translation.
5197
02:56:56,612 --> 02:56:57,332
and now we have
5198
02:56:57,362 --> 02:56:57,933
a
5199
02:56:57,963 --> 02:56:59,462
awesome translate function
5200
02:56:59,492 --> 02:57:00,151
and it should
5201
02:57:00,331 --> 02:57:01,651
probably work so
5202
02:57:01,921 --> 02:57:03,781
let's come down here and we'll test it out so
5203
02:57:04,021 --> 02:57:07,562
we only allow a user to input some information so
5204
02:57:07,592 --> 02:57:09,513
I'm basically going to call this function.
5205
02:57:09,663 --> 02:57:11,252
actually we're going to print it out so
5206
02:57:11,672 --> 02:57:14,281
we'll print this out and I'm going to call this function
5207
02:57:15,991 --> 02:57:16,801
translate
5208
02:57:17,281 --> 02:57:17,642
and
5209
02:57:17,672 --> 02:57:19,652
inside of here I'm actually just gonna
5210
02:57:19,683 --> 02:57:20,492
pass
5211
02:57:20,822 --> 02:57:21,872
whatever the user
5212
02:57:21,902 --> 02:57:22,473
inputs
5213
02:57:22,503 --> 02:57:23,133
so
5214
02:57:23,463 --> 02:57:24,453
I can just say
5215
02:57:24,543 --> 02:57:25,353
input
5216
02:57:25,562 --> 02:57:25,982
and
5217
02:57:26,013 --> 02:57:28,773
inside of these parentheses I can say the problem so
5218
02:57:29,313 --> 02:57:30,813
enter a phrase,
5219
02:57:31,174 --> 02:57:31,983
and so now
5220
02:57:32,224 --> 02:57:36,216
I'm basically combining all these statements together I'm saying I want to print
5221
02:57:36,246 --> 02:57:36,696
out
5222
02:57:37,326 --> 02:57:38,587
the translation
5223
02:57:38,887 --> 02:57:41,228
of whatever the user enters in.
5224
02:57:42,037 --> 02:57:44,107
so let's go ahead and run this program
5225
02:57:44,138 --> 02:57:45,548
and we'll see how we do
5226
02:57:45,578 --> 02:57:46,118
so
5227
02:57:46,208 --> 02:57:47,198
I'm gonna run the program
5228
02:57:47,258 --> 02:57:47,858
it says
5229
02:57:47,889 --> 02:57:49,389
enter a phrase actually let me
5230
02:57:49,479 --> 02:57:50,859
format this a little bit better.
5231
02:57:52,300 --> 02:57:52,569
okay
5232
02:57:55,209 --> 02:57:57,549
that's it says enter a phrase.
5233
02:57:57,608 --> 02:57:58,810
so let's go ahead and do that.
5234
02:57:59,079 --> 02:57:59,529
so
5235
02:57:59,560 --> 02:58:00,579
let's just type in
5236
02:58:00,729 --> 02:58:02,799
the example we use before him and say dog
5237
02:58:03,339 --> 02:58:05,919
and so now out pops the answer which is
5238
02:58:05,949 --> 02:58:06,520
d
5239
02:58:06,550 --> 02:58:07,450
g g.
5240
02:58:07,750 --> 02:58:08,619
so that's kind of cool.
5241
02:58:08,709 --> 02:58:12,218
and we can just keep running this as many times as we want so I could type only.
5242
02:58:12,397 --> 02:58:14,346
to be or not to be,
5243
02:58:14,826 --> 02:58:16,595
this is like a little bit longer of a string,
5244
02:58:16,984 --> 02:58:17,795
and you can see
5245
02:58:17,825 --> 02:58:19,627
it translates it into our
5246
02:58:19,657 --> 02:58:20,647
draft language.
5247
02:58:20,917 --> 02:58:23,227
so that's basically how we can
5248
02:58:23,467 --> 02:58:25,956
create our little a translator out and that's pretty cool.
5249
02:58:26,256 --> 02:58:28,356
as you can see we're using a for loop
5250
02:58:28,387 --> 02:58:30,127
in combination with an
5251
02:58:30,157 --> 02:58:32,466
f loop and that's a really powerful structure
5252
02:58:32,826 --> 02:58:35,287
and actually there's one place over here where we can
5253
02:58:35,347 --> 02:58:37,387
make this a little bit more efficient so
5254
02:58:37,627 --> 02:58:38,497
instead of saying
5255
02:58:38,527 --> 02:58:38,857
if
5256
02:58:38,888 --> 02:58:40,058
letter in
5257
02:58:40,088 --> 02:58:41,078
this string.
5258
02:58:41,378 --> 02:58:43,898
you'll notice here I'm checking to see if it's in
5259
02:58:44,049 --> 02:58:46,359
all the lower case and the upper case.
5260
02:58:46,600 --> 02:58:48,009
I could actually just say if
5261
02:58:48,039 --> 02:58:48,609
letter
5262
02:58:48,640 --> 02:58:49,149
dot
5263
02:58:49,209 --> 02:58:49,929
lower
5264
02:58:50,738 --> 02:58:51,309
in
5265
02:58:51,488 --> 02:58:54,338
and now I only have to type out the lower case letters,
5266
02:58:54,488 --> 02:58:56,647
and it's still going to do the same exact thing so
5267
02:58:57,008 --> 02:58:58,027
that's a little like
5268
02:58:58,058 --> 02:58:58,538
hack
5269
02:58:58,568 --> 02:58:59,858
or whatever that we could use
5270
02:58:59,979 --> 02:59:02,499
and there's also one more problem with this program so
5271
02:59:02,529 --> 02:59:03,640
you'll notice down here
5272
02:59:03,909 --> 02:59:06,490
we're setting the translation equal to the translation
5273
02:59:06,521 --> 02:59:07,301
plus
5274
02:59:07,421 --> 02:59:08,081
g.
5275
02:59:08,351 --> 02:59:09,400
but the problem is if
5276
02:59:09,431 --> 02:59:10,750
I was to start
5277
02:59:11,320 --> 02:59:14,739
my word inside of the phrase with a capital vowel
5278
02:59:14,770 --> 02:59:16,148
so in other words if I said like
5279
02:59:16,389 --> 02:59:16,869
on,
5280
02:59:17,560 --> 02:59:19,420
you'll notice that when this gets printed out,
5281
02:59:19,570 --> 02:59:22,271
it gets printed out as lower case g and
5282
02:59:22,451 --> 02:59:24,191
so it's not keeping our
5283
02:59:24,281 --> 02:59:24,911
uppercase
5284
02:59:24,941 --> 02:59:25,722
syntax
5285
02:59:25,962 --> 02:59:27,401
and that's kind of a problem so
5286
02:59:27,671 --> 02:59:29,802
we can actually use another if statement in here
5287
02:59:29,892 --> 02:59:31,152
and we could check to see
5288
02:59:32,202 --> 02:59:32,742
if
5289
02:59:33,762 --> 02:59:34,662
letter dot
5290
02:59:34,692 --> 02:59:35,473
is
5291
02:59:36,492 --> 02:59:37,002
upper
5292
02:59:37,782 --> 02:59:39,763
and if the letter is upper case
5293
02:59:39,793 --> 02:59:40,303
then
5294
02:59:40,333 --> 02:59:42,583
we can just set the translation equal to
5295
02:59:42,823 --> 02:59:43,634
the translation
5296
02:59:43,664 --> 02:59:44,234
plus
5297
02:59:44,265 --> 02:59:45,314
a capital g,
5298
02:59:47,954 --> 02:59:48,944
otherwise,
5299
02:59:49,274 --> 02:59:51,704
we can just set it equal to the lower case g.
5300
02:59:52,544 --> 02:59:54,254
it's a now we're able to control
5301
02:59:54,284 --> 02:59:56,054
both of those situation so
5302
02:59:56,594 --> 02:59:58,693
let's just test this and see if it works
5303
02:59:59,563 --> 03:00:00,613
and to rephrase
5304
03:00:00,883 --> 03:00:01,692
say on.
5305
03:00:02,112 --> 03:00:03,942
and now we're keeping that
5306
03:00:04,242 --> 03:00:05,352
capital letter so
5307
03:00:05,562 --> 03:00:08,771
those are just a couple different ways that we could make this program a little bit better,
5308
03:00:09,071 --> 03:00:11,172
but the basic concept is we have a for loop
5309
03:00:11,202 --> 03:00:11,803
and then we have some
5310
03:00:11,833 --> 03:00:12,882
if loops inside of it,
5311
03:00:13,122 --> 03:00:17,291
and we're calling this awesome function that can translate a word for us
5312
03:00:21,191 --> 03:00:25,062
in this tutorial I wanna talk to you guys about comments in python.
5313
03:00:25,362 --> 03:00:32,110
this is going to be a pretty short tutorial I just want to give you an overview of what comments are and how we can use them in our python programs.
5314
03:00:32,591 --> 03:00:33,431
so over here
5315
03:00:33,521 --> 03:00:36,851
in my python program I just have this line here it says print
5316
03:00:36,881 --> 03:00:37,541
comments
5317
03:00:37,571 --> 03:00:38,262
are fun.
5318
03:00:38,531 --> 03:00:39,881
so if I run my program
5319
03:00:40,150 --> 03:00:44,949
down here inside of the council it's going to print out comments are fun right,
5320
03:00:45,430 --> 03:00:47,619
so any code that I put over here is
5321
03:00:47,649 --> 03:00:49,629
going to get executed by python,
5322
03:00:50,079 --> 03:00:52,059
but there's actually a special
5323
03:00:52,089 --> 03:00:54,010
line of code that we can write
5324
03:00:54,189 --> 03:00:55,449
and it's called a comment
5325
03:00:55,749 --> 03:01:01,899
and a comment is basically a line inside of our python file that's just not going to get rendered by python,
5326
03:01:02,199 --> 03:01:06,639
so in python sees it as just going to ignore it it's not going to execute its not going to print anything out.
5327
03:01:07,059 --> 03:01:09,849
it's just gonna kind of ignore it and comments are
5328
03:01:09,879 --> 03:01:12,488
basically just used for us humans,
5329
03:01:12,788 --> 03:01:16,658
so a comment is used for like me or another developer to
5330
03:01:16,898 --> 03:01:21,876
write a little comment a little like plain tax dino comment inside of a file
5331
03:01:22,296 --> 03:01:23,105
nor retreat of
5332
03:01:23,165 --> 03:01:23,735
a comment
5333
03:01:23,766 --> 03:01:24,695
I could use this
5334
03:01:24,726 --> 03:01:25,926
hashtag symbol.
5335
03:01:26,256 --> 03:01:28,146
so in click hashtag and now I'm
5336
03:01:28,205 --> 03:01:29,285
writing a comment.
5337
03:01:29,705 --> 03:01:32,343
so I can write whatever I wanted in here I could say like
5338
03:01:32,493 --> 03:01:33,213
this
5339
03:01:33,843 --> 03:01:34,473
program
5340
03:01:34,503 --> 03:01:35,283
is cool
5341
03:01:36,093 --> 03:01:36,543
and
5342
03:01:36,603 --> 03:01:38,372
you'll notice when I run the program
5343
03:01:38,972 --> 03:01:40,502
that doesn't show up anywhere.
5344
03:01:40,562 --> 03:01:42,092
it doesn't matter what
5345
03:01:42,212 --> 03:01:43,592
I put off at halftime
5346
03:01:43,622 --> 03:01:45,602
this is just like ignore by python,
5347
03:01:45,871 --> 03:01:49,111
it's just for me or another developer to come in here and use.
5348
03:01:49,441 --> 03:01:51,960
so a lot of times you want to write like a little note
5349
03:01:51,990 --> 03:01:55,770
inside of your python files or maybe you can write yourself a little reminder.
5350
03:01:56,159 --> 03:01:57,209
or if you want to write
5351
03:01:57,239 --> 03:01:59,939
a line to lay explain a line of code
5352
03:02:00,090 --> 03:02:00,689
to for example
5353
03:02:00,720 --> 03:02:02,879
I can write a comment that would explain
5354
03:02:02,909 --> 03:02:04,589
this print statement sighted sailing
5355
03:02:04,619 --> 03:02:05,369
this
5356
03:02:05,909 --> 03:02:06,299
prints
5357
03:02:06,329 --> 03:02:06,689
out
5358
03:02:06,720 --> 03:02:07,799
a string
5359
03:02:07,829 --> 03:02:08,189
right
5360
03:02:08,459 --> 03:02:12,058
now anybody looking at my file would be able to read this and they'd be like,
5361
03:02:12,117 --> 03:02:13,527
oh that's what this does ok
5362
03:02:13,558 --> 03:02:13,918
cool
5363
03:02:14,578 --> 03:02:16,199
so comments are useful for
5364
03:02:16,529 --> 03:02:19,019
leaving little comments in a python file
5365
03:02:19,318 --> 03:02:20,068
you want to make
5366
03:02:20,128 --> 03:02:21,568
comments on multiple lines.
5367
03:02:21,778 --> 03:02:24,658
you can just create a new line and use another hashtag
5368
03:02:24,958 --> 03:02:27,566
and so that I could type out whatever my next comment was
5369
03:02:27,896 --> 03:02:32,877
I mean generally if you're gonna put comments on multiple lines you want to just use multiple hash tags
5370
03:02:33,327 --> 03:02:33,657
plot
5371
03:02:33,688 --> 03:02:36,746
there's actually another way that you can write out comments
5372
03:02:36,776 --> 03:02:38,486
so you can use a triple
5373
03:02:38,756 --> 03:02:41,485
quotation marks so I'm typing out these single quote
5374
03:02:42,355 --> 03:02:44,064
and I'm typing not three times
5375
03:02:44,095 --> 03:02:45,295
so you can see here,
5376
03:02:45,625 --> 03:02:48,654
up here we have this three times we have this three times.
5377
03:02:48,895 --> 03:02:52,586
so in here I can you know write any comment that I wanted so I can
5378
03:02:52,616 --> 03:02:53,275
put you know
5379
03:02:53,545 --> 03:02:55,405
as much taxed up here as I would want.
5380
03:02:56,215 --> 03:02:56,814
and
5381
03:02:56,904 --> 03:02:58,854
same thing when I run this program.
5382
03:02:58,975 --> 03:03:00,774
it's just not going to get rendered so
5383
03:03:00,805 --> 03:03:02,544
this is another way to make
5384
03:03:02,574 --> 03:03:04,494
multiple line comments
5385
03:03:04,854 --> 03:03:08,785
but the link official python like style guides or whatever
5386
03:03:08,995 --> 03:03:14,215
just recommends that if you're going to put comments on multiple lines you used these hashtags so
5387
03:03:14,515 --> 03:03:17,484
you know you can really do whatever you want but if you want to be like super
5388
03:03:17,515 --> 03:03:18,925
python official then
5389
03:03:19,255 --> 03:03:20,334
use these hashtags
5390
03:03:21,144 --> 03:03:22,974
comments can also be useful for
5391
03:03:23,004 --> 03:03:26,062
doing something called commenting out a line of code.
5392
03:03:26,362 --> 03:03:28,221
a lot of times when you're writing a program,
5393
03:03:28,431 --> 03:03:30,410
you might have a line of code in there
5394
03:03:30,500 --> 03:03:30,980
that
5395
03:03:31,011 --> 03:03:33,771
is maybe like potentially making stuff up.
5396
03:03:34,191 --> 03:03:36,411
and so what you can do is you can actually comment
5397
03:03:36,441 --> 03:03:37,971
out that line of code so
5398
03:03:38,181 --> 03:03:40,911
I can put a comment in front of this line of code.
5399
03:03:41,211 --> 03:03:42,951
and now when I run my program.
5400
03:03:43,071 --> 03:03:44,481
the program is going to run,
5401
03:03:44,661 --> 03:03:45,981
but it's not going to use
5402
03:03:46,041 --> 03:03:46,851
this line
5403
03:03:47,061 --> 03:03:49,940
so sometimes if you're trying to see if like a line of code is
5404
03:03:50,091 --> 03:03:54,199
causing you trouble or if you want to see what your program would be like without a line of code
5405
03:03:54,439 --> 03:03:55,939
or even like a block of code,
5406
03:03:56,119 --> 03:03:57,379
you can just commented out.
5407
03:03:57,559 --> 03:03:59,989
and that way you're not actually deleting the code
5408
03:04:00,020 --> 03:04:01,130
from your file
5409
03:04:01,340 --> 03:04:04,130
you're just commenting it out so pythons gonna ignore it,
5410
03:04:04,460 --> 03:04:08,149
and those are really the two uses for comments as to write little notes
5411
03:04:08,749 --> 03:04:10,519
right little comments about different things
5412
03:04:10,549 --> 03:04:11,718
or to comment
5413
03:04:11,748 --> 03:04:12,828
out code and
5414
03:04:13,038 --> 03:04:14,418
as you go forward and python
5415
03:04:14,448 --> 03:04:16,338
I'm sure you'll find uses for
5416
03:04:16,368 --> 03:04:17,059
comments
5417
03:04:20,839 --> 03:04:23,419
in this tutorial on a talk to you guys about
5418
03:04:23,449 --> 03:04:25,220
catching errors in
5419
03:04:25,250 --> 03:04:25,880
python,
5420
03:04:26,300 --> 03:04:28,549
and a lot of times when we're writing python programs
5421
03:04:28,938 --> 03:04:29,898
you'll encounter of an
5422
03:04:29,929 --> 03:04:32,327
error so different situations could come up
5423
03:04:32,597 --> 03:04:35,985
and your program might throw an error or it might throw an exception.
5424
03:04:36,315 --> 03:04:37,604
and a lot of times when these
5425
03:04:37,635 --> 03:04:41,234
situations happen though completely stop your program from running.
5426
03:04:41,954 --> 03:04:44,834
and what we can actually do is we can watch out for
5427
03:04:44,894 --> 03:04:47,294
you know a certain specific errors that are going to
5428
03:04:47,324 --> 03:04:49,904
pop up in our program and we can actually handle them.
5429
03:04:50,294 --> 03:04:53,475
so instead of our program just breaking and stop executing,
5430
03:04:53,625 --> 03:04:57,255
we can actually handle those errors and do things when they occur so
5431
03:04:57,615 --> 03:05:01,726
I want to show you guys an example of using this down here I'm saying number is equal to
5432
03:05:01,785 --> 03:05:02,295
its
5433
03:05:02,745 --> 03:05:03,944
input enter a number,
5434
03:05:04,185 --> 03:05:07,635
basically what's happening is I'm prompting the user to enter into a number
5435
03:05:07,665 --> 03:05:08,895
using this input command
5436
03:05:09,404 --> 03:05:11,774
and then I'm converting whatever they entered
5437
03:05:11,895 --> 03:05:12,824
into an integer.
5438
03:05:13,305 --> 03:05:17,685
so as long as they enter in like a valid integer I can convert it into an integer.
5439
03:05:18,104 --> 03:05:20,265
so I can convert it into like a whole number
5440
03:05:20,505 --> 03:05:22,695
and I can store it inside of this number variable
5441
03:05:22,726 --> 03:05:25,486
that I'm just printing it out so let's try to execute this program,
5442
03:05:25,906 --> 03:05:26,985
I'm going around the program
5443
03:05:27,855 --> 03:05:29,834
and you'll see down here it says enter a number,
5444
03:05:30,134 --> 03:05:32,624
so we can enter in like four for example
5445
03:05:33,044 --> 03:05:36,942
and when I answer in four everything's going to work and it's just going to print out four and
5446
03:05:37,002 --> 03:05:38,261
everything is right in the world.
5447
03:05:38,951 --> 03:05:41,801
and actually I'm going to modify this appears it's a little easier to see.
5448
03:05:42,400 --> 03:05:44,260
but what if we run the program again.
5449
03:05:44,560 --> 03:05:46,270
so it says okay enter your number.
5450
03:05:46,449 --> 03:05:51,640
let's say that I break the rules might don't enter a number so it is ignore what the prompts says and I put
5451
03:05:52,120 --> 03:05:52,480
you know
5452
03:05:52,511 --> 03:05:53,860
some random text in here,
5453
03:05:54,400 --> 03:05:56,142
now when I enter this
5454
03:05:56,741 --> 03:05:58,392
the program's going to throw an error,
5455
03:05:58,542 --> 03:06:00,853
you see down here it says value error
5456
03:06:01,122 --> 03:06:01,632
invalid
5457
03:06:01,662 --> 03:06:03,103
literal for ants
5458
03:06:03,133 --> 03:06:03,673
base
5459
03:06:03,703 --> 03:06:04,483
with basten
5460
03:06:04,813 --> 03:06:05,474
basically
5461
03:06:05,504 --> 03:06:06,704
paved and answering
5462
03:06:06,854 --> 03:06:07,694
an integer like
5463
03:06:07,725 --> 03:06:08,504
you said you would
5464
03:06:08,773 --> 03:06:09,193
write.
5465
03:06:09,373 --> 03:06:10,962
we told them to enter in a number
5466
03:06:10,992 --> 03:06:12,402
they entered in text
5467
03:06:12,522 --> 03:06:13,873
so it broke the program.
5468
03:06:14,443 --> 03:06:14,833
and
5469
03:06:14,863 --> 03:06:20,530
this is a situation that happens a lot so there's a lot of them in situations where something can just go wrong in our program.
5470
03:06:20,920 --> 03:06:24,009
and up until now we've just kind of accepted it as a reality
5471
03:06:24,039 --> 03:06:24,520
but
5472
03:06:24,729 --> 03:06:27,190
if you're writing a real live python program
5473
03:06:27,221 --> 03:06:30,162
you don't want something like this to trip up your program,
5474
03:06:30,312 --> 03:06:34,031
you don't want the entire program to break when somebody just forgets to enter in a number
5475
03:06:34,361 --> 03:06:34,571
right
5476
03:06:34,602 --> 03:06:37,271
you want to be able to handle all these different situations,
5477
03:06:37,571 --> 03:06:37,991
and
5478
03:06:38,142 --> 03:06:39,732
in order to handle them we can use
5479
03:06:39,763 --> 03:06:42,313
something called a try except block
5480
03:06:42,613 --> 03:06:46,364
in a try accept blog will basically allow your programs to try out
5481
03:06:46,994 --> 03:06:47,894
a piece of code,
5482
03:06:48,044 --> 03:06:50,204
and if everything goes well then we're great like
5483
03:06:50,414 --> 03:06:52,545
we could try out entering in the number
5484
03:06:52,575 --> 03:06:54,555
and if the user enters into correct number great,
5485
03:06:54,854 --> 03:06:58,334
but if they don't enter in the correct number then we can basically like
5486
03:06:58,424 --> 03:07:02,683
account for that so they entered it in something like a string when they're supposed to render in a number.
5487
03:07:02,982 --> 03:07:05,441
we could tell them like hey you entered in the wrong thing
5488
03:07:05,892 --> 03:07:09,911
so I'm sure you guys how we can use these try accept blocks are going to come up here
5489
03:07:10,271 --> 03:07:11,651
and I'm just going to say try
5490
03:07:12,432 --> 03:07:13,302
to make a colon.
5491
03:07:13,602 --> 03:07:14,892
and I want to indent.
5492
03:07:14,981 --> 03:07:15,971
both of these things.
5493
03:07:16,121 --> 03:07:18,760
so both of these things are going to be inside of this
5494
03:07:18,790 --> 03:07:19,900
try block.
5495
03:07:20,290 --> 03:07:23,259
now I'm going to make a new line I'm going to come down here and I'm just going to tape out
5496
03:07:24,068 --> 03:07:24,849
except.
5497
03:07:25,028 --> 03:07:26,707
and I'm also going to put a colon here,
5498
03:07:27,097 --> 03:07:29,917
and down here I'm just going to print something out so I'll just say like
5499
03:07:30,427 --> 03:07:31,117
invalid
5500
03:07:31,147 --> 03:07:31,657
input.
5501
03:07:32,167 --> 03:07:32,917
so now
5502
03:07:32,947 --> 03:07:35,945
since I put this code inside of this try block.
5503
03:07:36,665 --> 03:07:38,766
if the user enters in something wrong
5504
03:07:38,796 --> 03:07:42,487
it's going to be able to catch it so it'll be able to catch what the user does wrong
5505
03:07:42,787 --> 03:07:43,627
and print out
5506
03:07:43,657 --> 03:07:45,547
invalid input onto the stream.
5507
03:07:45,877 --> 03:07:47,587
so let's go ahead and run our program.
5508
03:07:48,517 --> 03:07:50,197
and it's just gonna say enter a number.
5509
03:07:50,348 --> 03:07:52,717
so we're going to ignore that will enter this end
5510
03:07:53,017 --> 03:07:55,508
and now instead of yelling at us in breaking the program
5511
03:07:55,538 --> 03:07:56,468
just says hey
5512
03:07:56,498 --> 03:07:57,368
invalid input.
5513
03:07:58,059 --> 03:08:02,919
so was able to handle the error they got called it was able to handle the invalid
5514
03:08:02,949 --> 03:08:03,850
input error
5515
03:08:04,180 --> 03:08:05,800
basically just told us hey
5516
03:08:06,100 --> 03:08:06,910
nowhere input.
5517
03:08:07,330 --> 03:08:07,960
so
5518
03:08:07,990 --> 03:08:11,200
this is a really powerful thing that we can do in our python programs
5519
03:08:11,561 --> 03:08:13,480
basically just to protect our programs
5520
03:08:13,511 --> 03:08:13,811
right
5521
03:08:14,080 --> 03:08:17,050
if I want to have my program running for long period the time
5522
03:08:17,080 --> 03:08:19,510
I can't have something as simple as an invalid
5523
03:08:19,540 --> 03:08:19,960
input
5524
03:08:19,990 --> 03:08:20,650
trip it up
5525
03:08:20,920 --> 03:08:24,158
so I can catch that invalid input using these try except
5526
03:08:24,188 --> 03:08:24,729
blocks.
5527
03:08:24,969 --> 03:08:26,737
but here's the thing you notice that this
5528
03:08:26,768 --> 03:08:28,447
little guy down here is getting
5529
03:08:28,688 --> 03:08:29,348
highlighted.
5530
03:08:29,768 --> 03:08:32,587
and let's just see what it has to say so it's basically saying
5531
03:08:32,797 --> 03:08:34,988
two broad exception clause.
5532
03:08:35,588 --> 03:08:36,038
and
5533
03:08:36,068 --> 03:08:39,668
this is a message that we're getting because when I just say accept
5534
03:08:39,758 --> 03:08:40,658
this will catch
5535
03:08:40,688 --> 03:08:44,587
any error under the sun so anything that can go wrong in my program for the most part
5536
03:08:44,617 --> 03:08:46,148
this is gonna accept it so
5537
03:08:46,898 --> 03:08:48,157
let me give you guys an example,
5538
03:08:48,427 --> 03:08:50,557
let's say I had in my program
5539
03:08:50,646 --> 03:08:52,388
I was creating a variable right so I'm
5540
03:08:52,418 --> 03:08:52,628
gonna
5541
03:08:52,658 --> 03:08:54,219
create a variable called
5542
03:08:54,549 --> 03:08:57,877
value and I set it equal to ten divided by the zero.
5543
03:08:58,327 --> 03:08:59,467
now if you know anything about math
5544
03:08:59,497 --> 03:09:02,978
you'll know that you can't divide a number by zero it's not possible.
5545
03:09:03,218 --> 03:09:03,698
so
5546
03:09:03,729 --> 03:09:04,508
the program
5547
03:09:04,538 --> 03:09:08,229
isn't going to be able to handle this and you'll see that this is going to throw an error for us.
5548
03:09:08,498 --> 03:09:09,729
so I run the program.
5549
03:09:10,179 --> 03:09:11,169
it basically says
5550
03:09:11,199 --> 03:09:13,360
zero division enter division by zero,
5551
03:09:13,420 --> 03:09:14,771
we're not allowed to do that right.
5552
03:09:15,311 --> 03:09:19,062
if I took this and I put this down and out of this try block.
5553
03:09:20,441 --> 03:09:20,951
and
5554
03:09:20,981 --> 03:09:22,481
I just pasted it in here,
5555
03:09:23,201 --> 03:09:25,452
it's going to get caught by this exception
5556
03:09:25,482 --> 03:09:29,351
that we wrote down here so it's going to get caught by that accepts and when I run the program
5557
03:09:29,650 --> 03:09:30,850
you'll see it says
5558
03:09:30,909 --> 03:09:31,960
invalid input.
5559
03:09:32,590 --> 03:09:34,449
but the problem is that we didn't
5560
03:09:34,539 --> 03:09:36,069
input something that was invalid
5561
03:09:36,220 --> 03:09:36,640
right
5562
03:09:37,000 --> 03:09:38,351
we just divided by zero
5563
03:09:38,381 --> 03:09:39,101
but it wasn't
5564
03:09:39,131 --> 03:09:40,301
able to handle that.
5565
03:09:40,360 --> 03:09:42,610
right so it could not divide by zero
5566
03:09:42,700 --> 03:09:43,540
it through an error.
5567
03:09:43,600 --> 03:09:45,580
so even though we didn't get an invalid
5568
03:09:45,610 --> 03:09:49,301
input even though it was because we divided by zero it's still printed this out.
5569
03:09:49,631 --> 03:09:52,781
and this brings me up to another point is we can actually catch
5570
03:09:53,081 --> 03:09:54,191
or we can accept
5571
03:09:54,222 --> 03:09:56,441
specific types of errors.
5572
03:09:56,711 --> 03:09:57,761
so for example
5573
03:09:57,940 --> 03:10:00,340
in this case we got a division by zero error
5574
03:10:00,550 --> 03:10:01,779
in this case we got
5575
03:10:01,869 --> 03:10:03,879
an invalid input air I we we
5576
03:10:03,909 --> 03:10:05,198
put something in that was wrong you
5577
03:10:05,229 --> 03:10:06,699
can convert the value.
5578
03:10:06,879 --> 03:10:12,100
so I can create two different except blocks to catch two different types of error so down here
5579
03:10:12,460 --> 03:10:16,869
I can just make a space and I can specify the type of error that I want to catch.
5580
03:10:17,139 --> 03:10:19,630
so when we divided by zero it was
5581
03:10:19,870 --> 03:10:21,490
zero division air.
5582
03:10:21,910 --> 03:10:24,340
so if I just put zero division error in here.
5583
03:10:24,580 --> 03:10:27,640
now it's going to catch that zero division later so I can say
5584
03:10:28,239 --> 03:10:29,920
divided by zero.
5585
03:10:30,310 --> 03:10:32,950
I can also make another accepts I could say
5586
03:10:33,040 --> 03:10:33,790
accepts
5587
03:10:34,210 --> 03:10:34,780
and
5588
03:10:34,900 --> 03:10:38,080
we can catch the other exception that we got so I think it was
5589
03:10:38,320 --> 03:10:40,000
a value air right now is
5590
03:10:40,120 --> 03:10:42,220
we put in the wrong type of value
5591
03:10:42,580 --> 03:10:43,661
inside of that
5592
03:10:43,812 --> 03:10:45,762
inputs so now we can print out
5593
03:10:46,092 --> 03:10:47,202
invalid input.
5594
03:10:47,442 --> 03:10:47,982
so
5595
03:10:48,013 --> 03:10:51,854
with these two except blocks were basically able to handle both of these
5596
03:10:51,884 --> 03:10:53,084
situations so
5597
03:10:53,414 --> 03:10:54,314
for example if
5598
03:10:54,345 --> 03:10:57,314
this ends up breaking the program this division by zero,
5599
03:10:57,675 --> 03:11:00,794
then it'll be able to catch that so down here it'll tell us.
5600
03:11:00,854 --> 03:11:01,334
hey
5601
03:11:01,394 --> 03:11:02,534
you divided by zero,
5602
03:11:02,954 --> 03:11:04,635
but if I was to get rid of
5603
03:11:04,665 --> 03:11:05,775
this line of code,
5604
03:11:06,405 --> 03:11:06,945
and
5605
03:11:06,976 --> 03:11:07,695
I just
5606
03:11:07,905 --> 03:11:09,135
entered in the number wrong
5607
03:11:09,375 --> 03:11:10,995
so I came down here and I answered in
5608
03:11:11,025 --> 03:11:12,346
a string set of a number.
5609
03:11:12,615 --> 03:11:13,517
now it's going to
5610
03:11:13,547 --> 03:11:15,108
tell us invalid input so
5611
03:11:15,318 --> 03:11:16,968
we're going to be able to specify
5612
03:11:16,998 --> 03:11:19,248
what happens when certain things break.
5613
03:11:19,518 --> 03:11:20,777
so when we get a valid it
5614
03:11:20,837 --> 03:11:23,117
when we get a value error we can say invalid
5615
03:11:23,147 --> 03:11:23,628
input.
5616
03:11:23,688 --> 03:11:29,928
when we get a zero division error we can say divided by zero and depending on what breaks depending on what happens,
5617
03:11:30,348 --> 03:11:31,548
we can actually
5618
03:11:31,578 --> 03:11:32,868
do different things,
5619
03:11:33,138 --> 03:11:34,067
and I want to show you guys
5620
03:11:34,098 --> 03:11:35,748
one more thing we can do which is
5621
03:11:35,928 --> 03:11:37,578
we can actually store
5622
03:11:37,608 --> 03:11:38,118
this
5623
03:11:38,178 --> 03:11:39,768
error as a variable.
5624
03:11:39,857 --> 03:11:41,327
so I can say except
5625
03:11:41,567 --> 03:11:42,798
I can say as
5626
03:11:42,978 --> 03:11:46,216
and I can type in a name here so a lot of times people will just say like.
5627
03:11:46,275 --> 03:11:47,236
ye are our
5628
03:11:48,076 --> 03:11:48,976
and down here
5629
03:11:49,216 --> 03:11:52,306
I can print out the actual error so I can just print
5630
03:11:52,786 --> 03:11:53,656
e r r.
5631
03:11:53,926 --> 03:11:56,027
and so if we end up dividing by zero.
5632
03:11:57,047 --> 03:12:00,167
so if I say answer is equal to ten divided by zero.
5633
03:12:00,797 --> 03:12:03,076
we're going to throw this error and it's going to print
5634
03:12:03,106 --> 03:12:04,756
out what went wrong so
5635
03:12:04,786 --> 03:12:06,227
now I can run this program
5636
03:12:06,496 --> 03:12:07,636
and it just says
5637
03:12:08,025 --> 03:12:09,105
division by zero
5638
03:12:09,136 --> 03:12:09,496
so it
5639
03:12:09,526 --> 03:12:10,486
just printed out
5640
03:12:10,517 --> 03:12:11,747
the error that we got.
5641
03:12:12,077 --> 03:12:14,747
so that's another useful thing you can do is you can actually print
5642
03:12:14,777 --> 03:12:17,209
out the specific error that got thrown.
5643
03:12:17,389 --> 03:12:17,898
now
5644
03:12:18,049 --> 03:12:21,081
a best practice in python is to use these
5645
03:12:21,111 --> 03:12:23,751
specific error so you always want to accept
5646
03:12:23,781 --> 03:12:25,521
and except for a specific
5647
03:12:25,552 --> 03:12:25,912
error
5648
03:12:27,472 --> 03:12:29,271
when you don't want to do is just say
5649
03:12:29,302 --> 03:12:30,202
except
5650
03:12:30,592 --> 03:12:31,162
and
5651
03:12:31,372 --> 03:12:33,472
then just accept anything under the sun.
5652
03:12:34,042 --> 03:12:35,332
it's this too broad
5653
03:12:35,362 --> 03:12:35,843
and
5654
03:12:36,022 --> 03:12:40,612
if not in good practice and pythons you wanna be catching specific errors like this
5655
03:12:44,422 --> 03:12:47,393
in this tutorial on a talk to you guys about reading from
5656
03:12:47,452 --> 03:12:48,951
external files in
5657
03:12:48,981 --> 03:12:49,672
python,
5658
03:12:50,152 --> 03:12:52,700
you know a lot of times in python you're going to want to
5659
03:12:52,730 --> 03:12:53,330
read
5660
03:12:53,360 --> 03:12:56,781
from files that are outside of your python file,
5661
03:12:57,081 --> 03:13:02,959
so you might want to read information from like a text file or a csv file or like an html file.
5662
03:13:03,439 --> 03:13:03,859
and
5663
03:13:03,890 --> 03:13:06,800
you can actually use something called the python
5664
03:13:06,859 --> 03:13:09,229
read command and it will allow you to
5665
03:13:09,260 --> 03:13:10,520
read a file
5666
03:13:10,729 --> 03:13:15,980
that is stored outside of your python file so you can use these files to get information or you can
5667
03:13:16,190 --> 03:13:18,800
parse through different files and do different things.
5668
03:13:19,160 --> 03:13:20,751
so I'm gonna show you guys the basics
5669
03:13:20,781 --> 03:13:22,102
of reading files
5670
03:13:22,132 --> 03:13:23,692
opening files closing files
5671
03:13:23,723 --> 03:13:24,863
doing all that stuff
5672
03:13:25,224 --> 03:13:26,903
over here I have this
5673
03:13:26,934 --> 03:13:27,653
file
5674
03:13:28,373 --> 03:13:29,933
called employees dot text
5675
03:13:30,232 --> 03:13:33,533
and it basically just lists out a bunch of different employees like
5676
03:13:33,773 --> 03:13:36,204
these can be employees in an office or whatever.
5677
03:13:36,564 --> 03:13:38,484
so it's just listing out all of this
5678
03:13:38,515 --> 03:13:39,385
information.
5679
03:13:39,654 --> 03:13:43,975
so let's say that inside of my app dot python file I wanted to read
5680
03:13:44,034 --> 03:13:45,414
the employees
5681
03:13:45,624 --> 03:13:46,974
inside of that file.
5682
03:13:47,273 --> 03:13:49,254
the first thing I have to do is actually
5683
03:13:49,313 --> 03:13:50,964
open that file from inside
5684
03:13:50,994 --> 03:13:51,624
python.
5685
03:13:51,954 --> 03:13:53,664
so I can use a special command
5686
03:13:53,694 --> 03:13:54,354
called
5687
03:13:54,624 --> 03:13:55,164
open.
5688
03:13:55,434 --> 03:13:56,454
so I can say open
5689
03:13:56,754 --> 03:13:57,084
and then
5690
03:13:57,114 --> 03:14:00,083
in here I can type in the name of the file that I want to
5691
03:14:00,113 --> 03:14:03,232
open so this is either going to be a relative path to the file.
5692
03:14:03,502 --> 03:14:05,572
an absolute path to the file or
5693
03:14:05,632 --> 03:14:07,492
just the files name if
5694
03:14:08,332 --> 03:14:09,112
both files
5695
03:14:09,143 --> 03:14:10,762
in the same directories on my case
5696
03:14:11,212 --> 03:14:13,671
app dot python and employees dot text
5697
03:14:13,701 --> 03:14:15,561
are in the same folder
5698
03:14:15,740 --> 03:14:19,997
within the same directory so I can just type out the name of the file liking to say
5699
03:14:20,327 --> 03:14:22,097
employees dot text.
5700
03:14:22,486 --> 03:14:25,605
and I want to put one more thing inside of this
5701
03:14:25,636 --> 03:14:26,535
open function,
5702
03:14:26,686 --> 03:14:27,886
and it's going to be the mode
5703
03:14:27,916 --> 03:14:29,626
that I want to open the file in
5704
03:14:29,866 --> 03:14:31,516
which you could actually open files in
5705
03:14:31,546 --> 03:14:32,835
a couple different modes
5706
03:14:33,075 --> 03:14:35,235
and the first mode is called read
5707
03:14:35,415 --> 03:14:36,194
so I just put an
5708
03:14:36,225 --> 03:14:38,205
r here and that's going to stand for a read
5709
03:14:38,505 --> 03:14:44,982
and this basically means that I only want to read the information inside the file I don't want to modify it I don't want to
5710
03:14:45,013 --> 03:14:45,643
change it.
5711
03:14:45,973 --> 03:14:50,442
I just want to read it I just want to see what's in the file and do some stuff without information.
5712
03:14:50,893 --> 03:14:51,553
another
5713
03:14:51,643 --> 03:14:52,902
mode is called right
5714
03:14:52,933 --> 03:14:54,372
so I can type in this w
5715
03:14:54,702 --> 03:14:56,532
and writing basically means that you can
5716
03:14:56,592 --> 03:14:58,451
change the file right you can write
5717
03:14:58,481 --> 03:15:01,032
new information you can change existing information.
5718
03:15:01,603 --> 03:15:02,593
there's another one called
5719
03:15:02,623 --> 03:15:03,163
a
5720
03:15:03,583 --> 03:15:03,883
and
5721
03:15:03,913 --> 03:15:05,502
a stands for a pen.
5722
03:15:05,802 --> 03:15:07,662
and it's basically means that you can
5723
03:15:07,782 --> 03:15:10,721
append information onto the end of the file so
5724
03:15:10,900 --> 03:15:13,301
you can't modify any of the information in the file.
5725
03:15:13,451 --> 03:15:15,041
you can't change any information
5726
03:15:15,071 --> 03:15:15,641
but you can
5727
03:15:15,700 --> 03:15:16,120
add
5728
03:15:16,150 --> 03:15:17,351
new information.
5729
03:15:17,681 --> 03:15:19,091
and there's one more which is
5730
03:15:19,181 --> 03:15:19,570
r
5731
03:15:19,601 --> 03:15:20,320
plus
5732
03:15:20,561 --> 03:15:21,971
and this basically means
5733
03:15:22,001 --> 03:15:22,601
read
5734
03:15:22,631 --> 03:15:24,401
and write so this will give you
5735
03:15:24,461 --> 03:15:26,922
all the power of reading and writing.
5736
03:15:27,072 --> 03:15:27,882
so in our case,
5737
03:15:28,212 --> 03:15:29,562
we are just going to be working with
5738
03:15:29,622 --> 03:15:32,081
regular are so we're going to be reading
5739
03:15:32,111 --> 03:15:33,281
from the file.
5740
03:15:33,791 --> 03:15:36,131
now this open function will essentially just
5741
03:15:36,161 --> 03:15:36,791
open
5742
03:15:36,821 --> 03:15:37,541
the
5743
03:15:37,601 --> 03:15:38,801
file so it's going to like
5744
03:15:38,831 --> 03:15:40,811
golden map file inside of our file system
5745
03:15:40,841 --> 03:15:41,470
opened it up
5746
03:15:41,770 --> 03:15:43,600
and it'll allow us to read through it
5747
03:15:43,779 --> 03:15:46,239
but generally we're going to want to store this
5748
03:15:46,270 --> 03:15:47,319
opened file
5749
03:15:47,350 --> 03:15:49,211
inside of a variable so
5750
03:15:49,541 --> 03:15:51,911
I can create a variable and we can just call it
5751
03:15:52,392 --> 03:15:53,892
employee file.
5752
03:15:54,161 --> 03:15:55,090
and I'm just going to set it
5753
03:15:55,120 --> 03:15:56,440
equal to this
5754
03:15:56,471 --> 03:15:57,370
open function.
5755
03:15:57,640 --> 03:15:58,480
so now the
5756
03:15:58,511 --> 03:16:00,940
open employees dot text file and
5757
03:16:00,971 --> 03:16:02,651
all the content inside of it
5758
03:16:03,041 --> 03:16:04,450
is stored inside of this
5759
03:16:04,480 --> 03:16:05,591
employee file
5760
03:16:05,621 --> 03:16:06,341
variable.
5761
03:16:06,791 --> 03:16:07,211
now
5762
03:16:07,271 --> 03:16:07,900
whenever you
5763
03:16:07,931 --> 03:16:08,830
open a file
5764
03:16:08,860 --> 03:16:10,630
you always want to make sure that you
5765
03:16:10,660 --> 03:16:12,911
close the file as well so
5766
03:16:13,271 --> 03:16:15,013
just like we have this open command
5767
03:16:15,043 --> 03:16:16,033
we also have
5768
03:16:16,063 --> 03:16:16,453
in
5769
03:16:16,543 --> 03:16:17,323
close
5770
03:16:17,354 --> 03:16:19,334
function so I can come down here and say.
5771
03:16:19,844 --> 03:16:20,624
employee
5772
03:16:20,654 --> 03:16:21,345
file
5773
03:16:21,375 --> 03:16:21,945
dot
5774
03:16:22,096 --> 03:16:22,876
clothes.
5775
03:16:23,236 --> 03:16:23,626
and
5776
03:16:23,656 --> 03:16:29,177
this is essentially just going to close the file so we're no longer going to be able to access it and
5777
03:16:29,537 --> 03:16:36,738
generally it's a good idea whenever you're opening up a file and you want to also make sure that your closing the file at some point so generally
5778
03:16:36,889 --> 03:16:39,019
once you're done reading it and you can just close it.
5779
03:16:39,288 --> 03:16:41,778
so that's kind of like how we can open and close the file.
5780
03:16:42,139 --> 03:16:45,498
now let's talk about how we can get information from the far right
5781
03:16:45,528 --> 03:16:48,110
there's no point having the file that we can't figure out what's in it
5782
03:16:48,141 --> 03:16:48,561
so
5783
03:16:48,740 --> 03:16:51,680
there's actually a few different functions that we can use
5784
03:16:51,739 --> 03:16:54,800
on this employee filed to figure out what's inside of it.
5785
03:16:55,250 --> 03:16:56,270
and I'm gonna show you guys
5786
03:16:56,300 --> 03:16:58,278
some of those so I'm just going to make a print statement.
5787
03:16:58,668 --> 03:16:59,208
and
5788
03:16:59,388 --> 03:17:02,688
inside this print statement will basically just print out some information
5789
03:17:02,718 --> 03:17:04,997
about the employee file so
5790
03:17:05,837 --> 03:17:08,747
the most basic thing we can print out is just the entire
5791
03:17:08,897 --> 03:17:10,217
contents of the file.
5792
03:17:10,486 --> 03:17:13,216
but before I do that I want to show you guys how you can check
5793
03:17:13,246 --> 03:17:15,465
to make sure that a file as readable.
5794
03:17:15,795 --> 03:17:19,427
so before we do anything else generally is a good idea to make sure
5795
03:17:19,457 --> 03:17:21,558
that it's possible to read this file.
5796
03:17:21,947 --> 03:17:22,427
and there's
5797
03:17:22,457 --> 03:17:23,597
a function
5798
03:17:23,656 --> 03:17:25,517
inside of python we can use called
5799
03:17:25,547 --> 03:17:27,407
readable so I'm just going to type out
5800
03:17:28,308 --> 03:17:29,388
in poorly file
5801
03:17:29,418 --> 03:17:30,048
dot
5802
03:17:31,488 --> 03:17:32,179
readable.
5803
03:17:32,629 --> 03:17:33,019
and
5804
03:17:33,049 --> 03:17:39,677
this is going to return a boolean value and it's going to tell us whether or not we can read from this file so I'm going to run my program
5805
03:17:40,547 --> 03:17:43,547
and you'll see down here we get a value of true
5806
03:17:43,877 --> 03:17:46,098
and that's because we set the file with
5807
03:17:46,128 --> 03:17:46,998
a read
5808
03:17:47,058 --> 03:17:49,396
mode so it's in read mode we can read from it.
5809
03:17:49,666 --> 03:17:50,625
if I was to put
5810
03:17:50,685 --> 03:17:52,845
a w here so if I put like right
5811
03:17:53,114 --> 03:17:53,685
now
5812
03:17:53,715 --> 03:17:58,306
redouble is going to be false because we can no longer read the file we can only write
5813
03:17:58,336 --> 03:17:59,506
to the file so
5814
03:17:59,596 --> 03:18:00,705
I'm going to
5815
03:18:00,735 --> 03:18:03,286
change this back to our so we can just read it.
5816
03:18:03,796 --> 03:18:07,006
so once you figure out whether or not the file can be read from
5817
03:18:07,036 --> 03:18:07,786
let's
5818
03:18:08,056 --> 03:18:09,286
actually read it so
5819
03:18:09,586 --> 03:18:15,770
there's another function called employee file dot read and this is basically just going to spit out all the information in the files
5820
03:18:15,800 --> 03:18:17,209
so when I run the program
5821
03:18:17,239 --> 03:18:18,561
it's just going to spit out
5822
03:18:18,591 --> 03:18:19,642
all of this
5823
03:18:19,672 --> 03:18:22,701
information right all the information isn't that was in that file.
5824
03:18:23,062 --> 03:18:29,392
I can also come down here and we could read an individual line inside this file so I can say employee filed dot
5825
03:18:29,422 --> 03:18:30,412
read line.
5826
03:18:30,652 --> 03:18:33,833
and what this is gonna do is it's gonna read an individual line
5827
03:18:34,253 --> 03:18:35,873
inside of this file so
5828
03:18:36,173 --> 03:18:40,972
now when I run this program you'll see it's just reading that first line in the file.
5829
03:18:41,092 --> 03:18:43,611
and this red line function is actually just
5830
03:18:43,642 --> 03:18:48,591
reading the first line and then it's basically like moving a little cursor onto the next line so
5831
03:18:48,831 --> 03:18:50,900
if I was to copy this line of code,
5832
03:18:51,530 --> 03:18:51,891
and then
5833
03:18:52,101 --> 03:18:53,570
printed again down here
5834
03:18:54,051 --> 03:18:56,480
I'm saying employee filed out read line.
5835
03:18:56,601 --> 03:18:58,069
so it's going to read the first line
5836
03:18:58,279 --> 03:19:00,621
and then when I say it again it's going to read
5837
03:19:00,681 --> 03:19:05,688
the line after that so this is actually going to end up printing out the first two lines in the file.
5838
03:19:06,198 --> 03:19:09,260
when I run this program you'll see we print out jim sales men
5839
03:19:09,470 --> 03:19:10,729
and dwight salesman.
5840
03:19:10,999 --> 03:19:14,808
so if I was to do this multiple times I could technically print out
5841
03:19:15,197 --> 03:19:17,718
every line inside of this file.
5842
03:19:18,857 --> 03:19:20,089
and you can see we can do that
5843
03:19:20,779 --> 03:19:27,140
and so that can be pretty useful for reading multiple lines in a file but there's actually another function that is better at doing that.
5844
03:19:27,590 --> 03:19:29,359
we can say instead of employee father
5845
03:19:29,390 --> 03:19:31,430
read line we can say dot read
5846
03:19:31,460 --> 03:19:32,330
lines.
5847
03:19:32,480 --> 03:19:34,252
and what this is gonna do is it's going to take
5848
03:19:34,282 --> 03:19:36,621
all of the lines inside of our file
5849
03:19:36,831 --> 03:19:38,511
and put them inside of an array.
5850
03:19:38,780 --> 03:19:42,471
and so now when I print this out you'll see we have this array down here it says
5851
03:19:42,740 --> 03:19:45,500
jim sales men that's the first item in the array
5852
03:19:45,680 --> 03:19:46,670
to white salesman
5853
03:19:46,700 --> 03:19:47,360
the second
5854
03:19:47,391 --> 03:19:48,320
item in the array.
5855
03:19:48,620 --> 03:19:51,859
it's basically taking each line and putting it inside of an array.
5856
03:19:52,159 --> 03:19:54,379
so if I want to access a specific line
5857
03:19:54,409 --> 03:19:58,340
I can just refer to it by its index in the array so if I said one.
5858
03:19:58,609 --> 03:20:00,319
now this is going to give us that
5859
03:20:00,379 --> 03:20:02,089
do white salesmen line
5860
03:20:02,329 --> 03:20:05,508
because that is at index position one inside of the array.
5861
03:20:06,107 --> 03:20:08,957
you can also use this reliance function
5862
03:20:08,987 --> 03:20:09,917
with a for loop
5863
03:20:09,947 --> 03:20:12,017
so I could come up here and create a for loop
5864
03:20:12,316 --> 03:20:13,696
is going to save four
5865
03:20:14,116 --> 03:20:15,016
and we'll say
5866
03:20:15,676 --> 03:20:16,546
employee
5867
03:20:16,576 --> 03:20:17,176
and
5868
03:20:17,565 --> 03:20:18,886
employee file
5869
03:20:19,756 --> 03:20:22,756
and then for each employee we just want to print them out so
5870
03:20:22,876 --> 03:20:23,566
it actually started
5871
03:20:23,597 --> 03:20:25,217
we have to put employee file dot
5872
03:20:25,247 --> 03:20:25,907
read
5873
03:20:26,417 --> 03:20:27,587
lines up here
5874
03:20:27,947 --> 03:20:30,587
and so now there's a loop through all the employees
5875
03:20:30,617 --> 03:20:33,168
in this employee filed out read lines array.
5876
03:20:33,468 --> 03:20:34,607
so we can actually just
5877
03:20:34,638 --> 03:20:35,447
print out
5878
03:20:35,808 --> 03:20:37,427
the individual employee
5879
03:20:37,816 --> 03:20:39,796
and now this will print out all the employees
5880
03:20:39,826 --> 03:20:42,437
inside of that files is basically printing out
5881
03:20:42,767 --> 03:20:44,536
each line in the file.
5882
03:20:44,776 --> 03:20:46,008
and that can be pretty useful.
5883
03:20:46,218 --> 03:20:50,807
so you can use all of these different functions like read read line read lines
5884
03:20:51,377 --> 03:20:56,235
readable you know there's a bunch of these different things that we can do to get information from a file.
5885
03:20:56,295 --> 03:21:01,635
and so there's a lot of cases where you're going to want to be able to parse through information in a file and this is a
5886
03:21:01,665 --> 03:21:02,926
awesome way to do it so
5887
03:21:03,286 --> 03:21:07,156
just to recap in whenever you want to open a file and read from it you can just use this
5888
03:21:07,187 --> 03:21:08,027
open function
5889
03:21:08,058 --> 03:21:10,277
type in the name of the file and then the mode,
5890
03:21:10,428 --> 03:21:12,048
which in our case is going to be r.
5891
03:21:12,317 --> 03:21:15,676
then you can do all sorts of stuff with it and you always want to make sure that
5892
03:21:15,735 --> 03:21:19,155
you close it when you've done that's just good practice so
5893
03:21:19,516 --> 03:21:22,664
that's the basics of reading from files and hopefully you guys can
5894
03:21:22,694 --> 03:21:25,335
use this in some way shape or form in the future.
5895
03:21:29,354 --> 03:21:34,363
in this tutorial on to talk to you about writing and appending to files in
5896
03:21:34,543 --> 03:21:35,143
python.
5897
03:21:35,532 --> 03:21:38,980
so one of the cool things about python is it allows you to work with
5898
03:21:39,011 --> 03:21:42,520
external files so I could have like an external text file and
5899
03:21:42,850 --> 03:21:44,830
I could actually like completely
5900
03:21:44,950 --> 03:21:47,531
read all the information in it I could pass through it
5901
03:21:47,562 --> 03:21:49,602
use that information to do certain things,
5902
03:21:50,142 --> 03:21:59,530
but it isn't a reading a file I can also write a file and that's what I want to talk to you guys about today's writing new files and appending onto existing files
5903
03:21:59,620 --> 03:22:01,989
over here I basically just have some code written out
5904
03:22:02,020 --> 03:22:03,280
and this essentially just
5905
03:22:03,490 --> 03:22:08,050
reads information from this employee's dot text file so you can see over here,
5906
03:22:08,439 --> 03:22:10,450
I am specifying the mode which is
5907
03:22:10,510 --> 03:22:12,221
r and that stands for read
5908
03:22:12,521 --> 03:22:14,170
and then down here under his reading
5909
03:22:14,200 --> 03:22:17,109
all of the contents of the file and spitting it out on the screen.
5910
03:22:17,649 --> 03:22:19,448
so I'm gonna click the play button over here,
5911
03:22:19,538 --> 03:22:20,138
and
5912
03:22:20,317 --> 03:22:21,188
you'll see that
5913
03:22:21,248 --> 03:22:23,348
if this executes so it's printing out
5914
03:22:23,708 --> 03:22:24,729
all of the
5915
03:22:24,818 --> 03:22:29,529
lines of code in our text file so over here I'm in this employee's dot text file
5916
03:22:29,859 --> 03:22:31,838
and it just has all this information like
5917
03:22:31,868 --> 03:22:33,309
employees in an office.
5918
03:22:33,698 --> 03:22:36,908
but let's say that I wanted to add another employee onto here
5919
03:22:37,059 --> 03:22:37,448
right ?
5920
03:22:37,568 --> 03:22:38,318
let's say that
5921
03:22:38,408 --> 03:22:39,038
a new
5922
03:22:39,068 --> 03:22:42,487
employee joined our company is that we wanted to add them onto this list.
5923
03:22:42,817 --> 03:22:43,178
well
5924
03:22:43,237 --> 03:22:45,847
I can come over here to my app dot python file
5925
03:22:46,236 --> 03:22:46,746
and
5926
03:22:46,836 --> 03:22:47,496
instead of
5927
03:22:47,556 --> 03:22:48,906
reading from the file
5928
03:22:48,937 --> 03:22:49,626
I want to
5929
03:22:49,656 --> 03:22:51,726
append it to the files I want to say
5930
03:22:51,756 --> 03:22:52,176
a
5931
03:22:52,656 --> 03:22:54,546
and appending to the file basically
5932
03:22:54,576 --> 03:22:56,226
basically means that you're adding
5933
03:22:56,346 --> 03:22:57,155
some text
5934
03:22:57,215 --> 03:22:58,686
at the end of the file so
5935
03:22:58,985 --> 03:23:01,537
wherever the file ends you're just going to add some text
5936
03:23:01,567 --> 03:23:02,317
onto there.
5937
03:23:02,888 --> 03:23:06,728
so what we can do is we can actually add another employee into the file.
5938
03:23:07,147 --> 03:23:07,718
so
5939
03:23:07,808 --> 03:23:08,887
instead of printing something
5940
03:23:08,917 --> 03:23:10,657
out I'm actually just going to say.
5941
03:23:12,157 --> 03:23:12,967
employee
5942
03:23:12,997 --> 03:23:13,717
file
5943
03:23:13,776 --> 03:23:14,526
dot
5944
03:23:14,706 --> 03:23:15,246
right.
5945
03:23:15,786 --> 03:23:19,837
and when I say employee filed out right I'm going to be able to write something to
5946
03:23:19,867 --> 03:23:21,427
the end of the file so
5947
03:23:21,907 --> 03:23:25,987
I can basically does right whatever I want so why don't we add in another employee
5948
03:23:26,228 --> 03:23:30,816
into our employees dot text file so we can add in another employee why don't we say like
5949
03:23:31,116 --> 03:23:31,986
toby.
5950
03:23:32,286 --> 03:23:33,938
and he's going to be in
5951
03:23:33,997 --> 03:23:34,807
human
5952
03:23:34,986 --> 03:23:36,097
resources.
5953
03:23:36,847 --> 03:23:37,417
so now
5954
03:23:37,717 --> 03:23:39,577
when I run this program.
5955
03:23:39,938 --> 03:23:40,809
it's going to add
5956
03:23:40,839 --> 03:23:44,648
toby human resources onto the end of the file somewhere on my program.
5957
03:23:45,368 --> 03:23:45,968
and
5958
03:23:46,298 --> 03:23:48,607
you'll see that nothing shows up down here in the council.
5959
03:23:48,877 --> 03:23:52,207
but if I go over to my employees dot text file.
5960
03:23:52,567 --> 03:23:53,438
all of a sudden
5961
03:23:53,468 --> 03:23:55,447
we have a new entry over here it's
5962
03:23:55,478 --> 03:23:56,197
toby
5963
03:23:56,228 --> 03:23:58,567
from human resource is right so I was able to
5964
03:23:58,957 --> 03:24:01,866
append a line onto the end of this file.
5965
03:24:02,736 --> 03:24:07,597
but here's the thing you need to be careful when you're writing to files because you can actually mess up a file
5966
03:24:07,627 --> 03:24:08,497
very easily
5967
03:24:08,797 --> 03:24:09,487
for example
5968
03:24:09,518 --> 03:24:12,277
I already added toby here into my file.
5969
03:24:12,487 --> 03:24:14,618
but if I was to run this program again,
5970
03:24:15,849 --> 03:24:18,519
you'll see that over here in this employee's dot text file
5971
03:24:18,759 --> 03:24:19,449
it when I hadn't
5972
03:24:19,479 --> 03:24:20,919
added toby again
5973
03:24:21,249 --> 03:24:23,710
right so it added this employee here
5974
03:24:23,740 --> 03:24:24,311
again
5975
03:24:24,490 --> 03:24:26,440
and also you'll notice that in this case,
5976
03:24:26,740 --> 03:24:29,501
these employee didn't go onto the next line
5977
03:24:29,621 --> 03:24:33,221
I accidentally ran my file again and all the sudden it messed up
5978
03:24:33,251 --> 03:24:34,900
this file over here
5979
03:24:35,051 --> 03:24:39,490
and so appending you really need to be careful because if you actually go under file again or have you
5980
03:24:39,550 --> 03:24:39,939
you know,
5981
03:24:40,569 --> 03:24:46,420
append something on something wrong to the file it's permanently it's getting saved inside of the file.
5982
03:24:47,020 --> 03:24:49,449
so I want to talk to you guys are a little bit more about you know
5983
03:24:49,479 --> 03:24:52,629
appending another thing we can do let's say we wanted to add another
5984
03:24:53,409 --> 03:24:54,100
employee
5985
03:24:54,279 --> 03:24:56,950
and you'll notice over here in this employees that text file
5986
03:24:57,670 --> 03:24:59,230
when I appended it on again
5987
03:24:59,261 --> 03:25:00,161
it got appended
5988
03:25:00,191 --> 03:25:00,882
to
5989
03:25:00,941 --> 03:25:03,041
the end of the existing line right
5990
03:25:03,281 --> 03:25:04,512
so the first time I had
5991
03:25:04,542 --> 03:25:08,202
a new line there but if you don't have a new line at the end of your file
5992
03:25:08,502 --> 03:25:10,302
and you all and you want to add a new line,
5993
03:25:10,632 --> 03:25:12,701
you're going to have to add some special characters
5994
03:25:12,731 --> 03:25:14,621
so let's add another employee
5995
03:25:14,921 --> 03:25:15,851
and we'll call her
5996
03:25:15,881 --> 03:25:16,541
kelly,
5997
03:25:16,631 --> 03:25:18,521
and let's just say kelley is in
5998
03:25:22,271 --> 03:25:23,621
customer service so
5999
03:25:23,891 --> 03:25:25,569
kelly is going to be in customer service.
6000
03:25:25,779 --> 03:25:27,130
and if I want to add
6001
03:25:27,189 --> 03:25:33,850
this employee onto the end of the file in a new line I'm going to have to put a new line character in front of it so I can say
6002
03:25:34,149 --> 03:25:34,899
backslash
6003
03:25:34,959 --> 03:25:35,439
n
6004
03:25:35,770 --> 03:25:37,149
and this will upend
6005
03:25:37,180 --> 03:25:38,170
this entry
6006
03:25:38,200 --> 03:25:39,160
into the file
6007
03:25:39,311 --> 03:25:42,250
with a new line so on a new line so now when I run this,
6008
03:25:42,550 --> 03:25:44,800
you'll see we get kelly from customer service
6009
03:25:44,830 --> 03:25:46,150
on her own line.
6010
03:25:46,480 --> 03:25:51,371
so you want to make sure that you're aware of like these special characters that you can use they call them
6011
03:25:51,401 --> 03:25:52,602
escape characters
6012
03:25:53,082 --> 03:25:58,841
and you're in time you're audi onto a file you want to make sure that you're adding on exactly where you want to add on.
6013
03:25:58,900 --> 03:26:01,390
so in addition to appending to a file.
6014
03:26:01,720 --> 03:26:02,979
I can also just like
6015
03:26:03,039 --> 03:26:04,899
overwrite a file or I can
6016
03:26:04,930 --> 03:26:05,500
write
6017
03:26:05,530 --> 03:26:07,090
an entirely new file.
6018
03:26:07,240 --> 03:26:10,332
this is as we already have this open instead of appending to the file.
6019
03:26:10,662 --> 03:26:12,042
why don't we just write
6020
03:26:12,162 --> 03:26:13,602
a file so I'm going to use this
6021
03:26:13,632 --> 03:26:14,352
w.
6022
03:26:15,191 --> 03:26:15,882
and now
6023
03:26:16,151 --> 03:26:18,401
if I say employee filed out right
6024
03:26:18,642 --> 03:26:21,161
because I'm using w and I'm not using
6025
03:26:21,221 --> 03:26:21,730
a,
6026
03:26:21,940 --> 03:26:22,630
it's actually going to
6027
03:26:22,660 --> 03:26:23,530
override
6028
03:26:23,561 --> 03:26:27,281
the entire file and it's only gonna put this inside the file so
6029
03:26:27,581 --> 03:26:28,540
when I run this
6030
03:26:28,720 --> 03:26:30,971
and we go over to this employee's dot text file
6031
03:26:31,360 --> 03:26:35,199
you'll see we only have one line inside of this file now it's just
6032
03:26:35,229 --> 03:26:36,670
kelley customer service.
6033
03:26:37,060 --> 03:26:39,009
that's because I was using double you
6034
03:26:39,039 --> 03:26:39,549
not
6035
03:26:39,608 --> 03:26:41,497
a when you use w it's just
6036
03:26:41,527 --> 03:26:44,377
overwriting everything that's in that existing file.
6037
03:26:45,127 --> 03:26:47,827
you can also use w to create a new file
6038
03:26:47,857 --> 03:26:51,398
so over here I could say employee file as he could to employees
6039
03:26:51,458 --> 03:26:52,058
one
6040
03:26:52,088 --> 03:26:52,958
dot text.
6041
03:26:53,408 --> 03:26:59,468
and now what's going to happen is when I run this it's going to create another file for me song in a run this
6042
03:27:00,067 --> 03:27:00,548
and
6043
03:27:00,578 --> 03:27:02,830
you'll see over here in my file browser.
6044
03:27:02,980 --> 03:27:05,829
we have this new file employees one dot text
6045
03:27:06,069 --> 03:27:07,389
so if I open this up.
6046
03:27:07,539 --> 03:27:10,389
it has exactly the same stuff as in this employees file,
6047
03:27:10,869 --> 03:27:15,905
but it basically created a new file for us and so a lot of times you're going to want to create a new file,
6048
03:27:16,535 --> 03:27:20,795
and you can use different extensions to so if I wanted to create like a web page
6049
03:27:20,825 --> 03:27:21,694
I could say
6050
03:27:23,164 --> 03:27:23,884
index start
6051
03:27:23,914 --> 03:27:24,724
each tier mel
6052
03:27:25,084 --> 03:27:26,854
and I could also add in some
6053
03:27:26,885 --> 03:27:28,385
each team malcolm here so
6054
03:27:28,475 --> 03:27:30,873
if you don't understand html don't worry about it but
6055
03:27:31,143 --> 03:27:32,312
if you do I can put like
6056
03:27:32,401 --> 03:27:33,751
a paragraph in year
6057
03:27:34,561 --> 03:27:35,910
another paragraph like
6058
03:27:36,630 --> 03:27:37,290
this is
6059
03:27:37,320 --> 03:27:38,070
html
6060
03:27:38,221 --> 03:27:40,262
basically ht mouth like a webpage.
6061
03:27:40,952 --> 03:27:41,222
and
6062
03:27:41,252 --> 03:27:43,922
the point I'm trying to make is that you can write out a webpage
6063
03:27:43,952 --> 03:27:46,352
inside of python by doing something like this so
6064
03:27:46,592 --> 03:27:47,941
now when I have played this
6065
03:27:47,972 --> 03:27:48,601
we get this
6066
03:27:48,631 --> 03:27:49,291
index style
6067
03:27:49,321 --> 03:27:50,491
html file.
6068
03:27:50,941 --> 03:27:51,992
and it has some
6069
03:27:52,022 --> 03:27:53,672
html inside of it so
6070
03:27:54,032 --> 03:27:57,123
that's one way that writing to files can be really useful you can
6071
03:27:57,153 --> 03:27:57,903
overwrite
6072
03:27:57,934 --> 03:27:59,104
an existing file,
6073
03:27:59,164 --> 03:28:01,294
you can write a new file and create it,
6074
03:28:01,384 --> 03:28:01,954
or
6075
03:28:02,104 --> 03:28:04,414
you can append onto the end of a file and
6076
03:28:04,924 --> 03:28:05,254
there's
6077
03:28:05,313 --> 03:28:09,363
tons of applications for writing to files and pythons and great language for
6078
03:28:09,633 --> 03:28:11,344
working with reading writing
6079
03:28:11,374 --> 03:28:13,024
doing all itself with files
6080
03:28:16,925 --> 03:28:21,274
in this tutorial on its altea guys about using modules in python.
6081
03:28:21,604 --> 03:28:25,324
now a module is essentially just a python file that we can
6082
03:28:25,414 --> 03:28:26,884
import into our
6083
03:28:26,914 --> 03:28:28,384
current python file so
6084
03:28:28,684 --> 03:28:36,002
for example if I wrote a python file that had a bunch of like useful functions are useful variables are you know other things like that.
6085
03:28:36,452 --> 03:28:38,312
I could take that file I could
6086
03:28:38,372 --> 03:28:40,951
import it into the file I'm currently working on
6087
03:28:41,161 --> 03:28:42,451
and I could actually access
6088
03:28:42,481 --> 03:28:43,650
all of those functions
6089
03:28:43,681 --> 03:28:44,881
all those variables.
6090
03:28:44,940 --> 03:28:46,201
all the stuff from that
6091
03:28:46,231 --> 03:28:47,401
external file
6092
03:28:47,821 --> 03:28:49,650
inside the file that I'm currently
6093
03:28:49,681 --> 03:28:50,610
working on so
6094
03:28:50,971 --> 03:28:53,700
I'm sure you guys how we can use module and then we'll talk about like
6095
03:28:53,970 --> 03:28:58,531
you know where you can find awesome modules and and really why modules make python and
6096
03:28:58,562 --> 03:28:59,161
awesome
6097
03:28:59,221 --> 03:28:59,881
language,
6098
03:29:00,271 --> 03:29:04,562
so over here in my text editor actually created this file and it's called
6099
03:29:04,593 --> 03:29:05,943
useful tools
6100
03:29:06,273 --> 03:29:07,264
dot python
6101
03:29:07,653 --> 03:29:10,684
and basically this file just has a bunch of
6102
03:29:10,773 --> 03:29:14,344
sort of like useful tools that I might want to use in one of my progress,
6103
03:29:14,824 --> 03:29:20,074
she'll see over here I have some variables this one is telling me how many feet are in a mile.
6104
03:29:20,374 --> 03:29:23,193
this one's telling me how many meters or a kilometer.
6105
03:29:23,313 --> 03:29:26,044
and then we have this list here which lists out all of the
6106
03:29:26,074 --> 03:29:27,333
members of the beatles,
6107
03:29:27,693 --> 03:29:32,702
am I also have a couple different functions down here so I have this get file extension function.
6108
03:29:33,122 --> 03:29:33,722
and this
6109
03:29:34,082 --> 03:29:35,012
basically just was
6110
03:29:35,042 --> 03:29:37,562
you know you give it a file name it'll tell you what the extension is,
6111
03:29:37,862 --> 03:29:39,961
and then we have this other function down here which
6112
03:29:40,021 --> 03:29:41,460
simulates rolling the dice
6113
03:29:41,490 --> 03:29:42,780
so you pass it a number
6114
03:29:43,021 --> 03:29:45,811
bypass it like a six it would roll a six sided dice
6115
03:29:46,051 --> 03:29:46,500
a passive
6116
03:29:46,530 --> 03:29:48,300
nine at roland nine sided dice etc
6117
03:29:48,330 --> 03:29:48,690
so
6118
03:29:48,780 --> 03:29:50,851
this is like a pipe on file that I wrote.
6119
03:29:51,181 --> 03:29:52,710
and it has some useful stuff in it,
6120
03:29:52,950 --> 03:29:56,667
and honestly there's a lot of stuff in here that I might want to use in the
6121
03:29:56,697 --> 03:29:59,066
other python files that I work with,
6122
03:29:59,366 --> 03:30:00,986
so let's say I'm over here at this
6123
03:30:01,046 --> 03:30:01,466
app
6124
03:30:01,496 --> 03:30:01,886
dot
6125
03:30:01,916 --> 03:30:03,836
python file and I'm thinking to myself,
6126
03:30:04,105 --> 03:30:04,676
ha,
6127
03:30:05,126 --> 03:30:07,497
I think I could use one of those functions
6128
03:30:07,527 --> 03:30:10,017
that was inside of that useful tools file
6129
03:30:10,047 --> 03:30:10,736
actually yeah
6130
03:30:10,767 --> 03:30:11,606
I need to
6131
03:30:11,637 --> 03:30:13,826
simulate rolling the dice in my program
6132
03:30:14,517 --> 03:30:16,437
well instead of having to go over here
6133
03:30:16,467 --> 03:30:17,696
copy this
6134
03:30:17,727 --> 03:30:18,626
function and then
6135
03:30:18,656 --> 03:30:20,396
paste it over here in my program
6136
03:30:20,757 --> 03:30:21,838
I can actually just
6137
03:30:21,958 --> 03:30:22,798
import
6138
03:30:22,828 --> 03:30:23,278
this
6139
03:30:23,309 --> 03:30:24,630
useful tools file
6140
03:30:24,870 --> 03:30:28,468
and I'll be able to import all of these functions and all of these
6141
03:30:28,498 --> 03:30:29,908
variables and attributes.
6142
03:30:30,298 --> 03:30:32,547
so the way I can do that is by coming up here
6143
03:30:32,606 --> 03:30:34,646
and I'm just going to go right at the top of my
6144
03:30:34,677 --> 03:30:36,146
file and I'm just going to say.
6145
03:30:36,507 --> 03:30:37,197
import.
6146
03:30:37,527 --> 03:30:41,424
and then I want to type in the name of the file that I want to import it so I was going to say,
6147
03:30:41,844 --> 03:30:43,313
useful underscore
6148
03:30:43,344 --> 03:30:44,094
tools
6149
03:30:44,454 --> 03:30:48,054
and pythons going to be smart enough to know that it should go off and
6150
03:30:48,084 --> 03:30:51,175
grab all the stuff from this useful tools dot
6151
03:30:51,205 --> 03:30:52,314
pi file
6152
03:30:52,765 --> 03:30:54,565
so once I've used that important statement
6153
03:30:54,596 --> 03:30:56,996
I can actually use all of the functions
6154
03:30:57,026 --> 03:30:58,885
inside of that useful tools file.
6155
03:30:59,365 --> 03:31:00,056
so
6156
03:31:00,086 --> 03:31:03,116
for example I could simulate rolling the dice I could say
6157
03:31:03,626 --> 03:31:04,826
useful tools.
6158
03:31:05,846 --> 03:31:06,596
dot,
6159
03:31:06,926 --> 03:31:09,297
and now I'm actually able to access
6160
03:31:09,327 --> 03:31:13,528
all of the attributes from inside that file so when I say useful tools dot
6161
03:31:13,828 --> 03:31:18,479
you'll see down here and my little suggestions menu it's telling me like beetles feet miles
6162
03:31:18,929 --> 03:31:21,839
get file extension meters and kilometers roll dice.
6163
03:31:21,959 --> 03:31:27,269
so it's giving me access to all of the stuff that was in that file so over here I could just say like
6164
03:31:28,108 --> 03:31:32,128
roll dice and we could pass this like a ten will roll a ten sided dice.
6165
03:31:32,578 --> 03:31:32,998
and
6166
03:31:33,028 --> 03:31:34,349
now this should actually
6167
03:31:34,379 --> 03:31:36,180
be able to run that function so
6168
03:31:36,239 --> 03:31:39,838
will simulate rolling a ten cited diet as you can see we got four
6169
03:31:40,438 --> 03:31:40,947
and
6170
03:31:41,277 --> 03:31:45,328
this is a really core concept in python which is
6171
03:31:45,718 --> 03:31:46,647
importing
6172
03:31:46,678 --> 03:31:48,027
functionality from
6173
03:31:48,058 --> 03:31:49,527
external python
6174
03:31:49,558 --> 03:31:50,757
files and this is like
6175
03:31:50,967 --> 03:31:54,806
huge in python and this is seriously going to change the way that you create your
6176
03:31:55,376 --> 03:31:56,396
python files
6177
03:31:56,936 --> 03:31:57,325
so
6178
03:31:57,535 --> 03:31:58,165
you'll notice like
6179
03:31:58,225 --> 03:31:59,545
I didn't have to
6180
03:31:59,575 --> 03:32:02,814
copy any functions or any variables or anything
6181
03:32:03,175 --> 03:32:06,085
over into this file and yet I was able to use
6182
03:32:06,115 --> 03:32:08,995
all this stuff that was inside this useful tools
6183
03:32:09,025 --> 03:32:09,596
file
6184
03:32:09,806 --> 03:32:11,936
so that is huge and honestly,
6185
03:32:12,056 --> 03:32:15,624
it's going to save you a lot of time because you can write something once and then you can
6186
03:32:15,684 --> 03:32:17,964
import it into your other files.
6187
03:32:18,264 --> 03:32:24,923
so that's really the basics of using modules mean modules are very simple module as any external python file
6188
03:32:25,163 --> 03:32:27,292
that you want to use some stuff inside of it.
6189
03:32:27,412 --> 03:32:28,402
I want to show you guys
6190
03:32:28,433 --> 03:32:29,062
a
6191
03:32:29,242 --> 03:32:32,361
place where you can go to find a huge list
6192
03:32:32,392 --> 03:32:33,651
of modules so
6193
03:32:34,012 --> 03:32:35,602
I'm going to go over here my web browser.
6194
03:32:35,661 --> 03:32:36,231
and
6195
03:32:36,592 --> 03:32:37,612
among this website
6196
03:32:37,643 --> 03:32:39,083
it's actually like the
6197
03:32:39,143 --> 03:32:40,643
official python docks
6198
03:32:41,183 --> 03:32:43,343
and basically all I did to get here was just typing
6199
03:32:43,373 --> 03:32:45,443
list of python modules and google,
6200
03:32:45,863 --> 03:32:49,792
and depending on the version of python you're using you're gonna want to make sure that you click the right one.
6201
03:32:50,002 --> 03:32:51,532
I flicked on the version three one
6202
03:32:51,683 --> 03:32:52,943
and over here on this page
6203
03:32:52,974 --> 03:32:55,282
you can see there's just a huge list
6204
03:32:55,312 --> 03:32:57,022
of python modules,
6205
03:32:57,322 --> 03:32:59,932
and these are basically modules inside of python
6206
03:32:59,962 --> 03:33:01,731
that you can just access so
6207
03:33:02,271 --> 03:33:03,291
essentially there's like
6208
03:33:03,321 --> 03:33:05,271
all of this awesome code that's
6209
03:33:05,331 --> 03:33:11,061
already been written for you and so if there's some sort of functionality that you want have inside of your python program,
6210
03:33:11,330 --> 03:33:12,200
chances are
6211
03:33:12,230 --> 03:33:13,791
there's a module in here
6212
03:33:14,121 --> 03:33:15,980
that has that functionalities of
6213
03:33:16,040 --> 03:33:17,060
all sorts of stuff
6214
03:33:17,090 --> 03:33:19,369
you can do I mean if you just look through this list like
6215
03:33:19,489 --> 03:33:21,710
you'll see a huge collection of
6216
03:33:21,979 --> 03:33:22,880
basically just
6217
03:33:23,240 --> 03:33:23,930
you know a bunch of
6218
03:33:23,960 --> 03:33:26,600
either python variables are python functions just
6219
03:33:26,659 --> 03:33:26,989
you know
6220
03:33:27,020 --> 03:33:29,749
things that you can use to make your programs better.
6221
03:33:30,139 --> 03:33:30,499
so
6222
03:33:30,529 --> 03:33:31,850
here's what I would recommend like
6223
03:33:32,060 --> 03:33:33,918
head over to this page and
6224
03:33:34,038 --> 03:33:37,817
to sort of look through a lot of these different module is no see what you can see
6225
03:33:38,178 --> 03:33:38,958
and honestly like
6226
03:33:38,988 --> 03:33:41,568
if you click on one of them it'll bring you to a page that
6227
03:33:41,658 --> 03:33:43,968
talks about like how to use they'll tell you like
6228
03:33:44,268 --> 03:33:45,767
how to import it and just you know
6229
03:33:45,797 --> 03:33:47,297
some basics about it
6230
03:33:48,106 --> 03:33:49,877
and this is sort of like the list
6231
03:33:49,907 --> 03:33:51,348
that on the official
6232
03:33:51,647 --> 03:33:52,488
python docs
6233
03:33:52,519 --> 03:33:52,908
but
6234
03:33:53,269 --> 03:33:54,019
he's using
6235
03:33:54,049 --> 03:33:58,909
the python community is huge there's tons of developers who use python.
6236
03:33:59,390 --> 03:34:03,980
and you can actually find a lot of third party modules so if you just go online and you know
6237
03:34:04,011 --> 03:34:07,071
look up like python module for doing actual
6238
03:34:07,102 --> 03:34:08,692
python module for doing why
6239
03:34:08,933 --> 03:34:14,212
chances are somebody out there has already written a python module to do what you're trying to do so.
6240
03:34:14,542 --> 03:34:18,562
if you get good at using modules and you get good at you know looking for them in finding them
6241
03:34:18,593 --> 03:34:21,083
you can actually save yourself a bunch of time because
6242
03:34:21,353 --> 03:34:24,682
chances are that somebody is already written a module to do
6243
03:34:24,712 --> 03:34:25,072
you know
6244
03:34:25,103 --> 03:34:26,332
what you're trying to do are like
6245
03:34:26,422 --> 03:34:27,801
part of what you're trying to do.
6246
03:34:28,041 --> 03:34:31,491
so now that we've taken a look at all these different python modules
6247
03:34:31,521 --> 03:34:36,771
I wanted to kind of dive in a little bit deeper into how we can actually use these things so
6248
03:34:37,610 --> 03:34:45,408
you'll notice here there's a lot of files right there's a lot of different modules that we apparently have access to in python but the question is
6249
03:34:45,678 --> 03:34:47,928
where all these files store
6250
03:34:47,958 --> 03:34:48,378
right
6251
03:34:48,647 --> 03:34:50,867
when I was over here in my program
6252
03:34:51,107 --> 03:34:53,566
for example I was using this useful tools
6253
03:34:53,776 --> 03:34:54,796
dot pie fire like
6254
03:34:54,826 --> 03:34:57,255
I knew where that was I created that file.
6255
03:34:57,465 --> 03:34:59,775
I was directly involved in making it
6256
03:34:59,835 --> 03:35:02,414
and I just imported over here it was pretty easy right ?
6257
03:35:02,804 --> 03:35:05,264
but what about all of these files
6258
03:35:05,323 --> 03:35:05,653
right
6259
03:35:05,713 --> 03:35:07,933
what about all these modules over healy
6260
03:35:07,963 --> 03:35:09,644
where all of these stored
6261
03:35:10,033 --> 03:35:11,202
and there's basically
6262
03:35:11,232 --> 03:35:16,812
two types of models here there's built in modules which means they're just built into the python language so
6263
03:35:17,052 --> 03:35:19,241
we can't just automatically have access to them.
6264
03:35:19,751 --> 03:35:20,290
and there's no
6265
03:35:20,350 --> 03:35:22,029
external modules
6266
03:35:22,329 --> 03:35:22,869
and
6267
03:35:23,139 --> 03:35:25,087
a lot of these external modules
6268
03:35:25,146 --> 03:35:26,587
are just stored in
6269
03:35:26,797 --> 03:35:27,907
basically the same
6270
03:35:27,938 --> 03:35:30,549
folder that we installed python on our computer so
6271
03:35:30,909 --> 03:35:34,148
for example let's look at a couple of these right we have on linking
6272
03:35:34,479 --> 03:35:35,889
base sixty four
6273
03:35:35,919 --> 03:35:37,119
bd be
6274
03:35:37,179 --> 03:35:38,469
been ascii like
6275
03:35:38,769 --> 03:35:40,087
if I come over here,
6276
03:35:40,537 --> 03:35:44,226
and you'll see I'm over here in milo file explorer I have my
6277
03:35:44,615 --> 03:35:46,386
python project which is draft.
6278
03:35:46,596 --> 03:35:48,996
there's also this other folder over here called
6279
03:35:49,026 --> 03:35:50,376
external libraries.
6280
03:35:50,706 --> 03:35:52,356
if I was to click down on this
6281
03:35:52,416 --> 03:35:53,616
and I come down here
6282
03:35:53,646 --> 03:35:54,636
you can see it's just
6283
03:35:54,695 --> 03:35:56,076
the version of python that I'm
6284
03:35:56,106 --> 03:35:56,767
amusing.
6285
03:35:57,727 --> 03:35:59,736
there's a folder here called lab
6286
03:35:59,796 --> 03:36:03,785
and this is a very important folder and this is basically storing all of those
6287
03:36:03,936 --> 03:36:06,755
external modules so you can see if I scroll down here
6288
03:36:07,085 --> 03:36:09,305
we have all of these different
6289
03:36:09,364 --> 03:36:10,624
like modules right
6290
03:36:10,864 --> 03:36:14,194
so here's that base sixty four hears bd be right.
6291
03:36:14,555 --> 03:36:17,224
a lot of these external modules are stored
6292
03:36:17,283 --> 03:36:19,203
inside of this lib folder and
6293
03:36:19,533 --> 03:36:23,823
like is that there's no external modules there's also a few modules that are just like a built in
6294
03:36:23,854 --> 03:36:24,573
modules
6295
03:36:24,693 --> 03:36:26,734
that are not can be stored inside of here
6296
03:36:26,975 --> 03:36:28,415
and you can actually tell so
6297
03:36:28,445 --> 03:36:30,457
for example if I was to come over here and click on
6298
03:36:30,487 --> 03:36:31,627
base sixty four.
6299
03:36:32,197 --> 03:36:34,628
it tells me where the source code
6300
03:36:34,658 --> 03:36:37,208
so the source codes in lab forward slash
6301
03:36:37,268 --> 03:36:38,317
base sixty four.
6302
03:36:38,647 --> 03:36:42,397
we are able to see that right how is I saw that inside of my lib folder
6303
03:36:43,058 --> 03:36:45,876
this been ascii though for example if I click on this,
6304
03:36:46,086 --> 03:36:47,256
you'll notice that this
6305
03:36:47,286 --> 03:36:47,886
isn't
6306
03:36:48,126 --> 03:36:53,165
giving me a folder cause this is basically just like built in to python so we don't have to worry about
6307
03:36:54,065 --> 03:36:54,546
you
6308
03:36:54,996 --> 03:36:56,556
lucky enough I'll just kind of like
6309
03:36:56,586 --> 03:36:57,516
it just how it works.
6310
03:36:57,756 --> 03:37:00,186
so some of these are external some of them are built in.
6311
03:37:00,275 --> 03:37:00,695
and
6312
03:37:00,905 --> 03:37:01,654
I want to show you guys
6313
03:37:01,864 --> 03:37:02,225
are
6314
03:37:02,314 --> 03:37:04,895
in addition to using these modules races.
6315
03:37:05,045 --> 03:37:07,325
there's a lot of good stuff here and honestly you could spend.
6316
03:37:07,535 --> 03:37:11,075
you know for years and years just learning about all these different modules.
6317
03:37:11,585 --> 03:37:14,163
but a lot of times you're going to want to use modules that
6318
03:37:14,223 --> 03:37:15,843
other people have written
6319
03:37:16,323 --> 03:37:16,684
and
6320
03:37:16,773 --> 03:37:17,044
you know
6321
03:37:17,074 --> 03:37:17,823
there's a lot of
6322
03:37:18,003 --> 03:37:18,933
developers
6323
03:37:19,383 --> 03:37:25,052
who work on python and who write different modules so there's a lot of useful modules either that aren't included
6324
03:37:25,321 --> 03:37:28,471
in this list right they're not going to be inside of this lib
6325
03:37:28,501 --> 03:37:29,221
folder
6326
03:37:29,431 --> 03:37:29,940
by
6327
03:37:29,971 --> 03:37:30,631
default.
6328
03:37:31,021 --> 03:37:33,331
and what we can actually do is
6329
03:37:33,361 --> 03:37:37,381
we can install those external module is as third party modules
6330
03:37:37,621 --> 03:37:38,971
that don't just come
6331
03:37:39,001 --> 03:37:40,531
preinstalled with python,
6332
03:37:40,892 --> 03:37:42,931
and I'm sure you guys haven't do that really quick so
6333
03:37:43,051 --> 03:37:45,781
the first thing you need to do obviously is find
6334
03:37:45,812 --> 03:37:49,022
a python module that you wanna installed you can download
6335
03:37:49,952 --> 03:37:51,782
and I have actually used one in the past.
6336
03:37:52,893 --> 03:37:54,453
python docs it's an
6337
03:37:54,604 --> 03:37:56,284
external module that you can use to
6338
03:37:56,524 --> 03:38:00,574
basically use python to create where documents which is pretty cool as you can like
6339
03:38:00,844 --> 03:38:04,174
format where documents inside of it so I'm just going to look that up here
6340
03:38:04,233 --> 03:38:05,254
in google.
6341
03:38:05,554 --> 03:38:07,114
I'm just gonna type in python
6342
03:38:07,145 --> 03:38:07,715
docks
6343
03:38:08,255 --> 03:38:08,555
and
6344
03:38:08,765 --> 03:38:10,535
here's a thing there's tons of these
6345
03:38:10,565 --> 03:38:13,026
extra modules you don't have to use python dogs.
6346
03:38:13,236 --> 03:38:14,856
I'm just giving you guys an example
6347
03:38:15,757 --> 03:38:17,196
but really it he just look up like
6348
03:38:17,256 --> 03:38:21,665
useful third party python modules there's going to be lists of hundreds of these things online
6349
03:38:22,325 --> 03:38:23,285
or in my case though
6350
03:38:23,315 --> 03:38:24,875
python docs has a website
6351
03:38:25,145 --> 03:38:26,705
and it basically just
6352
03:38:26,795 --> 03:38:29,585
has like some installation instructions are gonna come over here
6353
03:38:29,975 --> 03:38:34,236
and it tells me that I can install python docs using the command pip
6354
03:38:34,597 --> 03:38:36,157
install python docks.
6355
03:38:36,397 --> 03:38:37,928
so this brings us to
6356
03:38:38,138 --> 03:38:39,814
something I want to talk to you guys about which is a
6357
03:38:39,845 --> 03:38:40,354
pip
6358
03:38:40,744 --> 03:38:41,374
and pip
6359
03:38:41,404 --> 03:38:43,624
is essentially a program
6360
03:38:44,044 --> 03:38:49,384
and actually if you have a newer version of python three it comes preinstalled with python three
6361
03:38:49,804 --> 03:38:52,773
and you can use pipe to install python modules.
6362
03:38:53,043 --> 03:38:54,213
it's referred to as
6363
03:38:54,243 --> 03:38:54,903
a
6364
03:38:55,083 --> 03:38:56,133
package manager
6365
03:38:56,433 --> 03:38:59,313
and a package manager basically just allows you to like
6366
03:38:59,523 --> 03:39:01,023
install manage
6367
03:39:01,083 --> 03:39:04,083
update and uninstall like different python
6368
03:39:04,113 --> 03:39:04,804
modules
6369
03:39:05,044 --> 03:39:05,645
so pip
6370
03:39:05,675 --> 03:39:07,265
is extremely useful.
6371
03:39:07,625 --> 03:39:11,403
and in order for us to install python docs we're going to have to use pip
6372
03:39:11,823 --> 03:39:13,563
somno sure you guys are how we can do that,
6373
03:39:14,224 --> 03:39:15,904
but what I want to do is open up the
6374
03:39:15,935 --> 03:39:18,665
command prompt or the terminal on my computer.
6375
03:39:19,025 --> 03:39:21,217
if you're on a mac you wanna open up your terminal.
6376
03:39:21,547 --> 03:39:24,065
if you're on a windows computer you want to open up your command prompt
6377
03:39:24,096 --> 03:39:25,206
I'm using a windows
6378
03:39:25,236 --> 03:39:25,896
right now,
6379
03:39:26,195 --> 03:39:29,255
so I'm just going to come down to the search bar and type a and c m d
6380
03:39:29,615 --> 03:39:32,403
and this command prompts you to come up so I'm gonna click this
6381
03:39:32,823 --> 03:39:34,801
inside of the command prompt we can actually use
6382
03:39:34,831 --> 03:39:35,221
pip
6383
03:39:35,311 --> 03:39:38,160
firstly we want to do is check to make sure that pips install
6384
03:39:38,550 --> 03:39:42,839
and like I said if you have a newer version of python three pictured calm just
6385
03:39:42,869 --> 03:39:43,829
pretty installed
6386
03:39:44,369 --> 03:39:48,119
and it should do some work in here if you don't have a newer version of python three though,
6387
03:39:48,299 --> 03:39:50,129
you might have to install
6388
03:39:50,159 --> 03:39:50,520
pip
6389
03:39:50,550 --> 03:39:51,270
separately
6390
03:39:51,449 --> 03:39:54,239
and there's tons of instructions online and how to install pip.
6391
03:39:54,299 --> 03:39:56,340
so I'm just going to check to make sure that I have
6392
03:39:56,550 --> 03:39:57,119
to type in
6393
03:39:57,239 --> 03:39:57,779
pip
6394
03:39:57,959 --> 03:39:58,948
haven hyphen
6395
03:39:59,309 --> 03:40:00,059
version,
6396
03:40:00,358 --> 03:40:02,127
and they should spit out the version of pip
6397
03:40:02,157 --> 03:40:03,236
that I currently have.
6398
03:40:03,506 --> 03:40:04,466
so as long as we have to
6399
03:40:04,496 --> 03:40:04,856
pip
6400
03:40:04,887 --> 03:40:06,686
then we're ready to install an
6401
03:40:06,716 --> 03:40:08,546
external or third party
6402
03:40:08,846 --> 03:40:09,565
python
6403
03:40:09,596 --> 03:40:10,256
module.
6404
03:40:10,616 --> 03:40:12,087
all I have to do is just say pick
6405
03:40:12,177 --> 03:40:13,077
install
6406
03:40:13,377 --> 03:40:18,146
and now I just want to type in the name of the python module so in the case of python docks.
6407
03:40:18,807 --> 03:40:20,066
it was just
6408
03:40:20,336 --> 03:40:21,596
python dogs like that.
6409
03:40:21,865 --> 03:40:22,466
now again
6410
03:40:22,496 --> 03:40:23,875
you don't have to install python dogs
6411
03:40:23,905 --> 03:40:25,225
I'm just doing this for
6412
03:40:25,255 --> 03:40:27,234
this tutorial just going to show you guys
6413
03:40:27,444 --> 03:40:28,644
how this is going to work.
6414
03:40:28,884 --> 03:40:29,573
but you know
6415
03:40:29,604 --> 03:40:31,854
what you want to do is go online and look up some
6416
03:40:32,214 --> 03:40:34,583
third party external python modules,
6417
03:40:34,763 --> 03:40:35,902
and generally like
6418
03:40:35,933 --> 03:40:37,973
I'd say ninety to ninety five percent of the time
6419
03:40:38,003 --> 03:40:40,253
you're going to be able to just install them using pip.
6420
03:40:40,643 --> 03:40:43,253
in the off case that you can't install them using pip,
6421
03:40:43,493 --> 03:40:46,912
chances are they'll be like some detailed installation instructions but out say
6422
03:40:47,092 --> 03:40:48,352
for the most part any late
6423
03:40:48,411 --> 03:40:49,251
legitimate
6424
03:40:49,491 --> 03:40:50,182
python
6425
03:40:50,241 --> 03:40:53,001
module is going to be able to install using pip.
6426
03:40:53,691 --> 03:40:54,142
so
6427
03:40:54,172 --> 03:40:55,552
over here to understand a pip
6428
03:40:55,582 --> 03:40:57,651
install and add a module name so
6429
03:40:58,041 --> 03:40:59,781
python hyphen docks
6430
03:41:00,321 --> 03:41:04,400
and when I click enter this is going to go off and install python dogs for ourselves,
6431
03:41:04,521 --> 03:41:04,641
we
6432
03:41:04,671 --> 03:41:05,241
enter
6433
03:41:05,841 --> 03:41:09,651
and it's going to go off and install everything we need for python docs.
6434
03:41:10,521 --> 03:41:11,542
so you can see we have
6435
03:41:11,572 --> 03:41:13,822
successfully installed python docks
6436
03:41:14,152 --> 03:41:15,833
zero point eight point six,
6437
03:41:16,163 --> 03:41:16,493
so
6438
03:41:16,523 --> 03:41:17,304
I'm sure you guys
6439
03:41:17,334 --> 03:41:18,983
where exactly this god
6440
03:41:19,014 --> 03:41:19,943
placed so
6441
03:41:19,974 --> 03:41:21,714
normally when we install
6442
03:41:21,744 --> 03:41:22,164
a
6443
03:41:22,194 --> 03:41:23,034
external
6444
03:41:23,064 --> 03:41:24,055
third party module.
6445
03:41:24,354 --> 03:41:25,584
it's going to get put inside
6446
03:41:25,614 --> 03:41:26,694
this limb folder.
6447
03:41:26,874 --> 03:41:30,054
but it's gonna get put inside of a special folder in here called
6448
03:41:30,084 --> 03:41:31,374
site packages
6449
03:41:31,764 --> 03:41:35,064
so slight packages is a special folder and if I open this folder,
6450
03:41:35,395 --> 03:41:37,314
you'll see now we have this
6451
03:41:37,555 --> 03:41:39,715
docs folder and we also have this
6452
03:41:39,745 --> 03:41:42,234
python dark zero point eight point six
6453
03:41:42,685 --> 03:41:45,266
pi three points sakes thought eg info folder so
6454
03:41:45,476 --> 03:41:46,585
these two folders
6455
03:41:46,945 --> 03:41:47,966
are basically
6456
03:41:48,326 --> 03:41:50,726
included in that module installation so
6457
03:41:50,966 --> 03:41:54,596
you can see this docs folder has a bunch of different python files and
6458
03:41:54,896 --> 03:41:56,905
has a bunch of stuff in here that we can use.
6459
03:41:57,205 --> 03:42:00,233
so if I wanted to use this inside of one of my programs
6460
03:42:00,264 --> 03:42:03,534
I'm just going to refer to the name of the module so in our case,
6461
03:42:03,774 --> 03:42:05,395
it's just going to be docks.
6462
03:42:05,574 --> 03:42:07,344
so I used python docks
6463
03:42:07,554 --> 03:42:08,963
in order to install it but
6464
03:42:08,993 --> 03:42:11,753
we're going to use docs if we want to import it so
6465
03:42:11,993 --> 03:42:13,464
I could come up here and I could say
6466
03:42:13,494 --> 03:42:14,124
import
6467
03:42:14,184 --> 03:42:15,414
deal c x.
6468
03:42:15,984 --> 03:42:16,465
and
6469
03:42:16,495 --> 03:42:22,556
now I can actually use it so I can just say like docs dot whatever and you can see there's a bunch of different stuff down here.
6470
03:42:22,796 --> 03:42:23,846
there's like a document,
6471
03:42:23,996 --> 03:42:26,487
document part image part there's a bunch of stuff that we can
6472
03:42:26,518 --> 03:42:27,838
use with this and obviously
6473
03:42:28,048 --> 03:42:29,248
depending on the python
6474
03:42:29,278 --> 03:42:30,419
module you install
6475
03:42:30,449 --> 03:42:31,859
there can be different instructions.
6476
03:42:32,249 --> 03:42:32,969
but you can see it
6477
03:42:32,999 --> 03:42:34,500
got stored down here in this
6478
03:42:34,530 --> 03:42:35,880
site packages folder.
6479
03:42:36,120 --> 03:42:37,859
if I wanted to remove this
6480
03:42:37,890 --> 03:42:38,609
I could use
6481
03:42:38,640 --> 03:42:40,501
pick to do it so I could just say tip
6482
03:42:42,511 --> 03:42:44,371
and install and we could just
6483
03:42:45,901 --> 03:42:46,531
again saying
6484
03:42:46,562 --> 03:42:47,940
that a module names of
6485
03:42:47,971 --> 03:42:49,021
python dogs
6486
03:42:49,471 --> 03:42:50,520
and people now
6487
03:42:50,550 --> 03:42:51,810
and install this
6488
03:42:52,350 --> 03:42:53,250
on our computer.
6489
03:42:53,460 --> 03:42:54,449
so if I was to go back
6490
03:42:54,479 --> 03:42:55,919
over to this
6491
03:42:55,979 --> 03:42:56,608
folder,
6492
03:42:56,849 --> 03:42:58,288
you'll see that those two
6493
03:42:58,318 --> 03:42:59,969
that docs folder and then that
6494
03:42:59,999 --> 03:43:00,509
other
6495
03:43:00,809 --> 03:43:03,448
folder disappeared so they're no longer here,
6496
03:43:03,868 --> 03:43:06,808
and I'm actually not going to be able to use this anymore so
6497
03:43:07,107 --> 03:43:09,688
that's sort of the ins and outs of using
6498
03:43:09,718 --> 03:43:11,098
modules now again
6499
03:43:11,308 --> 03:43:12,839
there's tons of these modules and
6500
03:43:13,169 --> 03:43:15,119
I can be dozens and dozens of python
6501
03:43:15,149 --> 03:43:17,189
courses covering each one of these modules,
6502
03:43:17,520 --> 03:43:17,850
you know
6503
03:43:17,909 --> 03:43:19,500
the built in modules the
6504
03:43:19,980 --> 03:43:22,141
modules that are included by default and
6505
03:43:22,200 --> 03:43:23,161
external modules.
6506
03:43:23,312 --> 03:43:25,081
there's tons of these things out there
6507
03:43:25,411 --> 03:43:31,528
and really as a python programmer now what you can do is you can go out and play around with these different modules.
6508
03:43:31,679 --> 03:43:34,738
I showed you the ins and outs of installing them and you can use pip
6509
03:43:35,038 --> 03:43:37,077
to install all these different modules
6510
03:43:37,347 --> 03:43:41,847
and you know you can make sure that you have owned by checking the site packages folder or the lips folder
6511
03:43:42,297 --> 03:43:45,026
but really now it's on you to just come and go out and
6512
03:43:45,206 --> 03:43:49,975
use these modules and don't shy away from this because modules are a huge
6513
03:43:50,005 --> 03:43:50,935
part of python
6514
03:43:51,175 --> 03:43:54,594
you're definitely going to want to include them in your python stack.
6515
03:43:58,914 --> 03:44:03,354
in this tutorial on a talk to you guys about classes and objects in
6516
03:44:03,413 --> 03:44:04,163
python
6517
03:44:04,943 --> 03:44:06,474
classes and objects are
6518
03:44:06,533 --> 03:44:11,393
extremely useful in python programming and they can help you to make your programs
6519
03:44:11,423 --> 03:44:13,762
more organized and more powerful.
6520
03:44:14,302 --> 03:44:14,782
so
6521
03:44:14,842 --> 03:44:17,513
when we're in python we're dealing with all types of data
6522
03:44:17,603 --> 03:44:18,083
right
6523
03:44:18,383 --> 03:44:22,853
and a lot of times when we're writing programs we're going to have to work with different types of data
6524
03:44:23,272 --> 03:44:27,350
and there's essentially like a few basic types of data we can deal with usually things like
6525
03:44:27,380 --> 03:44:29,510
string cilic plain tax
6526
03:44:29,689 --> 03:44:33,171
numbers and boolean values those three are kind of like
6527
03:44:33,381 --> 03:44:36,651
the main types of data that you're going to be working with in
6528
03:44:37,132 --> 03:44:40,762
python and we have all sorts of structures we can use to store that data you know
6529
03:44:40,792 --> 03:44:42,651
things like lists or dictionaries.
6530
03:44:42,802 --> 03:44:43,642
but here's the problem
6531
03:44:43,672 --> 03:44:44,122
is that
6532
03:44:44,212 --> 03:44:44,722
not
6533
03:44:44,752 --> 03:44:45,592
all
6534
03:44:45,682 --> 03:44:48,892
information not all data not all things
6535
03:44:48,922 --> 03:44:49,762
can be
6536
03:44:49,792 --> 03:44:51,022
represented using
6537
03:44:51,053 --> 03:44:53,332
strings numbers or bullion's right,
6538
03:44:53,512 --> 03:44:53,961
there's a lot of
6539
03:44:53,991 --> 03:44:58,401
things in the real world that we can't represent in automating a string or an array,
6540
03:44:58,461 --> 03:44:59,781
or just a number right
6541
03:45:00,142 --> 03:45:02,392
in other words something like think of like something like a phone
6542
03:45:02,451 --> 03:45:03,561
or a computer
6543
03:45:03,860 --> 03:45:04,850
or a person
6544
03:45:04,880 --> 03:45:07,130
right you can't really represent those things
6545
03:45:07,580 --> 03:45:10,098
in like a string or a number you know it
6546
03:45:10,188 --> 03:45:11,026
in other words like
6547
03:45:11,086 --> 03:45:14,416
the data types that we have available to us in python
6548
03:45:14,446 --> 03:45:15,646
can't cover that.
6549
03:45:15,977 --> 03:45:21,015
and so what we can do with classes and objects is we can essentially create our own
6550
03:45:21,045 --> 03:45:22,155
data types.
6551
03:45:22,455 --> 03:45:25,483
so I can create my own data type for anything I want
6552
03:45:25,514 --> 03:45:26,444
python so
6553
03:45:26,595 --> 03:45:28,664
I could create like a phone data type
6554
03:45:28,694 --> 03:45:33,525
and it could represent a phone so I could store all the information I would ever want to know about my phone
6555
03:45:33,945 --> 03:45:35,925
inside of that data type in
6556
03:45:36,104 --> 03:45:39,074
and python we could create a class for it and
6557
03:45:39,284 --> 03:45:41,805
essentially what a classes is just saying hey
6558
03:45:41,835 --> 03:45:44,415
here's another data type that we want to use in python.
6559
03:45:44,896 --> 03:45:47,595
so with a class you can essentially define
6560
03:45:47,625 --> 03:45:48,405
your own
6561
03:45:48,436 --> 03:45:49,756
data type and its
6562
03:45:49,786 --> 03:45:52,966
super awesome and classes are extremely useful
6563
03:45:53,235 --> 03:45:57,227
causes are used in almost every single major programming language out there so
6564
03:45:57,347 --> 03:45:58,547
in this tutorial I just want to
6565
03:45:58,577 --> 03:46:00,377
give you guys a basic introduction of
6566
03:46:00,767 --> 03:46:03,646
classes and using them inside of python so
6567
03:46:03,706 --> 03:46:05,866
let's say that I'm writing a program,
6568
03:46:05,956 --> 03:46:07,396
and I want to
6569
03:46:07,456 --> 03:46:08,086
represent
6570
03:46:08,116 --> 03:46:09,017
a student
6571
03:46:09,047 --> 03:46:13,246
inside of this program so maybe I'm writing a program for like a college or a university.
6572
03:46:13,606 --> 03:46:14,867
let's say that in this program
6573
03:46:14,897 --> 03:46:16,247
I want to
6574
03:46:16,427 --> 03:46:17,958
model a student
6575
03:46:17,988 --> 03:46:21,438
like I want a model a real world objects and I wanted to be a student
6576
03:46:21,947 --> 03:46:23,777
right where we don't have a student data type
6577
03:46:23,987 --> 03:46:28,425
and I can't really represent a student in just a single string or a number.
6578
03:46:28,995 --> 03:46:32,056
so I can actually do is I can create a class
6579
03:46:32,086 --> 03:46:36,135
for a student and I'm basically creating like a student data type.
6580
03:46:36,615 --> 03:46:40,246
so I'm sure you guys how we can do that and create our student class
6581
03:46:40,276 --> 03:46:41,026
it's over here.
6582
03:46:41,326 --> 03:46:42,857
I'm just gonna make a new file.
6583
03:46:43,067 --> 03:46:47,269
wouldn't we get a new pipeline vase I'm just going to call it student dot pie
6584
03:46:48,499 --> 03:46:49,099
and
6585
03:46:49,219 --> 03:46:52,187
inside of this student dot pi file I want to create
6586
03:46:52,217 --> 03:46:54,106
a student class.
6587
03:46:54,406 --> 03:46:56,686
so the way that I can do that is just by typing
6588
03:46:56,716 --> 03:46:57,556
class.
6589
03:46:58,006 --> 03:46:59,146
and now I'm gonna type
6590
03:46:59,176 --> 03:47:00,557
the name of the class
6591
03:47:00,587 --> 03:47:01,756
that I want to create.
6592
03:47:01,996 --> 03:47:05,687
so in our case we are going to create a class called student so I'm just gonna say student.
6593
03:47:06,076 --> 03:47:06,945
and now we're going to make
6594
03:47:06,976 --> 03:47:07,876
a colon
6595
03:47:08,176 --> 03:47:10,695
now everything that goes inside of here
6596
03:47:10,785 --> 03:47:13,725
is going to be inside of our student class so
6597
03:47:13,875 --> 03:47:15,855
everything that's invented like this
6598
03:47:15,915 --> 03:47:17,596
will be considered a part of our
6599
03:47:17,626 --> 03:47:18,346
student
6600
03:47:18,376 --> 03:47:18,976
class
6601
03:47:19,396 --> 03:47:24,075
and basically what we can do inside of this student class is we can define a bunch of attributes
6602
03:47:24,105 --> 03:47:25,305
about a student.
6603
03:47:25,395 --> 03:47:27,944
so essentially what I'm doing is unlike modelling
6604
03:47:27,975 --> 03:47:30,796
a student I'm creating our student data type.
6605
03:47:31,065 --> 03:47:32,985
and I can use things like strings,
6606
03:47:33,195 --> 03:47:34,846
integers and bullion's
6607
03:47:35,025 --> 03:47:36,136
in order to
6608
03:47:36,195 --> 03:47:36,615
map
6609
03:47:36,646 --> 03:47:39,915
out what a student should be in what a student should have.
6610
03:47:40,335 --> 03:47:43,064
so I want to create something called an initialize
6611
03:47:43,095 --> 03:47:43,755
function.
6612
03:47:44,115 --> 03:47:45,854
and the way I do that as just by
6613
03:47:46,004 --> 03:47:47,414
typing out a d e f
6614
03:47:47,804 --> 03:47:48,643
and I was going to take
6615
03:47:48,673 --> 03:47:50,082
two underscores,
6616
03:47:50,502 --> 03:47:51,342
and then the word
6617
03:47:51,372 --> 03:47:52,752
I am I t
6618
03:47:52,992 --> 03:47:54,883
and then two more underscores,
6619
03:47:55,393 --> 03:47:55,812
and
6620
03:47:55,843 --> 03:47:57,072
you also want to type out
6621
03:47:57,103 --> 03:47:58,632
open close parentheses
6622
03:47:58,752 --> 03:48:01,271
and inside of those parentheses we want to type out
6623
03:48:01,301 --> 03:48:02,081
self,
6624
03:48:02,351 --> 03:48:04,061
and I'm on a colon after that.
6625
03:48:04,721 --> 03:48:07,630
what I can do inside of this initialize function
6626
03:48:07,899 --> 03:48:09,189
as I can basically map
6627
03:48:09,220 --> 03:48:09,609
out
6628
03:48:09,819 --> 03:48:11,949
what attributes a student should have
6629
03:48:11,979 --> 03:48:13,630
so we can essentially define like
6630
03:48:13,840 --> 03:48:14,320
hey,
6631
03:48:14,380 --> 03:48:16,149
here's the student data type
6632
03:48:16,209 --> 03:48:16,659
in
6633
03:48:16,779 --> 03:48:17,350
python
6634
03:48:17,380 --> 03:48:18,789
so what I want to do is add in
6635
03:48:18,819 --> 03:48:19,989
certain attributes
6636
03:48:20,020 --> 03:48:22,661
after this self so I'm just gonna say self
6637
03:48:22,691 --> 03:48:23,472
a comma.
6638
03:48:23,682 --> 03:48:25,541
and now we can start thinking about
6639
03:48:25,571 --> 03:48:26,052
you know
6640
03:48:26,111 --> 03:48:27,701
what values will
6641
03:48:27,761 --> 03:48:29,860
represent a student inside of our
6642
03:48:29,891 --> 03:48:31,211
python programs so
6643
03:48:31,541 --> 03:48:32,741
if I'm thinking lake
6644
03:48:32,831 --> 03:48:34,270
unthinking something like name
6645
03:48:34,329 --> 03:48:35,739
right so every student
6646
03:48:36,009 --> 03:48:37,659
in our programs should have a name.
6647
03:48:38,140 --> 03:48:40,119
they also might want to have a major
6648
03:48:40,149 --> 03:48:41,590
because they're in college,
6649
03:48:42,280 --> 03:48:45,041
they probably also will have a gps,
6650
03:48:45,251 --> 03:48:46,961
so their grade point average like
6651
03:48:46,991 --> 03:48:48,222
how they're doing in school
6652
03:48:48,731 --> 03:48:51,460
and lets to find one more thing that let me think,
6653
03:48:51,520 --> 03:48:52,270
why don't we make
6654
03:48:52,300 --> 03:48:53,561
a bullion
6655
03:48:53,980 --> 03:48:55,030
and it's going to be called
6656
03:48:55,090 --> 03:48:55,750
is
6657
03:48:55,840 --> 03:48:56,439
on
6658
03:48:57,130 --> 03:48:58,030
probation
6659
03:48:58,391 --> 03:49:01,449
and this will basically tell whether or not the student is on
6660
03:49:01,479 --> 03:49:02,319
probation.
6661
03:49:03,010 --> 03:49:03,580
so
6662
03:49:03,970 --> 03:49:06,100
essentially what I'm doing inside of this
6663
03:49:06,130 --> 03:49:07,839
initialize method inside of this
6664
03:49:07,869 --> 03:49:09,100
innate function is
6665
03:49:09,430 --> 03:49:11,319
I'm defining what a student
6666
03:49:11,350 --> 03:49:11,949
is
6667
03:49:11,979 --> 03:49:12,909
in our program.
6668
03:49:13,119 --> 03:49:14,439
and so in this program
6669
03:49:14,470 --> 03:49:15,189
a student
6670
03:49:15,249 --> 03:49:16,148
has a name,
6671
03:49:16,358 --> 03:49:17,408
it has a major
6672
03:49:17,588 --> 03:49:18,697
as a gps,
6673
03:49:18,817 --> 03:49:21,665
and it has a value that determines whether or not it's on probation.
6674
03:49:21,905 --> 03:49:24,425
this right here is the student data type.
6675
03:49:24,845 --> 03:49:27,876
so if I'm representing a student inside of my program now,
6676
03:49:28,146 --> 03:49:30,156
it has all of these attributes
6677
03:49:30,187 --> 03:49:31,446
associated to it.
6678
03:49:31,687 --> 03:49:33,517
and that's basically what I'm doing up here
6679
03:49:33,906 --> 03:49:34,387
now
6680
03:49:34,446 --> 03:49:36,276
inside of this initialize
6681
03:49:36,427 --> 03:49:38,707
function we actually have to do something and
6682
03:49:38,767 --> 03:49:40,627
basically what I want to do is
6683
03:49:41,257 --> 03:49:42,637
assign some values
6684
03:49:42,667 --> 03:49:45,637
so I'm going to be writing out some stuff and this might not make
6685
03:49:45,696 --> 03:49:46,717
total sense
6686
03:49:46,927 --> 03:49:47,767
right now.
6687
03:49:47,946 --> 03:49:51,365
but this is going to make sense in a second after we create our first
6688
03:49:51,425 --> 03:49:52,055
student
6689
03:49:52,145 --> 03:49:52,805
object.
6690
03:49:53,074 --> 03:49:53,494
so
6691
03:49:53,524 --> 03:49:56,314
just stick with me right now and just basically
6692
03:49:56,345 --> 03:50:00,155
know that we have to do what I'm doing over here so I'm just going to say self dot meme
6693
03:50:00,545 --> 03:50:01,505
is equal to name.
6694
03:50:02,075 --> 03:50:03,964
and then I'm going to say self dot major
6695
03:50:04,233 --> 03:50:05,253
because you get the major
6696
03:50:05,703 --> 03:50:07,173
self dot gps
6697
03:50:07,203 --> 03:50:07,504
is used
6698
03:50:07,534 --> 03:50:08,345
the gps.
6699
03:50:08,795 --> 03:50:10,234
and I'm going to say self dot
6700
03:50:10,265 --> 03:50:11,104
is
6701
03:50:11,704 --> 03:50:12,334
on
6702
03:50:13,894 --> 03:50:15,453
probation is equal to
6703
03:50:15,483 --> 03:50:16,654
is on probation.
6704
03:50:16,805 --> 03:50:17,645
so again
6705
03:50:17,675 --> 03:50:19,266
this might not make a whole lot of sense
6706
03:50:19,296 --> 03:50:20,196
right now
6707
03:50:20,227 --> 03:50:20,677
but
6708
03:50:20,736 --> 03:50:21,485
in a little bit
6709
03:50:21,516 --> 03:50:22,295
this is gonna make
6710
03:50:22,325 --> 03:50:23,195
total sense
6711
03:50:23,226 --> 03:50:23,796
so
6712
03:50:23,855 --> 03:50:26,405
now that I have this student class defined
6713
03:50:26,436 --> 03:50:28,145
I can actually use this class
6714
03:50:28,505 --> 03:50:31,055
inside of my other file so
6715
03:50:31,385 --> 03:50:33,093
I'm gonna come over here into this app
6716
03:50:33,123 --> 03:50:34,293
dot python file.
6717
03:50:34,503 --> 03:50:35,943
and this is just my main file.
6718
03:50:36,123 --> 03:50:37,712
so I actually want to create
6719
03:50:37,742 --> 03:50:39,271
a student right so
6720
03:50:39,571 --> 03:50:41,792
in that student class we defined
6721
03:50:41,912 --> 03:50:45,781
the student data type and we basically said like hey a student has a name,
6722
03:50:46,081 --> 03:50:47,521
a major a gps and
6723
03:50:47,730 --> 03:50:49,681
it says whether or not they're on probation
6724
03:50:49,891 --> 03:50:52,439
dots like the template for what a student
6725
03:50:52,470 --> 03:50:52,950
is,
6726
03:50:53,340 --> 03:50:53,939
but we can
6727
03:50:53,970 --> 03:50:55,439
actually create
6728
03:50:55,499 --> 03:50:56,759
a student so we can
6729
03:50:56,789 --> 03:50:59,789
create an actual student and give it some information.
6730
03:51:00,029 --> 03:51:00,989
and that's called an
6731
03:51:01,020 --> 03:51:01,739
object.
6732
03:51:02,039 --> 03:51:02,639
so
6733
03:51:02,789 --> 03:51:03,149
this
6734
03:51:03,180 --> 03:51:05,130
student class over here
6735
03:51:05,460 --> 03:51:07,710
is basically defining what a student
6736
03:51:07,740 --> 03:51:08,101
is
6737
03:51:08,131 --> 03:51:09,540
so a class is just like
6738
03:51:09,690 --> 03:51:11,971
an overview of what the student data type
6739
03:51:12,001 --> 03:51:12,511
is
6740
03:51:12,780 --> 03:51:13,800
an object
6741
03:51:14,040 --> 03:51:15,480
is an actual student
6742
03:51:15,570 --> 03:51:19,081
so it's an actual student with a name a major and a gps.
6743
03:51:19,471 --> 03:51:21,781
it's not just this template anymore it's
6744
03:51:21,812 --> 03:51:25,382
actually like a student that we're representing inside of our program so
6745
03:51:26,342 --> 03:51:30,331
in order to use that student class and create a student
6746
03:51:30,361 --> 03:51:33,062
object I actually need to import that so
6747
03:51:33,122 --> 03:51:35,012
all I have to do over here just say
6748
03:51:35,342 --> 03:51:36,092
from
6749
03:51:36,691 --> 03:51:37,531
student
6750
03:51:37,981 --> 03:51:39,512
and this is referring to this
6751
03:51:39,542 --> 03:51:40,771
student file.
6752
03:51:41,191 --> 03:51:41,942
I can say
6753
03:51:42,002 --> 03:51:42,752
import
6754
03:51:43,832 --> 03:51:44,522
student
6755
03:51:45,122 --> 03:51:48,273
and basically what this is saying is from the student
6756
03:51:48,304 --> 03:51:49,084
file.
6757
03:51:49,294 --> 03:51:51,725
I want to import the student class.
6758
03:51:51,845 --> 03:51:56,613
so even though these are both student they're referring to different things so this is referring to the file.
6759
03:51:56,974 --> 03:51:59,764
and this is referring to the actual student class.
6760
03:52:00,004 --> 03:52:02,732
so now that we did this we can create a student so
6761
03:52:02,912 --> 03:52:03,692
you can create an
6762
03:52:03,723 --> 03:52:05,072
object of a class
6763
03:52:05,103 --> 03:52:07,473
a lot like you would a normal variable so
6764
03:52:07,652 --> 03:52:08,822
I can just give it a name
6765
03:52:08,853 --> 03:52:09,873
I'm gonna call this
6766
03:52:10,053 --> 03:52:11,253
student one
6767
03:52:11,312 --> 03:52:12,963
and I'm going to set it equal to
6768
03:52:13,323 --> 03:52:14,163
student
6769
03:52:14,763 --> 03:52:17,013
and I'm gonna make an open and close parentheses
6770
03:52:17,223 --> 03:52:17,792
and now
6771
03:52:17,852 --> 03:52:19,771
inside of this parentheses.
6772
03:52:19,891 --> 03:52:21,270
I want to give this student
6773
03:52:21,359 --> 03:52:22,049
a name,
6774
03:52:22,739 --> 03:52:23,640
a major
6775
03:52:23,880 --> 03:52:24,870
a gps
6776
03:52:25,200 --> 03:52:25,771
and ann
6777
03:52:25,801 --> 03:52:27,211
is on probation
6778
03:52:27,541 --> 03:52:28,171
value.
6779
03:52:28,440 --> 03:52:31,407
so I'm going to say it will just create a fake student saw to say his name's
6780
03:52:31,438 --> 03:52:32,037
jim
6781
03:52:32,518 --> 03:52:33,897
and he's studying
6782
03:52:34,138 --> 03:52:35,098
business
6783
03:52:36,718 --> 03:52:37,468
and
6784
03:52:37,498 --> 03:52:40,167
we want to give them a gps and maybe has like a three point
6785
03:52:40,197 --> 03:52:40,797
one.
6786
03:52:41,547 --> 03:52:41,967
and
6787
03:52:41,997 --> 03:52:45,927
finally we want to say whether or not this student is on probation so why don't we say false.
6788
03:52:46,316 --> 03:52:48,087
so basically what I'm doing is I'm
6789
03:52:48,267 --> 03:52:50,126
saying that I want to create
6790
03:52:50,156 --> 03:52:51,086
a student.
6791
03:52:51,446 --> 03:52:53,726
so I want to actually create a student
6792
03:52:53,785 --> 03:52:55,076
object and rubber an
6793
03:52:55,106 --> 03:52:55,797
object
6794
03:52:55,827 --> 03:52:56,427
is just
6795
03:52:56,696 --> 03:52:56,966
an
6796
03:52:56,996 --> 03:52:57,716
instance
6797
03:52:57,746 --> 03:52:58,735
of a class.
6798
03:52:58,976 --> 03:53:02,845
so the class is like an overall template it defines what a student is
6799
03:53:03,114 --> 03:53:04,104
put an object
6800
03:53:04,164 --> 03:53:04,494
is an
6801
03:53:04,524 --> 03:53:05,784
actual student with
6802
03:53:05,844 --> 03:53:07,494
actual information so
6803
03:53:07,704 --> 03:53:09,804
we could call student one now
6804
03:53:09,834 --> 03:53:11,034
this is a student
6805
03:53:11,124 --> 03:53:11,904
objects.
6806
03:53:12,354 --> 03:53:13,884
so I just want to show you guys,
6807
03:53:13,943 --> 03:53:18,834
what this student object actually is and what we can do with it and then I'm going to talk some more about that
6808
03:53:18,864 --> 03:53:19,765
in it function
6809
03:53:19,795 --> 03:53:20,845
from before so
6810
03:53:21,475 --> 03:53:22,435
over here I'm just going to
6811
03:53:22,465 --> 03:53:23,664
make a print statement
6812
03:53:24,474 --> 03:53:26,393
inside of here I just want to print out
6813
03:53:26,782 --> 03:53:27,473
student
6814
03:53:27,862 --> 03:53:28,312
and
6815
03:53:28,433 --> 03:53:29,482
what's cool about
6816
03:53:29,542 --> 03:53:29,962
this
6817
03:53:29,992 --> 03:53:33,022
student one object is I can actually access
6818
03:53:33,082 --> 03:53:35,961
each of the attributes from inside of this object.
6819
03:53:36,261 --> 03:53:39,948
so if I wanted to get the name of the student I could say student one dot name
6820
03:53:40,368 --> 03:53:40,938
and now
6821
03:53:40,969 --> 03:53:42,078
this is actually going to print
6822
03:53:42,108 --> 03:53:43,519
out the student's name.
6823
03:53:43,969 --> 03:53:45,108
so over here,
6824
03:53:45,259 --> 03:53:46,578
you'll see it prints out
6825
03:53:46,608 --> 03:53:47,059
jim
6826
03:53:47,389 --> 03:53:49,277
if I wanted I could print out the students
6827
03:53:49,308 --> 03:53:50,147
gps
6828
03:53:50,537 --> 03:53:52,367
and it's going to print out the students
6829
03:53:52,457 --> 03:53:53,147
gps
6830
03:53:53,178 --> 03:53:54,048
three point one.
6831
03:53:54,498 --> 03:53:56,237
so now that I created this
6832
03:53:56,268 --> 03:53:56,928
student
6833
03:53:56,958 --> 03:53:57,648
objects.
6834
03:53:57,979 --> 03:54:01,129
I can actually access the information about the student
6835
03:54:01,159 --> 03:54:03,710
so essentially I'm just created a student
6836
03:54:03,740 --> 03:54:04,460
data type
6837
03:54:04,490 --> 03:54:10,218
so I could create as many of these students as I wanted if I wanted I could create another student we could call it student too.
6838
03:54:11,388 --> 03:54:12,078
and
6839
03:54:12,229 --> 03:54:15,560
essentially we do the same thing we just give it different information so
6840
03:54:15,590 --> 03:54:16,521
we could say lake
6841
03:54:16,971 --> 03:54:17,661
pam
6842
03:54:17,841 --> 03:54:19,161
and her major is
6843
03:54:19,251 --> 03:54:19,731
art
6844
03:54:20,151 --> 03:54:21,591
and she has like a
6845
03:54:21,831 --> 03:54:23,121
two point five.
6846
03:54:23,481 --> 03:54:25,792
and let's say that she is on probation.
6847
03:54:26,362 --> 03:54:29,931
so now I have another student student too so if I wanted
6848
03:54:30,081 --> 03:54:34,703
I could access information about that student we could say like student to dodgy p a
6849
03:54:35,063 --> 03:54:36,114
and now this has given me
6850
03:54:36,145 --> 03:54:37,375
the dpj of
6851
03:54:37,435 --> 03:54:38,425
student too.
6852
03:54:38,755 --> 03:54:42,177
so basically what I did was I created a student data type
6853
03:54:42,267 --> 03:54:44,336
and I created student objects
6854
03:54:44,396 --> 03:54:46,677
and now I'm able to represent a student
6855
03:54:46,707 --> 03:54:47,967
inside of my program.
6856
03:54:48,327 --> 03:54:48,777
so
6857
03:54:48,808 --> 03:54:52,828
let's talk real quick about all this stuff over here because I didn't really explain it
6858
03:54:53,248 --> 03:54:55,139
basically what's happening is
6859
03:54:55,889 --> 03:54:58,139
when I come over here and I say student
6860
03:54:58,408 --> 03:55:01,019
and I'm passing in all of these different values.
6861
03:55:01,828 --> 03:55:03,838
those are getting passed into this
6862
03:55:03,868 --> 03:55:04,857
init function.
6863
03:55:05,098 --> 03:55:06,988
so remember I passed in a name
6864
03:55:07,019 --> 03:55:09,448
I passed in a major at passing a gps.
6865
03:55:09,658 --> 03:55:11,458
when we create that student
6866
03:55:11,548 --> 03:55:12,987
we're actually calling
6867
03:55:13,018 --> 03:55:14,098
this function.
6868
03:55:14,458 --> 03:55:16,019
and when I pass in the name
6869
03:55:16,049 --> 03:55:17,519
the major and the gps
6870
03:55:17,729 --> 03:55:21,329
those values are actually getting stored over here in this name.
6871
03:55:21,539 --> 03:55:23,309
this major this gps
6872
03:55:23,339 --> 03:55:24,089
et cetera,
6873
03:55:24,539 --> 03:55:24,869
right
6874
03:55:24,989 --> 03:55:25,409
so I'm
6875
03:55:25,439 --> 03:55:26,459
giving this
6876
03:55:26,489 --> 03:55:27,839
student object.
6877
03:55:28,199 --> 03:55:29,699
all of that information.
6878
03:55:29,939 --> 03:55:31,170
and down here.
6879
03:55:31,410 --> 03:55:32,371
what I'm doing
6880
03:55:32,431 --> 03:55:32,851
is I'm
6881
03:55:32,881 --> 03:55:33,601
saying
6882
03:55:33,721 --> 03:55:35,040
self dot name
6883
03:55:35,070 --> 03:55:35,911
as he put the name
6884
03:55:35,941 --> 03:55:37,291
and basically what this means is
6885
03:55:37,531 --> 03:55:39,571
the actual objects name
6886
03:55:39,901 --> 03:55:42,602
is going to be equal to the name that they passed in
6887
03:55:42,661 --> 03:55:45,271
so self dot name as an attribute
6888
03:55:45,421 --> 03:55:46,321
of student,
6889
03:55:46,472 --> 03:55:51,271
raises the student is storing a name the student is storing a major the student is storing and gps,
6890
03:55:51,780 --> 03:55:53,221
but that's different from
6891
03:55:53,251 --> 03:55:54,121
this name
6892
03:55:54,151 --> 03:55:56,161
this major in this gps
6893
03:55:56,521 --> 03:55:59,581
remember and these are all just values that I passed in
6894
03:55:59,911 --> 03:56:01,081
there just parameters.
6895
03:56:01,441 --> 03:56:04,232
so I need to take the values that I passed in
6896
03:56:04,532 --> 03:56:09,450
and I need to assign them to the actual attributes of the object so I need to say
6897
03:56:09,720 --> 03:56:10,290
ok.
6898
03:56:10,410 --> 03:56:14,249
the name of the student is going to be equal to the name that we passed in
6899
03:56:14,759 --> 03:56:15,420
one more time.
6900
03:56:15,660 --> 03:56:17,311
the name of the student
6901
03:56:17,341 --> 03:56:18,181
objects
6902
03:56:18,271 --> 03:56:19,740
is going to be equal to the name
6903
03:56:19,771 --> 03:56:20,820
that we passed in
6904
03:56:21,061 --> 03:56:23,370
the name of the student's major,
6905
03:56:23,580 --> 03:56:24,810
is going to be equal to
6906
03:56:24,840 --> 03:56:26,311
the major that we passed in
6907
03:56:26,700 --> 03:56:28,471
the student's gps
6908
03:56:28,980 --> 03:56:31,710
is going to be equal to the gps that we passed in.
6909
03:56:31,860 --> 03:56:34,739
that's basically what's happening here so when I say self
6910
03:56:35,039 --> 03:56:37,619
is referring to the actual object so
6911
03:56:37,889 --> 03:56:39,658
over here what I'm creating this
6912
03:56:39,688 --> 03:56:40,769
student object.
6913
03:56:41,099 --> 03:56:43,288
I'm giving it all of this information.
6914
03:56:43,438 --> 03:56:46,799
it's taking that information and storing it as attributes
6915
03:56:46,829 --> 03:56:47,310
for
6916
03:56:47,340 --> 03:56:48,149
the object.
6917
03:56:48,600 --> 03:56:49,050
so
6918
03:56:49,140 --> 03:56:52,708
hopefully that makes sense I think that's about as clear as I can make it but
6919
03:56:52,888 --> 03:56:55,168
the point is that now we have a student
6920
03:56:55,198 --> 03:56:55,888
data type.
6921
03:56:56,157 --> 03:56:58,587
so now I can represent a student
6922
03:56:58,977 --> 03:57:00,087
inside of my
6923
03:57:00,117 --> 03:57:00,867
python
6924
03:57:00,897 --> 03:57:01,378
program
6925
03:57:01,408 --> 03:57:03,028
and that's like a super powerful.
6926
03:57:03,509 --> 03:57:06,539
and what's cool about classes and objects as you can do this with anything.
6927
03:57:06,959 --> 03:57:12,270
so in this example we created a student class and then we created student objects off of that.
6928
03:57:12,479 --> 03:57:13,409
but I can model
6929
03:57:13,439 --> 03:57:14,970
any real world entity
6930
03:57:15,000 --> 03:57:17,820
into this program I can model something like a phone
6931
03:57:18,210 --> 03:57:19,410
or I can model like
6932
03:57:19,440 --> 03:57:20,311
a water bottle
6933
03:57:20,341 --> 03:57:21,211
or I can model
6934
03:57:21,241 --> 03:57:21,631
you know
6935
03:57:22,171 --> 03:57:22,921
a keyboard
6936
03:57:22,951 --> 03:57:25,200
or I can model anything that I wanted.
6937
03:57:25,470 --> 03:57:26,820
inside of my program
6938
03:57:26,910 --> 03:57:29,011
I can just give it certain attributes right
6939
03:57:29,131 --> 03:57:32,821
so that's what's cool about classes we can model real world objects.
6940
03:57:32,881 --> 03:57:34,682
and we can create our own
6941
03:57:34,712 --> 03:57:35,853
data types
6942
03:57:40,053 --> 03:57:41,644
in this tutorial I'm gonna show you guys
6943
03:57:41,674 --> 03:57:45,124
how to build a multiple choice quiz in python.
6944
03:57:45,604 --> 03:57:46,774
so basically we're gonna
6945
03:57:46,805 --> 03:57:51,843
set up a little multiple choice quizzes and we'll have the user take the quiz and as they take the quiz
6946
03:57:52,112 --> 03:57:55,895
will keep track of their score and then at the end will tell them how they did so
6947
03:57:56,164 --> 03:58:02,373
this is going to be a pretty cool video I'm excited to show you guys how to do this and we'll get to use things like classes and
6948
03:58:02,403 --> 03:58:03,363
if statements
6949
03:58:03,453 --> 03:58:04,293
and loops
6950
03:58:04,562 --> 03:58:07,172
in order to build these programs are we're going to use a lot of cool
6951
03:58:07,202 --> 03:58:08,433
stuff in python.
6952
03:58:08,973 --> 03:58:10,322
the first thing I want to show you guys
6953
03:58:10,562 --> 03:58:12,901
actually did this before I started the video it's
6954
03:58:12,932 --> 03:58:15,571
this little a ray is called question prompts.
6955
03:58:15,871 --> 03:58:19,589
and I basically just wrote out all the questions that are going to be.
6956
03:58:19,709 --> 03:58:23,038
or I should say the questions I wrote out all the question prompts
6957
03:58:23,248 --> 03:58:26,967
that are going to be inside of my multiple choice quiz so the first one just says
6958
03:58:27,267 --> 03:58:29,758
what color are apples and the answers are
6959
03:58:29,817 --> 03:58:30,447
red,
6960
03:58:30,867 --> 03:58:32,188
purple or orange.
6961
03:58:32,518 --> 03:58:33,447
and the next one is
6962
03:58:33,478 --> 03:58:35,577
what color of banana is the options are
6963
03:58:35,607 --> 03:58:37,528
teal magenta and yellow,
6964
03:58:38,158 --> 03:58:41,218
and the third question is what color are strawberries and the
6965
03:58:41,458 --> 03:58:46,796
options are yellow red and blue so this is obviously a very very easy multiple choice quiz but
6966
03:58:47,096 --> 03:58:47,667
I just kind of
6967
03:58:47,727 --> 03:58:51,085
wrote out the questions beforehand so I didn't have to spend time doing that.
6968
03:58:51,445 --> 03:58:53,306
so let's talk about how we can build
6969
03:58:53,336 --> 03:58:53,756
a
6970
03:58:53,786 --> 03:58:55,076
multiple choice
6971
03:58:55,106 --> 03:58:55,736
test.
6972
03:58:56,066 --> 03:58:56,456
well.
6973
03:58:56,636 --> 03:59:00,325
the first thing I want to think about is how can I represent the questions in the test
6974
03:59:00,595 --> 03:59:01,045
right
6975
03:59:01,135 --> 03:59:03,385
over here we have the question prompts.
6976
03:59:03,595 --> 03:59:06,896
but there's actually two parts to a question when you think about it,
6977
03:59:07,136 --> 03:59:09,057
there's the prompts in other words like
6978
03:59:09,116 --> 03:59:09,597
the
6979
03:59:09,687 --> 03:59:11,157
actual question itself.
6980
03:59:11,607 --> 03:59:16,258
and then there's the answer to the question in both of those attributes needs to be
6981
03:59:16,317 --> 03:59:16,977
kept track of
6982
03:59:17,007 --> 03:59:17,247
right
6983
03:59:17,277 --> 03:59:21,414
I need to keep track of what we want to ask and I need a cap to keep track of what the answer is.
6984
03:59:21,774 --> 03:59:23,664
so what I'm actually going to do is create
6985
03:59:23,694 --> 03:59:24,055
a
6986
03:59:24,085 --> 03:59:25,436
question class
6987
03:59:25,466 --> 03:59:28,556
so I'm gonna create a little data type for questions
6988
03:59:28,976 --> 03:59:31,706
and inside of that question class will be able to store
6989
03:59:31,736 --> 03:59:33,057
the question prompts,
6990
03:59:33,297 --> 03:59:35,757
and will also be able to store the question's
6991
03:59:35,787 --> 03:59:36,387
answer,
6992
03:59:36,776 --> 03:59:40,706
so I'm just gonna come over here to my folder and I'm going to make a new
6993
03:59:40,886 --> 03:59:42,056
python file
6994
03:59:42,086 --> 03:59:43,676
and we're just going to call this
6995
03:59:43,706 --> 03:59:44,486
question
6996
03:59:44,517 --> 03:59:45,057
dot
6997
03:59:45,087 --> 03:59:47,066
p y so we'll call a question up high
6998
03:59:48,086 --> 03:59:53,064
and inside of this question dot pi file I'm going to make a class so I'm just gonna say class
6999
03:59:53,095 --> 03:59:53,904
question.
7000
03:59:54,234 --> 03:59:55,073
and I'm going to put a
7001
03:59:55,104 --> 03:59:55,974
colon here.
7002
03:59:56,363 --> 03:59:57,653
so inside of this
7003
03:59:57,684 --> 04:00:00,323
question class we want to define it and initialize
7004
04:00:00,623 --> 04:00:01,403
function so
7005
04:00:01,764 --> 04:00:02,694
I must say deaf
7006
04:00:03,024 --> 04:00:04,014
to underscores
7007
04:00:04,044 --> 04:00:04,584
in it
7008
04:00:04,644 --> 04:00:05,783
too underscores,
7009
04:00:06,173 --> 04:00:06,803
and
7010
04:00:06,923 --> 04:00:08,151
then we're going to type out an
7011
04:00:08,182 --> 04:00:09,472
opening close parentheses
7012
04:00:09,502 --> 04:00:10,222
self
7013
04:00:10,252 --> 04:00:11,241
and that a colon.
7014
04:00:11,781 --> 04:00:15,471
so after this self we wanted to find the different attributes
7015
04:00:15,501 --> 04:00:17,571
that will describe or that will
7016
04:00:17,602 --> 04:00:19,461
be included in a question so
7017
04:00:20,091 --> 04:00:21,532
we're going to include a
7018
04:00:21,562 --> 04:00:22,282
prompt
7019
04:00:22,312 --> 04:00:26,273
everyone to include an answer so every question we'll have a question prompt
7020
04:00:26,604 --> 04:00:28,013
and a question answer
7021
04:00:28,253 --> 04:00:31,881
now down here I'm going to take those values and assign them
7022
04:00:31,911 --> 04:00:32,481
to
7023
04:00:32,512 --> 04:00:33,321
the actual
7024
04:00:33,352 --> 04:00:35,782
class objects only to say self
7025
04:00:35,812 --> 04:00:36,322
dot
7026
04:00:36,473 --> 04:00:37,072
prompt
7027
04:00:37,492 --> 04:00:38,632
is either the prompt.
7028
04:00:39,172 --> 04:00:40,763
and I must say self dot
7029
04:00:40,942 --> 04:00:42,683
answer is equal to answer.
7030
04:00:42,982 --> 04:00:47,542
so now we have a question class set up and we can store all the information we need
7031
04:00:47,962 --> 04:00:49,372
about a question.
7032
04:00:49,882 --> 04:00:53,812
so what I want to do now is go back over to my app dot python file,
7033
04:00:54,411 --> 04:00:57,082
and we're actually going to create an array of questions.
7034
04:00:57,322 --> 04:01:00,142
so I have over here these three prompts,
7035
04:01:00,472 --> 04:01:03,232
and I'm actually just going to create another array so we'll just call it
7036
04:01:03,742 --> 04:01:04,672
questions.
7037
04:01:05,062 --> 04:01:06,950
and I'm going to set it equal to
7038
04:01:07,580 --> 04:01:09,171
to open or closed square brackets
7039
04:01:09,471 --> 04:01:11,210
and we're gonna start creating question
7040
04:01:11,240 --> 04:01:12,830
objects so I can just say
7041
04:01:13,130 --> 04:01:15,561
the first element in this questions ray will be a
7042
04:01:16,190 --> 04:01:16,940
question,
7043
04:01:17,421 --> 04:01:18,831
and we want to pass
7044
04:01:19,971 --> 04:01:21,351
questioned prompts
7045
04:01:22,221 --> 04:01:22,971
zero.
7046
04:01:23,121 --> 04:01:26,031
and the answer to the first question was
7047
04:01:26,361 --> 04:01:26,751
a
7048
04:01:26,781 --> 04:01:29,389
red green and that's the color of apple so I'm gonna pass
7049
04:01:29,599 --> 04:01:30,859
that first question.
7050
04:01:30,919 --> 04:01:32,689
and I'm also going to pass
7051
04:01:32,749 --> 04:01:34,039
the answer which is a,
7052
04:01:34,339 --> 04:01:36,468
and you see down here I'm getting an error so
7053
04:01:36,647 --> 04:01:37,667
seeing unresolved
7054
04:01:37,697 --> 04:01:38,357
references
7055
04:01:38,388 --> 04:01:39,107
question
7056
04:01:39,438 --> 04:01:41,657
so actually what we need to do before we can
7057
04:01:41,777 --> 04:01:46,098
create these questions is we need to import this question class on mckillop been here
7058
04:01:46,128 --> 04:01:47,059
come up here and say
7059
04:01:47,358 --> 04:01:47,898
from
7060
04:01:48,078 --> 04:01:48,918
question
7061
04:01:49,728 --> 04:01:50,508
import
7062
04:01:50,988 --> 04:01:51,648
question
7063
04:01:52,698 --> 04:01:53,358
so now
7064
04:01:53,389 --> 04:01:55,278
down here in this questions array we're
7065
04:01:55,309 --> 04:01:58,638
not getting that hair anymore so we created one question objects.
7066
04:01:59,088 --> 04:02:00,198
and I'm just going to
7067
04:02:00,229 --> 04:02:01,699
create a couple more for
7068
04:02:01,729 --> 04:02:02,659
these other ones
7069
04:02:02,689 --> 04:02:03,289
so
7070
04:02:04,009 --> 04:02:05,269
I'm just going to copy this one
7071
04:02:05,299 --> 04:02:05,929
and
7072
04:02:05,988 --> 04:02:08,029
we will pace this down here,
7073
04:02:10,640 --> 04:02:11,899
or it's an hour creating
7074
04:02:11,930 --> 04:02:14,391
two other questions in these ones are going to be
7075
04:02:14,480 --> 04:02:16,010
one and two.
7076
04:02:16,310 --> 04:02:18,799
and the answer to the second question is
7077
04:02:18,829 --> 04:02:19,639
c.
7078
04:02:20,119 --> 04:02:22,850
and the answer to the third question I think is that the
7079
04:02:23,149 --> 04:02:23,629
new york
7080
04:02:25,309 --> 04:02:25,608
yeah
7081
04:02:25,639 --> 04:02:26,119
so it's
7082
04:02:26,149 --> 04:02:26,779
cmb.
7083
04:02:27,319 --> 04:02:29,479
so essentially what we're doing is we're creating
7084
04:02:29,510 --> 04:02:30,830
three questions.
7085
04:02:30,890 --> 04:02:32,929
each one is getting a different question prompts,
7086
04:02:33,139 --> 04:02:38,147
and they're each getting different answers so now we have an array of questions that we want to ask
7087
04:02:38,447 --> 04:02:39,438
on our test.
7088
04:02:39,798 --> 04:02:44,266
so the next step is to actually write a function that will run the test right
7089
04:02:44,355 --> 04:02:47,566
it has to ask these are the questions and it has to check to see
7090
04:02:47,746 --> 04:02:49,306
if they got the answer right so
7091
04:02:49,636 --> 04:02:50,386
down here
7092
04:02:50,416 --> 04:02:51,285
lower in the file
7093
04:02:51,315 --> 04:02:52,635
let's create a function.
7094
04:02:53,115 --> 04:02:53,926
so I'm just going to say
7095
04:02:53,956 --> 04:02:54,437
death.
7096
04:02:54,706 --> 04:02:55,937
we'll call this run
7097
04:02:55,967 --> 04:02:56,657
test
7098
04:02:57,228 --> 04:02:57,708
and
7099
04:02:57,738 --> 04:02:59,178
inside of his prentices
7100
04:02:59,237 --> 04:03:02,057
were going to take one parameter into this function.
7101
04:03:02,297 --> 04:03:02,896
we're going to take
7102
04:03:02,927 --> 04:03:04,968
a list of questions so
7103
04:03:05,027 --> 04:03:06,527
I'm just going to say questions.
7104
04:03:07,188 --> 04:03:09,018
so this is basically going to be a list
7105
04:03:09,048 --> 04:03:11,928
of question objects that we want to ask the user.
7106
04:03:12,348 --> 04:03:13,518
so once I've been here
7107
04:03:13,548 --> 04:03:14,956
all I want to do is a loop
7108
04:03:14,986 --> 04:03:16,786
through all the questions so
7109
04:03:16,966 --> 04:03:18,496
I want to loop through each question
7110
04:03:18,526 --> 04:03:20,206
I want to ask it to the user.
7111
04:03:20,356 --> 04:03:23,566
I want to get the user's answer and I want to check to see if it's right,
7112
04:03:24,047 --> 04:03:30,465
and we need to be able to keep track of how the user does through the test so I'm gonna create a variable called score
7113
04:03:30,885 --> 04:03:32,594
and I'm going to set it equal to zero,
7114
04:03:32,894 --> 04:03:36,193
so every time the user answers a question right will increment this
7115
04:03:36,224 --> 04:03:37,124
score
7116
04:03:37,184 --> 04:03:37,903
variable
7117
04:03:38,474 --> 04:03:44,172
right so what I want to do is like I said loop through all the questions in that questions array so I'm going to create a for loop
7118
04:03:44,202 --> 04:03:45,312
I'm going to say for
7119
04:03:45,941 --> 04:03:46,842
question
7120
04:03:47,052 --> 04:03:47,651
in
7121
04:03:48,342 --> 04:03:49,212
questions.
7122
04:03:50,052 --> 04:03:52,513
so in other words for each question object
7123
04:03:52,843 --> 04:03:54,644
inside of this questions array.
7124
04:03:54,703 --> 04:03:55,663
I want to do something.
7125
04:03:56,533 --> 04:03:57,073
and
7126
04:03:57,104 --> 04:04:00,283
basically the first thing I want to do is ask the user the question
7127
04:04:00,823 --> 04:04:03,792
and I want to store their response inside of a variable.
7128
04:04:04,092 --> 04:04:05,052
so I'm going to say
7129
04:04:05,082 --> 04:04:06,853
I wanna make a variable down here called
7130
04:04:07,122 --> 04:04:07,812
answer.
7131
04:04:08,412 --> 04:04:10,423
and this is going to represent the
7132
04:04:10,453 --> 04:04:12,163
user's answer to the question.
7133
04:04:12,223 --> 04:04:12,793
and I'm gonna
7134
04:04:12,853 --> 04:04:13,183
set it
7135
04:04:13,213 --> 04:04:13,902
equal to
7136
04:04:14,263 --> 04:04:14,982
input
7137
04:04:15,822 --> 04:04:17,472
and I need to give this a prompt
7138
04:04:17,502 --> 04:04:18,162
so
7139
04:04:18,222 --> 04:04:21,792
I'm actually going to give this the prompt for the questions I can just say
7140
04:04:22,122 --> 04:04:23,262
questioned dot
7141
04:04:23,321 --> 04:04:24,071
prompt.
7142
04:04:24,131 --> 04:04:25,361
so now I have
7143
04:04:25,722 --> 04:04:29,109
the answer that the user entered in which is stored inside this variable.
7144
04:04:29,649 --> 04:04:32,019
so we want to check to see if they got the question right.
7145
04:04:32,229 --> 04:04:33,369
and I can do that using an
7146
04:04:33,399 --> 04:04:34,568
if statement so I can say
7147
04:04:34,599 --> 04:04:35,079
if
7148
04:04:35,739 --> 04:04:36,399
answer
7149
04:04:36,669 --> 04:04:38,680
and this refers to the student's answer
7150
04:04:39,460 --> 04:04:40,511
is equal to
7151
04:04:40,961 --> 04:04:42,012
question dot
7152
04:04:42,042 --> 04:04:42,612
answer
7153
04:04:42,882 --> 04:04:44,951
so I'm checking to see if the answer that the student
7154
04:04:44,981 --> 04:04:45,401
gave
7155
04:04:45,461 --> 04:04:48,222
as equal to the answer of the current question
7156
04:04:48,252 --> 04:04:48,792
that we're
7157
04:04:48,882 --> 04:04:49,452
asking.
7158
04:04:49,842 --> 04:04:51,222
and if this is true,
7159
04:04:51,312 --> 04:04:52,421
then I just want to
7160
04:04:52,451 --> 04:04:54,822
increment score so I'm going to say score
7161
04:04:55,362 --> 04:04:55,782
plus
7162
04:04:55,812 --> 04:04:58,572
equals one and this basically just means we're adding one
7163
04:04:58,603 --> 04:04:59,442
to the score.
7164
04:04:59,952 --> 04:05:02,893
so the last thing I want to do inside of this function is just
7165
04:05:02,923 --> 04:05:03,673
print out
7166
04:05:03,732 --> 04:05:06,073
the results I want to print out how the user did
7167
04:05:06,854 --> 04:05:08,264
so down here I'm just going to say,
7168
04:05:08,414 --> 04:05:08,834
print
7169
04:05:08,864 --> 04:05:11,174
and I'm basically just going up are not like hey you got like
7170
04:05:11,204 --> 04:05:14,623
two out of three questions are you got five out of six questions right
7171
04:05:14,803 --> 04:05:16,933
or you got zero out of ten questions right well
7172
04:05:16,992 --> 04:05:18,463
what does per not how they did so
7173
04:05:18,793 --> 04:05:20,354
to say to you got.
7174
04:05:21,163 --> 04:05:24,253
and now I want to print out how many questions they got right
7175
04:05:24,283 --> 04:05:25,933
so this is just going to be this score.
7176
04:05:26,263 --> 04:05:27,223
and in order to print
7177
04:05:27,253 --> 04:05:31,542
a number alongside of a string like this I'm going to have to say s t r,
7178
04:05:31,722 --> 04:05:33,581
and then type in the number so say
7179
04:05:33,641 --> 04:05:34,750
str score
7180
04:05:35,320 --> 04:05:36,850
so basically say you got
7181
04:05:36,939 --> 04:05:38,289
however many they got right
7182
04:05:38,649 --> 04:05:40,389
out of so we use this little
7183
04:05:40,419 --> 04:05:41,350
forward slash.
7184
04:05:41,770 --> 04:05:42,310
and
7185
04:05:43,210 --> 04:05:44,141
now we'll just say
7186
04:05:44,171 --> 04:05:46,512
how many questions there were so we can say.
7187
04:05:46,752 --> 04:05:50,951
and then I'm going to have to convert this to a string because it's going to be in numbers we can say string
7188
04:05:51,551 --> 04:05:55,271
and then want to figure out how many questions were in that questions array so I can say.
7189
04:05:55,331 --> 04:05:56,111
ellie ann
7190
04:05:56,472 --> 04:05:57,881
and inside of here we can just say
7191
04:05:57,911 --> 04:05:58,511
questions
7192
04:05:58,541 --> 04:05:59,531
so this is kind of like
7193
04:05:59,591 --> 04:05:59,951
this
7194
04:05:59,981 --> 04:06:02,831
long state and just to turn out how many questions that were
7195
04:06:02,951 --> 04:06:04,271
so that over here to say
7196
04:06:04,871 --> 04:06:05,591
correct.
7197
04:06:06,581 --> 04:06:08,620
so now we have this print statement.
7198
04:06:09,010 --> 04:06:12,398
and it's just going to be printing out how many questions they got right.
7199
04:06:13,208 --> 04:06:14,197
so let's see if
7200
04:06:14,467 --> 04:06:17,286
this works the last thing I need to do is just call this
7201
04:06:17,316 --> 04:06:19,297
run test function so I'll say
7202
04:06:19,687 --> 04:06:20,677
run tests.
7203
04:06:20,736 --> 04:06:22,327
and I'm just going to pass it that
7204
04:06:22,447 --> 04:06:24,848
questions are ready to be created before so
7205
04:06:25,208 --> 04:06:28,058
we created this questions array with all of these question
7206
04:06:28,088 --> 04:06:29,467
objects inside of it.
7207
04:06:30,187 --> 04:06:33,155
I'm basically just going to pass that into this run test
7208
04:06:33,186 --> 04:06:33,726
function.
7209
04:06:34,266 --> 04:06:35,976
so now let's run our program and
7210
04:06:36,006 --> 04:06:37,386
see how we didn't hopefully
7211
04:06:37,416 --> 04:06:38,676
we don't getting errors.
7212
04:06:39,006 --> 04:06:40,444
there's a lot of code there so
7213
04:06:40,714 --> 04:06:41,944
it's possible that we might.
7214
04:06:42,814 --> 04:06:46,353
okay so this is what color are apples has a tough one I once put
7215
04:06:46,383 --> 04:06:46,772
a.
7216
04:06:46,832 --> 04:06:48,302
so we'll get the first question right ?
7217
04:06:48,691 --> 04:06:49,921
what color are bananas.
7218
04:06:49,980 --> 04:06:51,690
let's get the second question wrong
7219
04:06:51,721 --> 04:06:52,529
so I'm going to say
7220
04:06:52,680 --> 04:06:54,539
be bananas aren't magenta
7221
04:06:55,199 --> 04:06:58,829
and we'll get the third question right so it says what color are strawberries
7222
04:06:58,859 --> 04:07:00,930
output be cassettes the right answer,
7223
04:07:01,470 --> 04:07:02,130
so now
7224
04:07:02,189 --> 04:07:04,109
you'll see that our program prints out
7225
04:07:04,140 --> 04:07:06,300
you've got two out of three correct.
7226
04:07:06,689 --> 04:07:10,740
so not only did to ask us all the questions and get our input for each question
7227
04:07:10,771 --> 04:07:12,361
but it also kept track of
7228
04:07:12,451 --> 04:07:14,491
our score and it printed it out so
7229
04:07:14,852 --> 04:07:16,682
why don't we run through the tasks one more time.
7230
04:07:17,132 --> 04:07:17,672
and
7231
04:07:17,702 --> 04:07:18,392
we'll just like
7232
04:07:18,872 --> 04:07:23,464
get two wrong this time so we'll get this one wrong I'll get this one wrong and I get this one right.
7233
04:07:23,974 --> 04:07:24,694
so now it says
7234
04:07:24,725 --> 04:07:26,826
you got one out of three correct so
7235
04:07:26,946 --> 04:07:28,627
say would actually great our test.
7236
04:07:28,687 --> 04:07:29,076
and
7237
04:07:29,166 --> 04:07:31,535
what's cool about the program we just wrote is
7238
04:07:32,016 --> 04:07:35,075
if I wanted I could add another question into here
7239
04:07:35,436 --> 04:07:35,796
and it would
7240
04:07:35,826 --> 04:07:40,205
automatically be able to ask it so it doesn't matter how many questions we put in here
7241
04:07:41,015 --> 04:07:42,035
it's just able to ask
7242
04:07:42,065 --> 04:07:42,485
so
7243
04:07:42,995 --> 04:07:48,365
really the point I was trying to make with this whole video was just how we can use something like a class
7244
04:07:48,605 --> 04:07:49,415
in order to
7245
04:07:49,445 --> 04:07:51,096
model a real world
7246
04:07:51,155 --> 04:07:51,755
entity.
7247
04:07:52,055 --> 04:07:53,075
so for example
7248
04:07:53,105 --> 04:07:55,505
we created this question class.
7249
04:07:55,715 --> 04:07:58,356
and we were able to store all the information
7250
04:07:58,416 --> 04:08:02,497
about a question that we could ever needs were ill bizarrely the prompts and the answer,
7251
04:08:02,947 --> 04:08:04,928
so we created our own question
7252
04:08:04,958 --> 04:08:05,678
data type
7253
04:08:05,708 --> 04:08:08,408
and then we were able to create a bunch of different questions,
7254
04:08:08,678 --> 04:08:10,717
pass it into this ron test method,
7255
04:08:10,837 --> 04:08:14,076
and it was able to grade the test and just run the test
7256
04:08:14,106 --> 04:08:16,026
really easily so that's kind of the point.
7257
04:08:16,626 --> 04:08:17,916
so hopefully this makes sense.
7258
04:08:18,186 --> 04:08:19,686
you know this was a lot of code
7259
04:08:19,716 --> 04:08:23,885
so if you don't fully understand what I did go back watch the video you know,
7260
04:08:23,944 --> 04:08:28,083
try to cobble times on your own and see if you can create your own multiple choice test
7261
04:08:31,863 --> 04:08:33,934
in this tutorial on talks you guys about
7262
04:08:33,964 --> 04:08:35,674
class functions
7263
04:08:35,704 --> 04:08:36,274
in
7264
04:08:36,334 --> 04:08:37,264
python so
7265
04:08:37,504 --> 04:08:40,864
a class function is essentially a function that we can use
7266
04:08:40,895 --> 04:08:42,663
inside of a class and it can
7267
04:08:42,693 --> 04:08:45,934
either modify the objects of that class where it can
7268
04:08:46,203 --> 04:08:48,753
give a specific information about those objects.
7269
04:08:48,812 --> 04:08:52,082
over here I have this student dot pi file
7270
04:08:52,562 --> 04:08:52,982
and
7271
04:08:53,042 --> 04:08:57,030
inside of here I created a student class I was headed class student
7272
04:08:57,391 --> 04:08:58,380
and I gave this student
7273
04:08:58,410 --> 04:09:00,839
a couple of different attributes I gave it a name,
7274
04:09:01,229 --> 04:09:03,208
a major and a gps
7275
04:09:03,238 --> 04:09:04,708
so I can give this student.
7276
04:09:04,768 --> 04:09:07,467
all of this information so when I create a student objects.
7277
04:09:07,856 --> 04:09:08,456
it'll have
7278
04:09:08,516 --> 04:09:09,745
all of that information
7279
04:09:09,775 --> 04:09:10,135
in it.
7280
04:09:10,585 --> 04:09:11,724
now over here on this
7281
04:09:11,754 --> 04:09:15,083
app dot pi file it actually created to students
7282
04:09:15,113 --> 04:09:15,684
so
7283
04:09:15,983 --> 04:09:17,483
student one is
7284
04:09:17,753 --> 04:09:21,263
oscar who was studying accounting and has a gps unit three point one
7285
04:09:21,652 --> 04:09:24,473
student to as phyllis who's studying business
7286
04:09:24,503 --> 04:09:25,822
and she has a three point
7287
04:09:25,882 --> 04:09:26,212
e.
7288
04:09:26,902 --> 04:09:27,442
so
7289
04:09:27,532 --> 04:09:29,573
what we can actually do is we can
7290
04:09:29,693 --> 04:09:35,094
use functions inside of these class files so I can actually define a function
7291
04:09:35,514 --> 04:09:38,604
instead of this student class and then all of my
7292
04:09:38,635 --> 04:09:40,495
student objects could access it.
7293
04:09:40,555 --> 04:09:41,515
so for example,
7294
04:09:41,604 --> 04:09:44,124
I can come down here and create a function and
7295
04:09:44,814 --> 04:09:46,613
let's say we wanted to create a function
7296
04:09:46,644 --> 04:09:47,153
that
7297
04:09:47,184 --> 04:09:49,582
told us whether or not this particular student
7298
04:09:49,642 --> 04:09:50,782
had honours
7299
04:09:50,812 --> 04:09:52,853
so whether or not they were on the honor roll right
7300
04:09:53,093 --> 04:09:53,872
basically like,
7301
04:09:54,022 --> 04:09:55,643
are they like a really good student
7302
04:09:56,333 --> 04:09:57,893
so I can define a function
7303
04:09:58,192 --> 04:09:58,763
call
7304
04:09:58,883 --> 04:09:59,423
on
7305
04:10:00,113 --> 04:10:00,953
honor roll
7306
04:10:01,673 --> 04:10:02,243
and
7307
04:10:02,273 --> 04:10:04,104
basically what it's going to do,
7308
04:10:04,254 --> 04:10:07,764
it's going to tell me whether or not this particular student is on
7309
04:10:07,823 --> 04:10:08,633
the honourable
7310
04:10:09,232 --> 04:10:09,622
and
7311
04:10:09,652 --> 04:10:13,490
let's basically just say the rules are being on honor roll is you have to have a
7312
04:10:13,521 --> 04:10:14,330
gps iif
7313
04:10:14,360 --> 04:10:16,040
three point five or above.
7314
04:10:16,340 --> 04:10:19,819
so here gps three point five or above that means you're on the honor roll
7315
04:10:20,300 --> 04:10:20,689
well
7316
04:10:20,720 --> 04:10:22,550
over here I could actually
7317
04:10:22,609 --> 04:10:24,198
write the code for that so I could say
7318
04:10:24,229 --> 04:10:24,709
if
7319
04:10:25,609 --> 04:10:27,350
self dot gps.
7320
04:10:27,830 --> 04:10:29,450
and when I say self over here
7321
04:10:29,601 --> 04:10:31,041
this is referring to like
7322
04:10:31,101 --> 04:10:33,050
the actual students gps
7323
04:10:33,500 --> 04:10:33,860
and you'll
7324
04:10:33,920 --> 04:10:36,229
notice over here I have to pass that in
7325
04:10:36,770 --> 04:10:37,729
as a parameter.
7326
04:10:37,789 --> 04:10:40,490
and that always has to be the first parameter so I could say if
7327
04:10:40,730 --> 04:10:42,262
self dot j e p a
7328
04:10:42,622 --> 04:10:43,432
is greater than or
7329
04:10:43,462 --> 04:10:44,271
equal to
7330
04:10:44,781 --> 04:10:46,011
the read point five.
7331
04:10:46,701 --> 04:10:48,322
then we can return
7332
04:10:48,592 --> 04:10:49,191
true
7333
04:10:49,791 --> 04:10:50,812
because this student
7334
04:10:50,842 --> 04:10:52,281
is on the honor roll
7335
04:10:53,182 --> 04:10:54,292
otherwise
7336
04:10:54,382 --> 04:10:55,161
an else
7337
04:10:55,371 --> 04:10:56,660
we can just return
7338
04:10:57,950 --> 04:10:59,271
false because
7339
04:10:59,330 --> 04:10:59,961
if their gps
7340
04:10:59,991 --> 04:11:01,642
isn't above a three point five that
7341
04:11:01,672 --> 04:11:02,542
they're not on
7342
04:11:02,602 --> 04:11:03,441
the honor roll.
7343
04:11:03,892 --> 04:11:04,372
so
7344
04:11:04,402 --> 04:11:08,752
that's essentially our little on honorable function and you can see it's a very small function,
7345
04:11:08,992 --> 04:11:10,013
but it provides
7346
04:11:10,043 --> 04:11:13,072
a service to the objects of this class right
7347
04:11:13,103 --> 04:11:13,763
it allows
7348
04:11:13,793 --> 04:11:15,263
the objects of this class to
7349
04:11:15,652 --> 04:11:19,133
figure out whether or not that current student is on the honor roll so
7350
04:11:19,853 --> 04:11:22,042
over in this app dot pi file.
7351
04:11:22,882 --> 04:11:24,142
I could just print
7352
04:11:24,292 --> 04:11:25,701
out that values so I could say
7353
04:11:25,731 --> 04:11:26,182
print
7354
04:11:26,812 --> 04:11:28,102
and I'm gonna see if
7355
04:11:28,672 --> 04:11:29,992
student one
7356
04:11:30,562 --> 04:11:32,063
is on the honor roll.
7357
04:11:32,813 --> 04:11:33,563
so
7358
04:11:33,983 --> 04:11:37,103
now when I run this you'll see it should print out false
7359
04:11:37,312 --> 04:11:38,633
and is putting out false
7360
04:11:38,663 --> 04:11:39,533
down here
7361
04:11:39,713 --> 04:11:41,993
because student one only has a gps
7362
04:11:42,023 --> 04:11:42,354
of
7363
04:11:42,413 --> 04:11:43,584
three point one.
7364
04:11:43,944 --> 04:11:46,254
if I was to do the same thing on student to
7365
04:11:46,884 --> 04:11:48,683
students who has a gdp of three point
7366
04:11:48,713 --> 04:11:49,013
eight
7367
04:11:49,043 --> 04:11:50,902
so we should return true.
7368
04:11:51,232 --> 04:11:53,332
and that's exactly what happens so
7369
04:11:53,662 --> 04:11:54,742
essentially a
7370
04:11:54,772 --> 04:12:01,763
class function is just a little function that can be used by the objects of the class and I would say this is a pretty good example of
7371
04:12:02,183 --> 04:12:04,043
what a class function should be doing
7372
04:12:04,312 --> 04:12:09,979
should be like giving us information about the class or it could also be like modifying information about the class.
7373
04:12:10,038 --> 04:12:14,387
and so that's the basics of using functions and classes I mean this is a pretty simple tutorial but
7374
04:12:14,627 --> 04:12:17,476
I really just wanted to introduce you guys to the concept
7375
04:12:17,506 --> 04:12:17,896
of
7376
04:12:18,165 --> 04:12:18,765
pudding
7377
04:12:18,795 --> 04:12:19,875
met functions
7378
04:12:19,935 --> 04:12:22,604
inside of classes this is going to be really useful and
7379
04:12:23,023 --> 04:12:27,523
if you're making a class you always wanna think about like what functions can I put inside of here
7380
04:12:27,793 --> 04:12:28,394
that will
7381
04:12:28,424 --> 04:12:29,594
you know essentially
7382
04:12:29,624 --> 04:12:32,834
healthy user to either figure out information about the object
7383
04:12:33,284 --> 04:12:33,914
or
7384
04:12:33,974 --> 04:12:36,734
modify different values in the objects
7385
04:12:40,544 --> 04:12:43,215
in this tutorial on antarctic guys about inheritance
7386
04:12:43,245 --> 04:12:43,515
in
7387
04:12:43,545 --> 04:12:44,175
python.
7388
04:12:44,685 --> 04:12:49,965
inheritance is basically where we can define a bunch of attributes and functions
7389
04:12:50,234 --> 04:12:51,854
and things inside of a class,
7390
04:12:52,095 --> 04:12:55,905
and then we can create another class and we can inherit all of those
7391
04:12:55,965 --> 04:12:56,715
attributes.
7392
04:12:57,015 --> 04:12:58,215
so I could basically
7393
04:12:58,245 --> 04:12:59,805
have one class that has
7394
04:12:59,835 --> 04:13:01,996
all the functionality of another class
7395
04:13:02,356 --> 04:13:05,296
without having to physically write out any of the same
7396
04:13:05,326 --> 04:13:07,066
methods or attributes.
7397
04:13:07,336 --> 04:13:09,346
so it that's confusing don't worry I'm
7398
04:13:09,405 --> 04:13:11,085
sure you guys exactly what this is
7399
04:13:11,385 --> 04:13:12,555
in this video so
7400
04:13:13,154 --> 04:13:15,493
let me show you about some stop I have set up over here.
7401
04:13:15,854 --> 04:13:17,654
I created this class
7402
04:13:17,685 --> 04:13:18,404
called
7403
04:13:18,555 --> 04:13:19,335
chef
7404
04:13:19,815 --> 04:13:21,556
and over here we just have this class chef.
7405
04:13:21,976 --> 04:13:25,034
and inside of this chef class we have three functions
7406
04:13:25,064 --> 04:13:26,924
so the shaft can do three things.
7407
04:13:27,313 --> 04:13:28,093
the chef can
7408
04:13:28,123 --> 04:13:28,423
make
7409
04:13:28,453 --> 04:13:29,023
chicken.
7410
04:13:29,653 --> 04:13:30,584
the chef can
7411
04:13:30,614 --> 04:13:31,574
make solid
7412
04:13:31,844 --> 04:13:32,983
and the chef can make
7413
04:13:33,014 --> 04:13:34,063
a special dish.
7414
04:13:34,363 --> 04:13:36,224
and whatever the chef makes a dish
7415
04:13:36,254 --> 04:13:37,604
he basically just says
7416
04:13:37,874 --> 04:13:40,424
the chef makes a chick in order the chef makes
7417
04:13:40,454 --> 04:13:41,264
a salad
7418
04:13:41,684 --> 04:13:44,714
or the chef makes barbecue ribs for this special dish.
7419
04:13:44,983 --> 04:13:46,273
so basically just
7420
04:13:46,333 --> 04:13:48,643
saying whatever the chef is doing so
7421
04:13:48,883 --> 04:13:51,462
if I was to come over here to my app dot python file,
7422
04:13:51,731 --> 04:13:53,622
you'll notice that I'm importing the
7423
04:13:53,742 --> 04:13:54,252
chef
7424
04:13:54,282 --> 04:13:55,512
so I'm basically
7425
04:13:55,872 --> 04:13:57,823
allowed to use this chef class now,
7426
04:13:58,333 --> 04:13:59,412
and I can say
7427
04:13:59,442 --> 04:14:02,352
my chef is equal to shafts I'm creating a new chef.
7428
04:14:02,682 --> 04:14:05,412
so now if I came down here and I send my
7429
04:14:05,472 --> 04:14:06,162
chef
7430
04:14:06,192 --> 04:14:06,853
dot
7431
04:14:07,122 --> 04:14:07,422
make
7432
04:14:07,452 --> 04:14:07,962
chicken,
7433
04:14:09,672 --> 04:14:11,171
when I run my program.
7434
04:14:11,230 --> 04:14:12,430
now it's going to say,
7435
04:14:13,420 --> 04:14:14,709
the chef makes a chicken.
7436
04:14:14,979 --> 04:14:15,788
if I said
7437
04:14:15,818 --> 04:14:16,599
make
7438
04:14:18,129 --> 04:14:19,479
special dish
7439
04:14:20,078 --> 04:14:21,157
and are on the program.
7440
04:14:21,337 --> 04:14:25,116
now it's going to say the chef makes barbecue ribs so it because that's the chef's
7441
04:14:25,146 --> 04:14:26,076
special dish.
7442
04:14:26,316 --> 04:14:29,285
so I have this really awesome chef class and it works really well.
7443
04:14:29,915 --> 04:14:32,826
but let's say that I wanted to create another class
7444
04:14:32,856 --> 04:14:35,257
to model another type of chef
7445
04:14:35,646 --> 04:14:36,275
rise to this
7446
04:14:36,335 --> 04:14:39,455
chef class is just modelling like some generic schafroff
7447
04:14:39,485 --> 04:14:41,196
we're representing some generic chef
7448
04:14:41,526 --> 04:14:42,307
in our program,
7449
04:14:42,787 --> 04:14:44,617
but let's say that I wanted to create
7450
04:14:44,647 --> 04:14:45,277
a
7451
04:14:45,457 --> 04:14:47,828
class that modeled the different type of chef
7452
04:14:47,858 --> 04:14:48,579
for example,
7453
04:14:48,879 --> 04:14:51,908
let's say we wanted to create a class that modeled a chinese chef.
7454
04:14:51,968 --> 04:14:53,978
so instead of just a normal chef this is a
7455
04:14:54,008 --> 04:14:54,998
chinese chef,
7456
04:14:55,479 --> 04:14:57,908
well I actually created a file over here called
7457
04:14:57,938 --> 04:14:59,648
chinese chef dot python.
7458
04:14:59,948 --> 04:15:02,138
so we can actually use this
7459
04:15:02,228 --> 04:15:05,288
chinese shaft out python file to create our chinese
7460
04:15:05,318 --> 04:15:05,828
chef
7461
04:15:05,858 --> 04:15:06,458
class
7462
04:15:06,758 --> 04:15:08,168
tom's going as a class.
7463
04:15:08,228 --> 04:15:10,058
and over here I'm just going to say
7464
04:15:10,117 --> 04:15:11,228
chinese chef
7465
04:15:11,678 --> 04:15:12,248
and
7466
04:15:12,908 --> 04:15:13,898
basically
7467
04:15:14,019 --> 04:15:16,929
I just can define everything that the chinese chef can do,
7468
04:15:17,349 --> 04:15:18,519
but let's say that
7469
04:15:18,549 --> 04:15:20,019
our chinese chef
7470
04:15:20,288 --> 04:15:21,068
can do
7471
04:15:21,099 --> 04:15:23,768
everything that are generic chef can do.
7472
04:15:23,947 --> 04:15:25,956
so the chinese chef is like a special
7473
04:15:25,986 --> 04:15:28,296
schafroff it's very specific type of chef.
7474
04:15:28,746 --> 04:15:30,636
but let's say that this chinese chef
7475
04:15:30,666 --> 04:15:34,687
can do everything that the normal chef can do so the chinese chef can make chicken
7476
04:15:34,866 --> 04:15:35,856
can make salad,
7477
04:15:36,066 --> 04:15:37,267
and can also make
7478
04:15:37,297 --> 04:15:38,406
a special dish.
7479
04:15:38,496 --> 04:15:39,967
well if I wanted to give this
7480
04:15:39,997 --> 04:15:40,927
chinese chef,
7481
04:15:40,986 --> 04:15:42,546
all of that functionality.
7482
04:15:42,786 --> 04:15:46,444
I could just come over here and I could copy all of these
7483
04:15:46,475 --> 04:15:47,165
functions.
7484
04:15:47,555 --> 04:15:49,685
and I can paste them in here
7485
04:15:50,045 --> 04:15:52,564
and so now the chinese chef can do everything
7486
04:15:52,595 --> 04:15:54,065
that the other chefs can do,
7487
04:15:54,155 --> 04:15:57,454
but let's say that in addition to all of these things the chinese chef
7488
04:15:57,784 --> 04:15:59,164
can also make
7489
04:15:59,224 --> 04:16:01,264
a special dish called fried rice
7490
04:16:01,294 --> 04:16:02,164
so I could say
7491
04:16:02,314 --> 04:16:02,795
deaf
7492
04:16:03,125 --> 04:16:04,325
and we could say make
7493
04:16:04,835 --> 04:16:06,154
fried rice.
7494
04:16:06,244 --> 04:16:06,874
so
7495
04:16:07,144 --> 04:16:09,243
the chinese chef has this extra
7496
04:16:09,273 --> 04:16:11,403
function which allows it to make fried rice.
7497
04:16:11,703 --> 04:16:13,323
and over here we just say,
7498
04:16:13,413 --> 04:16:14,764
the chef makes
7499
04:16:14,854 --> 04:16:15,843
fried rice.
7500
04:16:16,173 --> 04:16:17,313
and let's also say that
7501
04:16:17,344 --> 04:16:21,783
the chinese chef has a different special dish so instead of making barbecue ribs.
7502
04:16:22,083 --> 04:16:23,463
the chinese chef makes
7503
04:16:23,522 --> 04:16:24,152
lunge
7504
04:16:24,183 --> 04:16:24,663
chicken.
7505
04:16:25,863 --> 04:16:28,562
all right so now we have our chinese chef class set up
7506
04:16:28,593 --> 04:16:30,872
and you'll notice that it can do everything
7507
04:16:30,902 --> 04:16:31,353
that
7508
04:16:31,383 --> 04:16:32,854
the normal chef could do.
7509
04:16:33,334 --> 04:16:36,784
so let's go back over to our app dot python file and I want to create
7510
04:16:36,814 --> 04:16:37,265
a
7511
04:16:37,295 --> 04:16:38,045
chinese chef
7512
04:16:38,075 --> 04:16:38,646
object.
7513
04:16:38,976 --> 04:16:39,726
so
7514
04:16:39,815 --> 04:16:41,766
instead of importing from chef
7515
04:16:41,796 --> 04:16:44,104
we're going to just import it from chinese chef.
7516
04:16:44,585 --> 04:16:45,425
so I'll say
7517
04:16:46,024 --> 04:16:46,924
chinese chef
7518
04:16:46,954 --> 04:16:48,094
and we're going to employ for
7519
04:16:48,514 --> 04:16:49,354
chinese chef.
7520
04:16:49,773 --> 04:16:51,032
so let's go ahead and make
7521
04:16:51,062 --> 04:16:52,202
a chinese chef
7522
04:16:52,262 --> 04:16:52,861
object
7523
04:16:53,731 --> 04:16:56,010
sit down here I'm going to make one arrow to say
7524
04:16:56,069 --> 04:16:56,850
my.
7525
04:16:57,029 --> 04:16:57,959
and then
7526
04:16:59,099 --> 04:17:00,180
my chinese chef.
7527
04:17:00,510 --> 04:17:02,699
we can print out this special dish so
7528
04:17:03,029 --> 04:17:04,529
remember the chinese chef can do
7529
04:17:04,560 --> 04:17:06,390
everything that the normal chef could do
7530
04:17:06,689 --> 04:17:08,850
so if I say my chinese chef da
7531
04:17:08,880 --> 04:17:10,049
make special dish.
7532
04:17:10,289 --> 04:17:12,179
when I run this program you'll see
7533
04:17:12,749 --> 04:17:13,439
the
7534
04:17:13,770 --> 04:17:17,880
regular chef is making barbecue ribs and the chinese chef is making orange
7535
04:17:17,910 --> 04:17:18,450
chicken
7536
04:17:18,510 --> 04:17:19,619
so everything works out.
7537
04:17:19,739 --> 04:17:23,189
and this chinese chef also has an extra method called make
7538
04:17:24,239 --> 04:17:25,410
fried rice.
7539
04:17:25,891 --> 04:17:26,490
and
7540
04:17:26,550 --> 04:17:27,390
you can also
7541
04:17:27,420 --> 04:17:27,810
make
7542
04:17:27,840 --> 04:17:28,740
fried rice.
7543
04:17:28,800 --> 04:17:31,079
but here's the problem right when I go over here to this
7544
04:17:31,109 --> 04:17:32,850
chinese chef dot pie.
7545
04:17:33,600 --> 04:17:37,200
I went I wanted to use all of the functionality that was inside this
7546
04:17:37,230 --> 04:17:38,250
chuffed class
7547
04:17:38,580 --> 04:17:42,061
I actually had to copy and physically paste.
7548
04:17:42,541 --> 04:17:44,281
all of these functions down
7549
04:17:44,312 --> 04:17:45,601
into this file right
7550
04:17:45,780 --> 04:17:46,949
and that's kind of a drag.
7551
04:17:47,219 --> 04:17:49,919
and they especially like imagine if this chef had like
7552
04:17:49,979 --> 04:17:52,350
twenty or thirty of these different functions in it.
7553
04:17:52,649 --> 04:17:54,719
we have to copy and I have the pace.
7554
04:17:54,778 --> 04:17:57,057
all of those inside of this chinese chef
7555
04:17:57,087 --> 04:17:59,786
and this is where we can use something called inheritance
7556
04:17:59,816 --> 04:18:01,556
so instead of having to copy and paste
7557
04:18:01,586 --> 04:18:03,087
all of these functions.
7558
04:18:03,327 --> 04:18:05,607
I could just inherit these functions
7559
04:18:05,638 --> 04:18:06,237
from that
7560
04:18:06,268 --> 04:18:07,197
chef class
7561
04:18:07,587 --> 04:18:08,816
and in order to do that,
7562
04:18:08,906 --> 04:18:10,766
I can actually just get rid of all of these,
7563
04:18:11,065 --> 04:18:12,626
and I can come over here
7564
04:18:12,866 --> 04:18:13,496
and
7565
04:18:13,916 --> 04:18:16,496
right next to where I'm saying class chinese chef
7566
04:18:16,796 --> 04:18:22,254
inside of the parentheses I can say the name of the class that I want to inherit from so I can just say a chef.
7567
04:18:22,974 --> 04:18:27,054
and I'm also going to have to import this song to come over here and we'll say
7568
04:18:27,983 --> 04:18:28,674
from
7569
04:18:28,974 --> 04:18:29,693
chef
7570
04:18:30,563 --> 04:18:31,374
in poor
7571
04:18:31,494 --> 04:18:32,124
shelf.
7572
04:18:32,754 --> 04:18:34,675
so basically what this is saying is
7573
04:18:34,705 --> 04:18:36,686
inside of this chinese chef.
7574
04:18:37,136 --> 04:18:40,615
I want to be able to use all of the functions that are contained
7575
04:18:40,675 --> 04:18:42,415
inside of the chef class
7576
04:18:42,685 --> 04:18:43,825
so say that one more time
7577
04:18:44,275 --> 04:18:46,376
inside of this chinese chef class
7578
04:18:46,406 --> 04:18:49,557
I want to be able to use all of the functions that are inside of this
7579
04:18:49,587 --> 04:18:50,427
chef class
7580
04:18:50,937 --> 04:18:51,536
so
7581
04:18:51,596 --> 04:18:53,576
by using inheritance here
7582
04:18:53,727 --> 04:18:57,118
I'm actually able to come over here to this anecdote pi file.
7583
04:18:57,178 --> 04:18:57,838
and now
7584
04:18:58,138 --> 04:19:00,508
I'm still able to execute for example like
7585
04:19:00,567 --> 04:19:01,107
the make
7586
04:19:01,138 --> 04:19:01,768
chicken
7587
04:19:01,827 --> 04:19:02,457
function.
7588
04:19:03,057 --> 04:19:07,737
even though I didn't specify the make chicken function in here I didn't write it out.
7589
04:19:08,397 --> 04:19:10,827
I can still run this program
7590
04:19:10,887 --> 04:19:12,057
and the chinese stuff.
7591
04:19:12,116 --> 04:19:14,636
the chinese chef will still be able to make
7592
04:19:14,666 --> 04:19:15,206
chicken.
7593
04:19:15,626 --> 04:19:17,215
so when I run this program
7594
04:19:17,455 --> 04:19:18,895
you'll see it out here it says
7595
04:19:18,925 --> 04:19:20,215
the chef makes chicken
7596
04:19:20,635 --> 04:19:24,085
and that's because I inherited the make chicken method
7597
04:19:24,115 --> 04:19:24,655
from
7598
04:19:24,686 --> 04:19:25,586
the chef class
7599
04:19:26,156 --> 04:19:27,896
but here's one thing
7600
04:19:27,927 --> 04:19:28,377
that
7601
04:19:28,407 --> 04:19:29,247
got my stuff
7602
04:19:29,307 --> 04:19:31,107
if I come over here and I say make
7603
04:19:31,138 --> 04:19:32,428
special dish.
7604
04:19:32,788 --> 04:19:34,169
remember the chinese chef
7605
04:19:34,319 --> 04:19:36,659
special dish was supposed to be orange chicken.
7606
04:19:37,079 --> 04:19:37,739
but now
7607
04:19:37,770 --> 04:19:40,620
the chinese chef is going to be making barbecue ribs
7608
04:19:40,650 --> 04:19:41,460
because
7609
04:19:41,790 --> 04:19:42,990
I inherited
7610
04:19:43,200 --> 04:19:44,850
this makes special dish
7611
04:19:44,909 --> 04:19:45,600
function
7612
04:19:45,840 --> 04:19:46,500
from this
7613
04:19:46,530 --> 04:19:47,400
chef class
7614
04:19:47,641 --> 04:19:50,400
is what I can actually do is I could come in here and I could
7615
04:19:50,490 --> 04:19:51,660
override
7616
04:19:52,050 --> 04:19:52,710
that
7617
04:19:52,770 --> 04:19:53,880
make special dishcloth
7618
04:19:53,910 --> 04:19:54,510
so I could say
7619
04:19:54,540 --> 04:19:55,050
death
7620
04:19:55,290 --> 04:19:55,950
make
7621
04:19:56,400 --> 04:19:57,510
special dish.
7622
04:19:58,410 --> 04:19:59,340
and down here
7623
04:19:59,460 --> 04:19:59,851
I can just
7624
04:19:59,881 --> 04:20:01,472
override it so I could say,
7625
04:20:02,071 --> 04:20:02,762
the chef
7626
04:20:02,821 --> 04:20:03,781
makes
7627
04:20:04,472 --> 04:20:05,012
orange
7628
04:20:05,042 --> 04:20:05,522
chicken
7629
04:20:06,362 --> 04:20:07,442
and now
7630
04:20:07,473 --> 04:20:09,542
when I go over here and I run
7631
04:20:09,572 --> 04:20:10,172
this
7632
04:20:10,202 --> 04:20:11,282
make special dish
7633
04:20:11,312 --> 04:20:11,883
function.
7634
04:20:12,423 --> 04:20:13,863
now the chefs are going to be
7635
04:20:13,894 --> 04:20:16,982
back to making orange chicken so the chinese chef will make his
7636
04:20:17,013 --> 04:20:18,003
special dish.
7637
04:20:18,272 --> 04:20:18,962
so that's
7638
04:20:19,172 --> 04:20:21,992
basically what inheritance does it allows me to inherit
7639
04:20:22,322 --> 04:20:26,013
functionality from an existing class into the new class.
7640
04:20:26,522 --> 04:20:27,062
and
7641
04:20:27,452 --> 04:20:32,404
I can actually just inherit all of it without having to write it out so I didn't have to write out
7642
04:20:32,494 --> 04:20:32,854
make
7643
04:20:32,885 --> 04:20:35,675
chicken and make solid inside the chinese class,
7644
04:20:36,035 --> 04:20:36,516
but
7645
04:20:36,785 --> 04:20:37,775
the chinese chef
7646
04:20:37,806 --> 04:20:38,916
can still make
7647
04:20:38,946 --> 04:20:42,576
chicken and salad because it inherited that functionality from the chef class
7648
04:20:46,296 --> 04:20:48,696
in this tutorial I wanna talk to you guys about the
7649
04:20:48,727 --> 04:20:50,376
python interpreter.
7650
04:20:50,676 --> 04:20:56,977
the python interpreter is basically a little environment that we can use to execute python
7651
04:20:57,007 --> 04:20:57,727
commands.
7652
04:20:58,057 --> 04:21:03,098
so it's kind of like this little sandbox environment where we can test out and try out different
7653
04:21:03,157 --> 04:21:05,828
python commands are different python functions
7654
04:21:06,278 --> 04:21:08,768
in a very safe and neutral environment.
7655
04:21:08,888 --> 04:21:13,418
so it's kind of like a quick and dirty way to write python and try different things out.
7656
04:21:13,718 --> 04:21:16,477
the way we use the python interpreter is by opening up
7657
04:21:16,507 --> 04:21:18,547
opening up our command prompt.
7658
04:21:18,937 --> 04:21:22,536
now if you're on windows there's a program called command prompt
7659
04:21:22,566 --> 04:21:24,576
if you're on mac there's a program called
7660
04:21:24,636 --> 04:21:25,266
terminal.
7661
04:21:25,596 --> 04:21:27,246
basically you need to open
7662
04:21:27,276 --> 04:21:30,365
that program in order to use the python interpreter,
7663
04:21:30,726 --> 04:21:31,956
so I'm here on a mac
7664
04:21:31,986 --> 04:21:33,518
but if you're on a window as you can
7665
04:21:33,577 --> 04:21:35,497
essentially do exactly what I'm doing just
7666
04:21:35,527 --> 04:21:37,237
inside of the command prompt.
7667
04:21:37,598 --> 04:21:40,058
so on mac here I'm just going to search for
7668
04:21:40,237 --> 04:21:41,138
my terminal.
7669
04:21:41,527 --> 04:21:46,326
if you're on windows you can just search for like cmd or command prompt in it should pop up,
7670
04:21:46,807 --> 04:21:48,457
so the terminal is
7671
04:21:49,147 --> 04:21:51,037
basically an environment
7672
04:21:51,097 --> 04:21:52,626
on our computer where we can
7673
04:21:52,656 --> 04:21:55,086
interact with the computer and do different things
7674
04:21:55,355 --> 04:21:59,978
without a graphical user interface so normally when we interact with the computer
7675
04:22:00,338 --> 04:22:05,857
we're using things like buttons or you know windows and you know what we can move stuff around we can
7676
04:22:05,888 --> 04:22:07,269
you know basically just like
7677
04:22:07,448 --> 04:22:08,889
interact with the computer.
7678
04:22:09,219 --> 04:22:10,269
with graphics
7679
04:22:10,479 --> 04:22:12,548
with the terminal or the command prompt
7680
04:22:12,607 --> 04:22:16,087
is a place where you can interact with the computer using text commands.
7681
04:22:16,387 --> 04:22:18,007
so you know am I going to get too much into
7682
04:22:18,037 --> 04:22:21,396
what the terminal the command prompt dog but that's essentially what it is.
7683
04:22:21,816 --> 04:22:23,227
so inside of here,
7684
04:22:23,977 --> 04:22:26,228
we can use the python interpreter
7685
04:22:26,588 --> 04:22:30,009
and the python interpreter is basically just a little program
7686
04:22:30,039 --> 04:22:31,508
that like I said and we can write
7687
04:22:31,538 --> 04:22:32,858
you know sort of python
7688
04:22:32,889 --> 04:22:33,158
in
7689
04:22:33,188 --> 04:22:34,059
so generally,
7690
04:22:34,299 --> 04:22:37,029
all you have to do is go over to your terminal or your command prompt
7691
04:22:37,299 --> 04:22:38,380
and type in
7692
04:22:38,710 --> 04:22:39,520
python
7693
04:22:39,550 --> 04:22:40,330
three
7694
04:22:40,570 --> 04:22:43,630
and since we're using python three on monotype python three.
7695
04:22:44,350 --> 04:22:48,519
but you can also just like normal python and I'm pretty sure that gives you python two.
7696
04:22:49,089 --> 04:22:50,739
now here's a quick disclaimer.
7697
04:22:50,799 --> 04:22:51,309
I'm
7698
04:22:51,549 --> 04:22:52,659
on windows,
7699
04:22:53,020 --> 04:22:55,028
you may run into a problem
7700
04:22:55,059 --> 04:22:55,539
where
7701
04:22:55,569 --> 04:22:58,059
you can't use this python three command,
7702
04:22:58,299 --> 04:22:59,919
and it's possible that
7703
04:22:59,949 --> 04:23:01,271
if you're running into that problem
7704
04:23:01,301 --> 04:23:02,201
python
7705
04:23:02,921 --> 04:23:06,280
python three hasn't been added to your windows
7706
04:23:06,370 --> 04:23:07,510
path variable.
7707
04:23:08,080 --> 04:23:11,919
and basically what that means is your computer doesn't recognize the command
7708
04:23:11,949 --> 04:23:12,970
python three
7709
04:23:13,239 --> 04:23:14,050
and that's the case
7710
04:23:14,080 --> 04:23:16,239
all you have to do is just go and google
7711
04:23:16,270 --> 04:23:19,269
how to add python three to your windows path variable.
7712
04:23:19,419 --> 04:23:22,390
it's really easy I'm not going to get into it in this video just because it's kind of
7713
04:23:22,420 --> 04:23:23,350
outside the scope
7714
04:23:23,380 --> 04:23:23,710
but
7715
04:23:24,040 --> 04:23:25,271
if you're running into that problem.
7716
04:23:25,330 --> 04:23:27,880
that's probably it's not on your windows
7717
04:23:27,910 --> 04:23:31,271
path variables such as google around for that and you should be able to find an answer,
7718
04:23:31,721 --> 04:23:34,211
but onsite python three and then click enter
7719
04:23:34,241 --> 04:23:37,150
and it's going to open up this cool thing down here so
7720
04:23:37,721 --> 04:23:40,900
you can see it basically just says like here's the version of python.
7721
04:23:41,290 --> 04:23:41,740
now
7722
04:23:41,830 --> 04:23:41,980
I'm
7723
04:23:42,011 --> 04:23:44,169
going to enter so we can have some like
7724
04:23:44,229 --> 04:23:45,399
new lines here
7725
04:23:45,789 --> 04:23:46,270
and
7726
04:23:47,079 --> 04:23:50,077
put down here this is the python interpreter so we can write
7727
04:23:50,497 --> 04:23:53,107
python code in here and it's going to work so I could
7728
04:23:53,287 --> 04:23:54,547
for example I could write like
7729
04:23:54,697 --> 04:23:55,207
print
7730
04:23:55,627 --> 04:23:57,186
and inside of here I could print like
7731
04:23:57,365 --> 04:23:58,445
hello world.
7732
04:23:59,165 --> 04:23:59,705
and
7733
04:23:59,915 --> 04:24:00,725
when I click enter
7734
04:24:00,755 --> 04:24:01,836
you'll see that it prints out
7735
04:24:01,866 --> 04:24:02,616
hello world.
7736
04:24:02,826 --> 04:24:06,186
I could create a variable so for example I can say like number one
7737
04:24:06,455 --> 04:24:07,596
is equal to ten.
7738
04:24:07,865 --> 04:24:10,475
I can say numb two is equal to ninety.
7739
04:24:10,774 --> 04:24:11,645
and then I could print
7740
04:24:11,675 --> 04:24:13,115
out number one
7741
04:24:13,146 --> 04:24:13,806
plus
7742
04:24:13,865 --> 04:24:14,735
none too
7743
04:24:15,245 --> 04:24:16,864
and it's going to be able to do that for me ?
7744
04:24:17,044 --> 04:24:21,093
I could also use awesome like a function so I can define a function in here,
7745
04:24:21,513 --> 04:24:26,431
we can make a function that is called say hi and it'll take a name parameter.
7746
04:24:27,751 --> 04:24:28,351
and
7747
04:24:28,410 --> 04:24:31,381
you'll see here when it saw I wanted to create a functional
7748
04:24:31,411 --> 04:24:33,301
put these three little dots
7749
04:24:33,331 --> 04:24:37,290
and I can index in and we can write the code for a function so I can say like
7750
04:24:37,320 --> 04:24:37,860
print
7751
04:24:39,181 --> 04:24:40,051
hello
7752
04:24:42,150 --> 04:24:43,410
last name.
7753
04:24:45,090 --> 04:24:47,250
and now I have a function called
7754
04:24:47,280 --> 04:24:50,521
say hi so I can break out of this by this entering again
7755
04:24:50,820 --> 04:24:52,770
and I would call the function so I could
7756
04:24:52,920 --> 04:24:53,550
say
7757
04:24:53,580 --> 04:24:54,300
say
7758
04:24:54,660 --> 04:24:55,200
hi
7759
04:24:55,230 --> 04:24:56,280
and we'll say out of me.
7760
04:24:57,420 --> 04:24:58,079
I'm like
7761
04:24:58,109 --> 04:24:59,189
so now it's going to say
7762
04:24:59,220 --> 04:24:59,909
hello mike
7763
04:25:00,149 --> 04:25:02,159
so I can use a function I could use something like an
7764
04:25:02,189 --> 04:25:02,880
if statement
7765
04:25:02,910 --> 04:25:03,420
you know
7766
04:25:03,720 --> 04:25:04,500
I could say,
7767
04:25:05,460 --> 04:25:07,920
I can easily afford the wicked use while loose.
7768
04:25:08,340 --> 04:25:12,929
I mean we can basically use all of the basic like python commands and you know
7769
04:25:12,959 --> 04:25:15,689
inside of this python interpreter and like I said before.
7770
04:25:16,050 --> 04:25:18,300
it's essentially just an environment where you can test
7771
04:25:18,330 --> 04:25:18,780
out
7772
04:25:18,960 --> 04:25:19,800
python code.
7773
04:25:20,100 --> 04:25:22,561
now this is not a place where you want to write
7774
04:25:22,650 --> 04:25:24,601
like any serious python
7775
04:25:24,690 --> 04:25:25,471
scripts
7776
04:25:25,501 --> 04:25:28,229
so if you're like designing and writing a python program
7777
04:25:28,260 --> 04:25:29,550
I would not recommend
7778
04:25:29,580 --> 04:25:31,230
doing it inside of this interpreter ?
7779
04:25:31,410 --> 04:25:31,830
it is,
7780
04:25:32,040 --> 04:25:37,079
it's not a very intuitive environment it's pretty much just set up for some quick and dirty tests
7781
04:25:37,259 --> 04:25:40,287
we need to test somethin' out great this is a perfect place for it.
7782
04:25:40,587 --> 04:25:42,086
you'll have to set up a file
7783
04:25:42,416 --> 04:25:43,526
you'll have to use like some
7784
04:25:43,557 --> 04:25:47,607
id you don't have to execute a filing is going here it's quick it's dirty,
7785
04:25:47,667 --> 04:25:48,356
you get it done.
7786
04:25:48,776 --> 04:25:50,816
but if you're writing an actual program.
7787
04:25:50,876 --> 04:25:53,485
you definitely definitely definitely want to use
7788
04:25:53,516 --> 04:25:53,815
a
7789
04:25:53,846 --> 04:25:54,746
text editor.
7790
04:25:55,256 --> 04:26:03,655
the text editor is just going to be way more organized everything is going to be a lot cleaner and you're not going to get confused with like where stuff is and what you have so
7791
04:26:04,136 --> 04:26:06,176
that's the basics of the python interpreter,
7792
04:26:06,266 --> 04:26:07,796
you know in the course I
7793
04:26:07,855 --> 04:26:09,655
havent really been using it at all,
7794
04:26:09,896 --> 04:26:13,375
just because I think it's a lot easier to teach when we're inside of a file,
7795
04:26:13,525 --> 04:26:15,055
then inside of here but
7796
04:26:15,085 --> 04:26:15,445
you know
7797
04:26:15,476 --> 04:26:16,734
don't count this guy out
7798
04:26:16,765 --> 04:26:21,085
the python interpreter is awesome a lot of people who use it and it's great if you just need a task
7799
04:26:21,115 --> 04:26:23,846
you know little bits of code out without having to set up some
7800
04:26:23,876 --> 04:26:25,346
huge environment so
7801
04:26:25,796 --> 04:26:26,605
python interpreter
7802
04:26:26,636 --> 04:26:29,547
definitely awesome out player out there you know have some fun
7803
04:26:29,727 --> 04:26:30,837
and take advantage of it.
7804
04:26:31,407 --> 04:26:34,436
hey things are washing if you enjoy the video please leave alike answered
7805
04:26:34,466 --> 04:26:37,377
garbage off academy to be the first snow and release new content
7806
04:26:37,947 --> 04:26:40,768
also were always going to improve so if you have any
7807
04:26:40,798 --> 04:26:43,828
constructive criticism or questions or anything leave a common below
7808
04:26:44,128 --> 04:26:46,887
finally if you're enjoying job academy and you want to help us grow
7809
04:26:47,037 --> 04:26:51,114
head over to draft academy dotcom ford sauce contribute and invest in our future.
534555
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.