Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
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
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
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
Samoan
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
1
To begin,
2
I want you to locate the day 1.2 debugging exercise.
3
And now, as you did before, go ahead and read through the instructions.
4
Be mindful that the output must match the example output precisely.
5
And when you hit run, this is the outcome you're looking for.
6
So there's quite a few things broken here,
7
but I want you to have a go at fixing each line individually and pulling out the
8
bugs from the code. So pause the video now and give that a go.
9
All right.
10
So how did that go? If you haven't got your computer in front of you,
11
if you're traveling, if somehow you can't access the exercise, just pause
12
and when you've got time,
13
then complete the challenge and then come back to the course.
14
It is so important that you actually do some hands-on stuff.
15
And I stress that this is the only way that you are going to become the rock
16
star coder that I know you can be. Let's take a look at the code below.
17
You can see that when we run our code as it is right now,
18
we get a new error.
19
And this is going to point to the first of many errors in this file.
20
And in this case, it tells us that on line three,
21
so this one right here, at around this position
22
or somewhere around here, um, as denoted by the little caret sign,
23
there is a syntax error. If we study this closely,
24
you can see that the code highlighting seems to be suggesting that all of this
25
is code, but this is somehow text. So what's going on here?
26
Well, notice that we've only got one double quote.
27
So it thinks that what comes after this is the text,
28
but what comes before it, it thought it was just a continuation of code.
29
So to fix this one,
30
all we have to do is add a double quote right here. That changes the text to the
31
color that we're used to and this fixes this line.
32
So if we run our code now, we should get a different error. And indeed we do.
33
The next one tells us that on line five,
34
so this one right here, there is an indentation error.
35
There's an unexpected indent somewhere around here on line five.
36
So let's take a look at line five and there you go.
37
There's a little bit of extra space between the print and the beginning of the
38
line.
39
So now that we've fixed that one, let's click run. And it will point to
40
another line of code that's broken. And in this case,
41
it says on line seven,
42
which is here where there's actually no code,
43
there's the unexpected EOF while parsing. What does this mean?
44
Well, if you're not sure,
45
then go ahead and paste it into Google and let's take a look at what people say
46
on Stack Overflow. So as this person,
47
very kind, Felix, um, has explained, this index error
48
unexpected EOF
49
while parsing means that the end of your source code was reached before all
50
code blocks were completed. What is a code block? Well,
51
this is a code block because it's a print function,
52
it has a beginning and it has an end. But what does this line not have?
53
Well, it's got two open parentheses,
54
but only one closing parentheses.
55
So the computer thinks that you are going to continue writing something and then
56
close it off at the end, which is not the case. In fact,
57
what has happened is we simply have an extra misplaced open parenthesis.
58
And now if we delete that and hit run,
59
you'll see that we have everything printed.
60
But at this point, notice how on line four
61
which is the line that we haven't fixed yet,
62
it prints string concatenation is done with the 'blank' sign.
63
Whereas in fact, it should say plus sign.
64
And even though we don't see any errors being printed in our console,
65
you'll see that we have an output mismatch because I'm expecting to see this
66
line, the String Concatenation is done with the "+" sign,
67
but here,
68
the output doesn't have that part. It's missing this part.
69
So there's one last thing that you need to debug. And that is of course,
70
on line four.
71
And what's happening here is we have this part being interpreted as a string,
72
this part being interpreted a string,
73
and it thinks that this plus sign is just us concatenating
74
these two parts together,
75
which is why it printed out like this. But in fact,
76
we wanted to print out is this as text down here.
77
So what we have to do is to change this outer apart from double quotes
78
into single quotes.
79
And now you can see when it highlights this part,
80
it's all the same color including the plus sign.
81
Now it sees this as a complete string,
82
and it's not looking at this as if it's code. So now if we run our program,
83
you can see the entire sentence being printed out.
84
So if you've completed the challenge and you've gotten everything right,
85
then you're now done with this exercise.
86
If you got stuck and you want to have a look at the solution, as always it's down
87
here,
88
and it might be useful to have a look at this page to see where you might've
89
missed something or where you might've gotten something wrong.
90
So I hope you enjoyed this code exercise. In the next lesson,
91
we're going to learn about a new type of Python function,
92
which is the input function. So for all of that and more, I'll see you there.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.