1
00:00:01,200 --> 00:00:03,780
The goal of this exercise is to practice

2
00:00:03,780 --> 00:00:08,250
what you have learned about the print() statement in Python.

3
00:00:08,250 --> 00:00:09,720
So using what you know,

4
00:00:09,720 --> 00:00:13,020
including the syntax of the print() statement,

5
00:00:13,020 --> 00:00:15,210
which symbols you need to type

6
00:00:15,210 --> 00:00:18,030
in order to print out each of these lines,

7
00:00:18,030 --> 00:00:22,230
try and figure out if you can modify the code, add to it,

8
00:00:22,230 --> 00:00:24,120
and when you hit RUN,

9
00:00:24,120 --> 00:00:27,750
each of these five lines should be printed out separately

10
00:00:27,750 --> 00:00:31,200
into the Output area at the bottom.

11
00:00:31,200 --> 00:00:33,570
So try and figure out if you can do this

12
00:00:33,570 --> 00:00:36,300
and take a look at the Instructions pane

13
00:00:36,300 --> 00:00:39,810
to help you and guide you through this exercise.

14
00:00:39,810 --> 00:00:42,630
Once you're confident that your code is doing exactly

15
00:00:42,630 --> 00:00:43,920
what it's meant to do,

16
00:00:43,920 --> 00:00:47,550
hit SUBMIT and test your code against the test cases

17
00:00:47,550 --> 00:00:49,680
that we have prepared for you.

18
00:00:49,680 --> 00:00:54,330
Now it's really important that you print out

19
00:00:54,330 --> 00:00:57,540
exactly word for word, letter for letter,

20
00:00:57,540 --> 00:01:00,120
what we have in the example outputs,

21
00:01:00,120 --> 00:01:03,660
no extra spaces, no extra full stops,

22
00:01:03,660 --> 00:01:05,129
just be really, really careful

23
00:01:05,129 --> 00:01:08,760
because the match has to go through exactly.

24
00:01:08,760 --> 00:01:10,590
It has to be precisely the same.

25
00:01:10,590 --> 00:01:12,963
So just be careful with that, and have a go.

26
00:01:14,640 --> 00:01:15,960
All right, so on this slide,

27
00:01:15,960 --> 00:01:18,810
I want to go through the code solution with you.

28
00:01:18,810 --> 00:01:22,830
And this is a read-only code base,

29
00:01:22,830 --> 00:01:25,380
so you can't change it, you can't touch it,

30
00:01:25,380 --> 00:01:28,920
but it does show you exactly what you need to type

31
00:01:28,920 --> 00:01:31,980
or to change to the previous exercise

32
00:01:31,980 --> 00:01:34,920
in order for it to pass all of the tests.

33
00:01:34,920 --> 00:01:36,960
Now in this case, we want to print out

34
00:01:36,960 --> 00:01:40,410
five of these statements each on their own line.

35
00:01:40,410 --> 00:01:43,290
So we need five different print() statements.

36
00:01:43,290 --> 00:01:46,260
And the print() statements syntax is very simple.

37
00:01:46,260 --> 00:01:48,180
We use the keyword "print"

38
00:01:48,180 --> 00:01:50,310
to tell the computer our intention,

39
00:01:50,310 --> 00:01:53,340
we want to print something into the Output area.

40
00:01:53,340 --> 00:01:55,710
And then we define what we want to print

41
00:01:55,710 --> 00:01:58,560
inside a set of parentheses,

42
00:01:58,560 --> 00:02:02,310
which is also known as these round brackets ().

43
00:02:02,310 --> 00:02:04,200
Now, inside the round brackets,

44
00:02:04,200 --> 00:02:06,750
we can define what it is we want to print,

45
00:02:06,750 --> 00:02:08,910
and in this case, we want to print text.

46
00:02:08,910 --> 00:02:12,330
So we've put the text in between a set of double quotes

47
00:02:12,330 --> 00:02:14,340
to tell the computer this,

48
00:02:14,340 --> 00:02:16,560
even though it's written in a similar way,

49
00:02:16,560 --> 00:02:19,740
like you might see code, this is not code

50
00:02:19,740 --> 00:02:23,040
and it doesn't have any actions for you to do,

51
00:02:23,040 --> 00:02:25,830
instead, it's just text that I want to print

52
00:02:25,830 --> 00:02:27,540
into the Output area.

53
00:02:27,540 --> 00:02:30,780
So now when the computer reads this file from top to bottom,

