The goal of this exercise is to practice
what you have learned about the print() statement in Python.
So using what you know,
including the syntax of the print() statement,
which symbols you need to type
in order to print out each of these lines,
try and figure out if you can modify the code, add to it,
and when you hit RUN,
each of these five lines should be printed out separately
into the Output area at the bottom.
So try and figure out if you can do this
and take a look at the Instructions pane
to help you and guide you through this exercise.
Once you're confident that your code is doing exactly
what it's meant to do,
hit SUBMIT and test your code against the test cases
that we have prepared for you.
Now it's really important that you print out
exactly word for word, letter for letter,
what we have in the example outputs,
no extra spaces, no extra full stops,
just be really, really careful
because the match has to go through exactly.
It has to be precisely the same.
So just be careful with that, and have a go.
All right, so on this slide,
I want to go through the code solution with you.
And this is a read-only code base,
so you can't change it, you can't touch it,
but it does show you exactly what you need to type
or to change to the previous exercise
in order for it to pass all of the tests.
Now in this case, we want to print out
five of these statements each on their own line.
So we need five different print() statements.
And the print() statements syntax is very simple.
We use the keyword "print"
to tell the computer our intention,
we want to print something into the Output area.
And then we define what we want to print
inside a set of parentheses,
which is also known as these round brackets ().
Now, inside the round brackets,
we can define what it is we want to print,
and in this case, we want to print text.
So we've put the text in between a set of double quotes
to tell the computer this,
even though it's written in a similar way,
like you might see code, this is not code
and it doesn't have any actions for you to do,
instead, it's just text that I want to print
into the Output area.
So now when the computer reads this file from top to bottom,
from left to right, it knows exactly what it needs to do,
and in fact, if you hit RUN CODE,
you'll see all five of these statements print out
one by one, each on their own line.
Now, if you had any issues passing the previous test,
make sure that you don't have any extra spaces,
extra symbols, anything is going to change the result there.
And if in doubt, at the end, you can also just copy
this entire five lines of code,
paste it into the previous slide
and see if it passes all the tests,
and maybe you'll figure out what the issue is that you had.
Now, in addition to the basic print() statements
that you saw before,
you can also add some modifiers to our text
in order to achieve a specific need.
So for example, in this case, in the first print() statement,
we want to have some double quotes
around an actual quotation,
so the word "Hello".
But notice the color coding here.
Because the computer reads from left to right,
when it sees the first double quote,
it thinks, "Uh, this is the beginning of text,"
and then it sees the second double quote
at the beginning of the word "Hello"
and it thinks, erroneously, that that is the end of the text.
So then what comes after the end of text?
Well, it's code.
Look at how the word "Hello"
is highlighted in the same color as the keyword print,
this computer thinks that the word "Hello" is a command,
it's an action, but it's not.
Instead, it's actually us trying to use
the English language grammatical syntax
to put the double quotes around something
that has been spoken by someone.
So how do you solve this?
Well, a really simple way is to alternate the use
of single and double quotes.
In Python, we can define a piece of text,
which is also known as a string,
using either a single quote or a double quote.
Depending on what it is that you need
to have inside the string,
for example, in this case, we want to use double quotes
inside the text area,
then we can instead use single quotes to define our text.
So this way, because the single quote
and double quote are different,
the computer knows that this is the beginning of text
from the word "She said",
and then at the end,
"then left." is the end of the entire string.
And in the middle,
we can have our English grammatical double quote.
So just by alternating this,
we can have either double quotes inside our text
or single quotes inside our text
by using a different type of symbol.
Now, another alternative option
that I want you to be aware of
is the use of what's called an escape backslash.
So this when you see here, it says, She said,
and then we've got a colon,
and then we have a backslash right before the double quote.
So even though in this case we've got double quotes
inside double quotes,
which as we said in the beginning can be confusing
for the computer to know what is text and what is code,
but because we have the backslash (\)
in front of the double quotes that we want to keep,
then the computer knows to ignore this as code.
So yes, the double quote can be used
in English to denote speech,
but also in programming, it's there to be placed around
words to tell the computer that it is text.
But in this case, we add the backslash
in front of the double quotes in the middle of the sentence
to tell the computer, "Ignore this.
This is definitely not code.
Don't worry about it.
It is meant to be printed exactly as it is."
So these are two of the ways
that you can modify your print() statement
if you want to add symbols
that are used within the syntax of the print() statement.
So you've heard the theory
of how to modify print() statements,
but now let's see it in practice.
So here, I've got the three examples that I talked about
where you can alternate single and double quotes,
and you can also use the backslash
in order to escape a particular symbol.
So go ahead and run this code and see what it prints out,
and then see if you can mess around with the code
to make all of this knowledge your own
so that you understand exactly what's going on
and what I mean by all of the explanations
that I gave in the previous slide.
Play around with the code,
you won't be able to break anything,
just try it out and make sure you understand
what's going on.