0% found this document useful (0 votes)
34 views7 pages

Basic Output: Teach Computer Science

The document teaches how to use print statements in Python to output text to the screen. It explains that output provides a way for programs to communicate with users by displaying words, pictures, and sounds. The lessons show how to use print to output simple text and format text over multiple lines by escaping special characters. An activity has the user output an image of a dog using print statements.

Uploaded by

Imane Bourous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views7 pages

Basic Output: Teach Computer Science

The document teaches how to use print statements in Python to output text to the screen. It explains that output provides a way for programs to communicate with users by displaying words, pictures, and sounds. The lessons show how to use print to output simple text and format text over multiple lines by escaping special characters. An activity has the user output an image of a dog using print statements.

Uploaded by

Imane Bourous
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Teach Computer Science

Basic Output

teachcomputerscience.com
Basic Output Intro
For other people to know what we
are thinking about, we have to say
what’s on our mind! Similarly, we
can’t read the computer’s “mind.”
We have to tell it to communicate
with us. When the computer gives us
information, we call it output.
Output can include words on the
screen, pictures, and sound, among
other things.

In this lesson, we’ll learn how to tell


Python to write words on the screen.
Why do we need to know this?
Because getting feedback from our
programs lets us know if they’re
working correctly and lets the user
know what's going on.
teachcomputerscience.com
Basic Output pt. 1
▪ Run the code in the example.

Q: Based on the output we see on


the right side, what must print be
doing?
A: It takes what is between the
parentheses and outputs it on the
right side.

Q: Why didn’t it output the quotes?


▪ Take away the quotes and run the
code.
A: Python uses the quotes to
understand what type of data it is
dealing with. It needs them in this
case.
teachcomputerscience.com
Basic Output pt. 2
▪ Change the code so it outputs the
following, running it for each
item.
□ your name
print("Darth Vader")

□ That was interesting


print("That was interesting")

□ That was “interesting”


print("That was "interesting"")

Q: Why the error?


A: Some characters are special and
need to be escaped to be printed
exactly as they are. In this case, we
need to use a backslash (\) to escape
each quotation mark.
▪ Run:
print("That was \"interesting\"")

teachcomputerscience.com
Basic Output pt. 3
Each print statement outputs on its
own line.
▪ Run:
print("The sentence below is true.")
print("The sentence above is false.")

teachcomputerscience.com
Basic Output pt. 4
Activity:
▪ Use your new Python print
statement skills to output the
good boy below.
^..^ /
/_/\_____/
/\ /\
/ \/ \

Hint: Remember that each print


statement outputs onto a new line.
Hint: You may have to escape a few
characters!

Ideal answer on the next page.

teachcomputerscience.com
Basic Output pt. 5
Ideal answer:
print("^..^ /")
print("/_/\_____/")
print(" /\ /\\")
print(" / \ / \\")

Explanation:
The last two lines each contain an
extra backslash (orange) to escape
the backslash after it (green).
Without the extra backslash, Python
doesn’t know where the print
statement ends!

teachcomputerscience.com

You might also like