Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:08,821 --> 00:00:11,328
In this course,
you're going to learn to write computer
2
00:00:11,328 --> 00:00:14,130
programs in the Python
programming language.
3
00:00:14,130 --> 00:00:18,420
But before we get into that, we need
to know exactly what programming is.
4
00:00:18,420 --> 00:00:21,620
Fundamentally, programming is
giving a list of instructions for
5
00:00:21,620 --> 00:00:23,420
a computer to follow.
6
00:00:23,420 --> 00:00:24,920
In the contest of programming,
7
00:00:24,920 --> 00:00:28,010
this instructions are sometimes
called algorithms.
8
00:00:28,010 --> 00:00:32,140
Now computers are really good in following
this instructions very reliably and
9
00:00:32,140 --> 00:00:34,650
very quickly but not very creatively.
10
00:00:35,970 --> 00:00:39,520
And we can't just give computers
instructions in English or any other
11
00:00:39,520 --> 00:00:44,610
natural language that we normally speak
because natural language has ambiguity.
12
00:00:44,610 --> 00:00:49,490
Words or sentences can have multiple
meanings which computers can't figure out.
13
00:00:49,490 --> 00:00:52,960
Instead we need to give computers
instructions in a programming language,
14
00:00:52,960 --> 00:00:55,600
which is a kind of language
that computers can understand
15
00:00:55,600 --> 00:00:58,480
because they have a formal syntax or
set of rules.
16
00:00:59,520 --> 00:01:04,420
There are many programming languages that
exist including JavaScript, C++ Java,
17
00:01:04,420 --> 00:01:06,570
Haskell and many many more.
18
00:01:06,570 --> 00:01:09,890
But in this course we're going to learn
to use the Python programming language.
19
00:01:11,380 --> 00:01:14,520
The process of learning programming is
more than just learning the rules of
20
00:01:14,520 --> 00:01:16,350
the Python programming language.
21
00:01:16,350 --> 00:01:18,170
It's also about how to breakdown and
22
00:01:18,170 --> 00:01:21,190
solve problems regardless of
the programming language.
23
00:01:21,190 --> 00:01:24,690
And I like to think of programming as a
translation process, where the programmer
24
00:01:24,690 --> 00:01:29,350
translates their goals from natural
language into a programming language.
25
00:01:29,350 --> 00:01:30,140
For example,
26
00:01:30,140 --> 00:01:33,760
if I want to write my own version of
the game Wheel of Fortune, then I need to
27
00:01:33,760 --> 00:01:38,270
translate the rules of the game into an
unambiguous set of instructions written in
28
00:01:38,270 --> 00:01:41,849
the Python programming language that
tell the computer how to run the game.
29
00:01:42,960 --> 00:01:46,990
And as you become a programmer, you'll
learn how to come up with strategies, or
30
00:01:46,990 --> 00:01:50,980
algorithms, for solving problems in
how to translate these strategies
31
00:01:50,980 --> 00:01:53,590
in the Python code that
a computer can execute.
32
00:01:54,590 --> 00:01:58,740
Now, all that said, the best way to learn
programming is through practice, so
33
00:01:58,740 --> 00:01:59,660
let's get started.
34
00:02:00,980 --> 00:02:04,100
In this course, you'll be able to write
Python codes right in your browser.
35
00:02:05,150 --> 00:02:07,730
You'll see what are called
active code windows
36
00:02:07,730 --> 00:02:09,630
that look like this in your textbook.
37
00:02:10,810 --> 00:02:14,960
Now, most programming courses start off
with what's called a Hello World program
38
00:02:14,960 --> 00:02:17,990
or a program that prints out Hello World
on the screen when you run it.
39
00:02:19,000 --> 00:02:22,380
In Python, a program to print
Hello World looks like this.
40
00:02:23,900 --> 00:02:28,360
In order to actually run this code,
we need to click the Save & Run button.
41
00:02:28,360 --> 00:02:32,100
When we do that, we'll see an output
window show up to the right here.
42
00:02:33,250 --> 00:02:35,853
Now to break down what all of this shows,
43
00:02:35,853 --> 00:02:38,619
we have our Python
source code on the left.
44
00:02:44,428 --> 00:02:47,401
And we have our output on the right.
45
00:02:53,647 --> 00:02:58,149
Now, when we click Save & Run what
happens is that there's a hidden Python
46
00:02:58,149 --> 00:02:59,084
interpreter.
47
00:03:08,623 --> 00:03:11,832
And it looks at what's in our source code,
and
48
00:03:11,832 --> 00:03:14,970
prints out whatever any
relevant output is.
49
00:03:16,030 --> 00:03:19,250
And remember that this source
code is a set of instructions.
50
00:03:19,250 --> 00:03:23,080
In this case, the source code
is an instruction to print out
51
00:03:23,080 --> 00:03:26,800
whatever is in quotation marks here,
in this case, Hello World.
52
00:03:28,580 --> 00:03:31,390
If we wanted to change the set
of instructions, so for
53
00:03:31,390 --> 00:03:35,170
example, I want to change it to print out,
Hello Michigan.
54
00:03:37,400 --> 00:03:42,860
Then I need to put it through the
interpreter by clicking Save & Run again,
55
00:03:42,860 --> 00:03:43,850
and now when I do that,
56
00:03:43,850 --> 00:03:47,660
you'll see that my output changed
from Hello World, to Hello Michigan.
57
00:03:49,260 --> 00:03:55,033
If I want to change it back,
Then I need to click Save & Run.
58
00:03:58,124 --> 00:04:01,699
Now, the Python interpreter typically
tries to run all of the source
59
00:04:01,699 --> 00:04:03,890
code that we put in this window.
60
00:04:03,890 --> 00:04:08,300
But it can sometimes be helpful to leave
natural language notes or explanations for
61
00:04:08,300 --> 00:04:11,490
ourselves or for other programmers
who are looking at the source code.
62
00:04:12,590 --> 00:04:15,740
Now the Python interpreter
typically tries to run
63
00:04:15,740 --> 00:04:19,270
all of the source code that we put
into our source code window, but
64
00:04:19,270 --> 00:04:23,100
sometimes it can be helpful to leave
natural language notes or explanations for
65
00:04:23,100 --> 00:04:26,060
ourselves or for other programmers
looking at the source code.
66
00:04:27,100 --> 00:04:29,619
In order to do that,
we have what are called comments.
67
00:04:30,780 --> 00:04:34,879
In Python, we write a comment
by using the # symbol and
68
00:04:34,879 --> 00:04:37,205
writing what we want after it.
69
00:04:39,430 --> 00:04:43,662
When we write a comment, then Python
ignores everything that comes after the #
70
00:04:43,662 --> 00:04:46,767
symbol, meaning that we can
write whatever we want here.
71
00:04:50,063 --> 00:04:54,320
And on the next line,
Python will start running the code again.
72
00:04:54,320 --> 00:04:59,409
So if we wanted to write a comment,
we would need to add a # symbol.
73
00:05:05,396 --> 00:05:10,582
And what comments do are they tell
the Python interpreter to ignore
74
00:05:10,582 --> 00:05:16,430
these portions of the source code,
and only to run what's not commented.
75
00:05:18,140 --> 00:05:22,800
In our case, the only code that actually
runs here is print Hello World.
76
00:05:24,580 --> 00:05:28,220
Another thing that's worth noting is
that the Python interpreter is not very
77
00:05:28,220 --> 00:05:29,390
forgiving.
78
00:05:29,390 --> 00:05:33,350
So recall that when you write source code,
you're giving the computer a set of
79
00:05:33,350 --> 00:05:36,780
instructions, and
these instructions need to be unambiguous,
80
00:05:36,780 --> 00:05:40,650
they need to follow the rules of
the Python programming language.
81
00:05:40,650 --> 00:05:44,650
One of the rules of Python is that
when we have an open parenthesis,
82
00:05:44,650 --> 00:05:48,550
then we are going to need to
have a closed parenthesis.
83
00:05:48,550 --> 00:05:51,470
So, let's suppose that
I forget that rule and
84
00:05:51,470 --> 00:05:54,800
I delete this closed parenthesis,
and I try to run my program.
85
00:05:56,040 --> 00:05:59,948
What happens is that I get
what's called a syntax error.
86
00:05:59,948 --> 00:06:04,920
A syntax error is Python saying that it
doesn't understand the rules of what you
87
00:06:04,920 --> 00:06:10,960
wrote, so it doesn't try to actually
execute what's in the source code window.
88
00:06:10,960 --> 00:06:15,630
In other words, a syntactic error or
a syntax error is when
89
00:06:15,630 --> 00:06:19,080
you are not following the rules of
the of the Python programming language.
90
00:06:19,080 --> 00:06:23,260
In this case, we are not following
the rule that this open parenthesis
91
00:06:23,260 --> 00:06:25,410
has to be followed by
a closed parenthesis.
92
00:06:26,440 --> 00:06:29,613
Throughout this course,
we're going to run into syntax errors and
93
00:06:29,613 --> 00:06:33,023
other kinds of errors, including run
time errors and semantic errors.
94
00:06:35,290 --> 00:06:39,012
So when we get a syntax error, as we
will many times throughout this course,
95
00:06:39,012 --> 00:06:42,325
we can fix it by editing the source
code to obey the syntactic rules of
96
00:06:42,325 --> 00:06:44,530
the Python programming language.
97
00:06:44,530 --> 00:06:47,210
In this case,
I'm going to add a close parenthesis
98
00:06:47,210 --> 00:06:50,290
to match the opening parenthesis
that starts out here.
99
00:06:51,520 --> 00:06:53,360
Now when I click Save & Run again,
100
00:06:53,360 --> 00:06:58,400
then you'll see that the syntax error
disappears and my program runs again.
101
00:06:58,400 --> 00:07:01,660
With that, you're already on your
way to becoming a programmer.
102
00:07:01,660 --> 00:07:04,840
With more practice, you'll better
understand how the Python interpreter
103
00:07:04,840 --> 00:07:09,270
works, and will be able to write larger,
and more complex programs.
104
00:07:09,270 --> 00:07:09,900
See you next time.9745
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.