Search Header Logo
Python - 1.1: Output, Concatenation, and Documentaion

Python - 1.1: Output, Concatenation, and Documentaion

Assessment

Presentation

Computers

9th - 12th Grade

Practice Problem

Hard

Created by

Robert Giordano

FREE Resource

10 Slides • 8 Questions

1

media

1.1 - Output, Concatenation, &
Documentation

2

media

Console Output

One of the simplest things we can do in any CS language is to output text and numbers to the console of our Integrated Development Environment (IDE).

In Python, the command to output to the console is:

print( )

That’s it. You can place numbers, Strings, or even variables (next lessons) inside the ( ) and it will print that to the console.

3

media
media
media

Example:

This is where the
code is written.

This is the console
where it is output.

4

Fill in the Blanks

5

Multiple Choice

Question image

Which of the following will display as a result of the code shown?

1

Happy Brithday!

2

Happy Birthday!

3

HappyBirthday!

4

Nothing there is an error.

6

media

Concatenation:

One of the things that we can do when outputting is to concatenate two outputs
together. We do this in order to make our programs output meaningful context and
results.

There are 2 methods of combining these outputs together:

Concatenation with +

Concatenation with ,

7

media

Concatenation with ‘+’:

If we try to concatenate a string (text) with a non-string (number) using the ‘+’
symbol we will get a syntax error. This is because Python only likes to concatenate
strings with other strings.

To fix this issue, we have to tell the computer to convert any non-strings into strings
so that it can combine them. We do this by surrounding the non-strings with the
command str( ). Anything inside the parentheses of this command will be
transformed to a string by the computer.

8

media
media
media

Example:

9

Multiple Choice

Question image

What will print as a result of the code?

1

In 1947 Grace Hopper found the first computer bug

2

In 1947 Grace Hopper found the first computer bug

3

In1947Grace Hopper found the first computer bug

4

Nothing, there is an error

10

Fill in the Blanks

11

Drag and Drop

Complete the code below:



("Shohei Ohtani #" ​
(17))​
Drag these tiles and drop them in the correct blank above
print
+
str
display
output
,
int
float

12

media

Concatenation with ‘,’:

While this technically isn’t true concatenation, we can combine two outputs using a comma in the print statement. There are some differences between concatenating using the ‘+’ symbol and this method:

Concatenating with + doesn’t add any space between the outputs. Combining using a , does.

Concatenating with + requires you to convert non-strings into strings with str( ). Combining using a , doesn’t

13

media
media
media

Example:

Notice the space
between the # and 17.

14

Multiple Choice

Question image

Which of the following is the output of the code?

1

The Yankees have won27World Championships

2

The Yankees have won 27 World Championships

3

The Yankees have won,27,World Championships

4

Nothing there is an error.

15

Multiple Choice

Question image

What will print as a result of the code?

1

I am,37,years old

2

I am 37 years old

3

I am37years old

4

Nothing there is an error.

16

media
media
media

Comments:

Did you notice in the previous 2 examples that there were 2 lines with something
written, but only one of them was actually performed by the computer?

These lines starting with a # are called comments. Comments are lines of
instructions or notes written by the programmer to give context to the code that will follow it. Writing comments is a skill that is very important and something that all programmers should do whenever they are writing code.

17

media
media

Documentation:

A program’s documentation is a brief introduction into the basic info of the
program. It includes the author’s name, the program’s name, the date it was
developed, and the version number. This documentation is also sometimes called a header since it sits at the top of a program’s file.

Here’s a sample header

18

Multiple Choice

Question image

What will print as a result of the code.

1

Alan Turing1912-1954

2

Alan Turing 1912 - 1954

3

Alan Turing,1912,-,1954

4

Nothing there is an error

media

1.1 - Output, Concatenation, &
Documentation

Show answer

Auto Play

Slide 1 / 18

SLIDE