54
00:02:30,780 --> 00:02:33,900
from left to right, it knows exactly what it needs to do,

55
00:02:33,900 --> 00:02:35,850
and in fact, if you hit RUN CODE,

56
00:02:35,850 --> 00:02:38,400
you'll see all five of these statements print out

57
00:02:38,400 --> 00:02:41,340
one by one, each on their own line.

58
00:02:41,340 --> 00:02:44,550
Now, if you had any issues passing the previous test,

59
00:02:44,550 --> 00:02:47,310
make sure that you don't have any extra spaces,

60
00:02:47,310 --> 00:02:52,310
extra symbols, anything is going to change the result there.

61
00:02:52,470 --> 00:02:56,370
And if in doubt, at the end, you can also just copy

62
00:02:56,370 --> 00:02:58,680
this entire five lines of code,

63
00:02:58,680 --> 00:03:00,510
paste it into the previous slide

64
00:03:00,510 --> 00:03:02,700
and see if it passes all the tests,

65
00:03:02,700 --> 00:03:06,873
and maybe you'll figure out what the issue is that you had.

66
00:03:08,820 --> 00:03:11,610
Now, in addition to the basic print() statements

67
00:03:11,610 --> 00:03:13,110
that you saw before,

68
00:03:13,110 --> 00:03:16,470
you can also add some modifiers to our text

69
00:03:16,470 --> 00:03:19,293
in order to achieve a specific need.

70
00:03:20,580 --> 00:03:24,570
So for example, in this case, in the first print() statement,

71
00:03:24,570 --> 00:03:26,850
we want to have some double quotes

72
00:03:26,850 --> 00:03:30,450
around an actual quotation,

73
00:03:30,450 --> 00:03:31,980
so the word "Hello".

74
00:03:31,980 --> 00:03:35,640
But notice the color coding here.

75
00:03:35,640 --> 00:03:39,780
Because the computer reads from left to right,

76
00:03:39,780 --> 00:03:41,880
when it sees the first double quote,

77
00:03:41,880 --> 00:03:45,480
it thinks, "Uh, this is the beginning of text,"

78
00:03:45,480 --> 00:03:48,180
and then it sees the second double quote

79
00:03:48,180 --> 00:03:50,010
at the beginning of the word "Hello"

80
00:03:50,010 --> 00:03:55,010
and it thinks, erroneously, that that is the end of the text.

81
00:03:55,290 --> 00:03:57,240
So then what comes after the end of text?

82
00:03:57,240 --> 00:03:58,470
Well, it's code.

83
00:03:58,470 --> 00:04:00,450
Look at how the word "Hello"

84
00:04:00,450 --> 00:04:04,380
is highlighted in the same color as the keyword print,

85
00:04:04,380 --> 00:04:09,210
this computer thinks that the word "Hello" is a command,

86
00:04:09,210 --> 00:04:12,210
it's an action, but it's not.

87
00:04:12,210 --> 00:04:14,640
Instead, it's actually us trying to use

88
00:04:14,640 --> 00:04:17,220
the English language grammatical syntax

89
00:04:17,220 --> 00:04:19,200
to put the double quotes around something

90
00:04:19,200 --> 00:04:21,720
that has been spoken by someone.

91
00:04:21,720 --> 00:04:23,853
So how do you solve this?

92
00:04:25,140 --> 00:04:28,680
Well, a really simple way is to alternate the use

93
00:04:28,680 --> 00:04:30,780
of single and double quotes.

94
00:04:30,780 --> 00:04:33,810
In Python, we can define a piece of text,

95
00:04:33,810 --> 00:04:35,880
which is also known as a string,

96
00:04:35,880 --> 00:04:38,880
using either a single quote or a double quote.

97
00:04:38,880 --> 00:04:40,800
Depending on what it is that you need

98
00:04:40,800 --> 00:04:42,300
to have inside the string,

99
00:04:42,300 --> 00:04:44,820
for example, in this case, we want to use double quotes

100
00:04:44,820 --> 00:04:47,430
inside the text area,

101
00:04:47,430 --> 00:04:52,430
then we can instead use single quotes to define our text.

102
00:04:53,100 --> 00:04:55,980
So this way, because the single quote

103
00:04:55,980 --> 00:04:57,660
and double quote are different,

104
00:04:57,660 --> 00:05:01,650
the computer knows that this is the beginning of text

105
00:05:01,650 --> 00:05:03,510
from the word "She said",

106
00:05:03,510 --> 00:05:04,860
and then at the end,

107
00:05:04,860 --> 00:05:08,070
"then left." is the end of the entire string.

108
00:05:08,070 --> 00:05:08,903
And in the middle,

109
00:05:08,903 --> 00:05:11,760
we can have our English grammatical double quote.

110
00:05:11,760 --> 00:05:13,470
So just by alternating this,

111
00:05:13,470 --> 00:05:16,440
we can have either double quotes inside our text

112
00:05:16,440 --> 00:05:18,420
or single quotes inside our text

113
00:05:18,420 --> 00:05:22,140
by using a different type of symbol.

114
00:05:22,140 --> 00:05:23,850
Now, another alternative option

115
00:05:23,850 --> 00:05:26,010
that I want you to be aware of

116
00:05:26,010 --> 00:05:30,780
is the use of what's called an escape backslash.

117
00:05:30,780 --> 00:05:34,380
So this when you see here, it says, She said,

118
00:05:34,380 --> 00:05:36,090
and then we've got a colon,

119
00:05:36,090 --> 00:05:40,140
and then we have a backslash right before the double quote.

120
00:05:40,140 --> 00:05:42,540
So even though in this case we've got double quotes

121
00:05:42,540 --> 00:05:43,680
inside double quotes,

122
00:05:43,680 --> 00:05:46,170
which as we said in the beginning can be confusing

123
00:05:46,170 --> 00:05:49,530
for the computer to know what is text and what is code,

124
00:05:49,530 --> 00:05:51,990
but because we have the backslash (\)

125
00:05:51,990 --> 00:05:55,290
in front of the double quotes that we want to keep,

126
00:05:55,290 --> 00:06:00,270
then the computer knows to ignore this as code.

127
00:06:00,270 --> 00:06:03,240
So yes, the double quote can be used

128
00:06:03,240 --> 00:06:05,580
in English to denote speech,

129
00:06:05,580 --> 00:06:10,580
but also in programming, it's there to be placed around

130
00:06:11,010 --> 00:06:14,550
words to tell the computer that it is text.

131
00:06:14,550 --> 00:06:16,950
But in this case, we add the backslash

132
00:06:16,950 --> 00:06:20,700
in front of the double quotes in the middle of the sentence

133
00:06:20,700 --> 00:06:22,740
to tell the computer, "Ignore this.

134
00:06:22,740 --> 00:06:24,330
This is definitely not code.

135
00:06:24,330 --> 00:06:25,163
Don't worry about it.

136
00:06:25,163 --> 00:06:28,770
It is meant to be printed exactly as it is."

137
00:06:28,770 --> 00:06:30,780
So these are two of the ways

138
00:06:30,780 --> 00:06:33,360
that you can modify your print() statement

139
00:06:33,360 --> 00:06:36,330
if you want to add symbols

140
00:06:36,330 --> 00:06:39,453
that are used within the syntax of the print() statement.

141
00:06:40,350 --> 00:06:41,820
So you've heard the theory

142
00:06:41,820 --> 00:06:43,830
of how to modify print() statements,

143
00:06:43,830 --> 00:06:46,890
but now let's see it in practice.

144
00:06:46,890 --> 00:06:49,950
So here, I've got the three examples that I talked about

145
00:06:49,950 --> 00:06:53,100
where you can alternate single and double quotes,

146
00:06:53,100 --> 00:06:55,770
and you can also use the backslash

147
00:06:55,770 --> 00:06:59,460
in order to escape a particular symbol.

148
00:06:59,460 --> 00:07:04,020
So go ahead and run this code and see what it prints out,

149
00:07:04,020 --> 00:07:06,150
and then see if you can mess around with the code

150
00:07:06,150 --> 00:07:08,490
to make all of this knowledge your own

151
00:07:08,490 --> 00:07:11,310
so that you understand exactly what's going on

152
00:07:11,310 --> 00:07:14,580
and what I mean by all of the explanations

153
00:07:14,580 --> 00:07:17,040
that I gave in the previous slide.

154
00:07:17,040 --> 00:07:18,030
Play around with the code,

155
00:07:18,030 --> 00:07:19,530
you won't be able to break anything,

156
00:07:19,530 --> 00:07:21,660
just try it out and make sure you understand

157
00:07:21,660 --> 00:07:22,533
what's going on.

