
Python - 1.1: Output, Concatenation, and Documentaion
Presentation
•
Computers
•
9th - 12th Grade
•
Practice Problem
•
Easy
Robert Giordano
Used 1+ times
FREE Resource
10 Slides • 8 Questions
1
1.1 - Output, Concatenation, &
Documentation
2
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
Example:
This is where the
code is written.
This is the console
where it is output.
4
Fill in the Blanks
5
Multiple Choice
Which of the following will display as a result of the code shown?
Happy Brithday!
Happy Birthday!
HappyBirthday!
Nothing there is an error.
6
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
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
Example:
9
Multiple Choice
What will print as a result of the code?
In 1947 Grace Hopper found the first computer bug
In 1947 Grace Hopper found the first computer bug
In1947Grace Hopper found the first computer bug
Nothing, there is an error
10
Fill in the Blanks
11
Drag and Drop
12
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
Example:
Notice the space
between the # and 17.
14
Multiple Choice
Which of the following is the output of the code?
The Yankees have won27World Championships
The Yankees have won 27 World Championships
The Yankees have won,27,World Championships
Nothing there is an error.
15
Multiple Choice
What will print as a result of the code?
I am,37,years old
I am 37 years old
I am37years old
Nothing there is an error.
16
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
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
What will print as a result of the code.
Alan Turing1912-1954
Alan Turing 1912 - 1954
Alan Turing,1912,-,1954
Nothing there is an error
1.1 - Output, Concatenation, &
Documentation
Show answer
Auto Play
Slide 1 / 18
SLIDE
Similar Resources on Wayground
13 questions
El alfabeto/Abecedario
Presentation
•
9th - 12th Grade
13 questions
Theme Review
Presentation
•
9th - 12th Grade
14 questions
Geo 10-6
Presentation
•
9th - 12th Grade
14 questions
Percent Yield
Presentation
•
9th - 12th Grade
14 questions
Slope and Slope Intercept Form
Presentation
•
9th - 12th Grade
14 questions
Balancing Chemical Equations Review
Presentation
•
9th - 12th Grade
13 questions
Types of Chemical Reactions
Presentation
•
9th - 12th Grade
13 questions
Properties of Parallelograms
Presentation
•
9th - 12th Grade
Popular Resources on Wayground
10 questions
HCS SCI 03 Summer School Review 4
Quiz
•
3rd Grade
11 questions
HSMS - Standard Response Protocol
Quiz
•
6th - 8th Grade
16 questions
1.1-1.2 Quiz Review
Quiz
•
9th - 12th Grade
12 questions
Exponent Expressions
Quiz
•
6th Grade
20 questions
Adding and Subtracting Integers
Quiz
•
6th - 7th Grade
11 questions
Northeast States
Quiz
•
3rd - 4th Grade
10 questions
Characterization
Quiz
•
3rd - 7th Grade
10 questions
Common Denominators
Quiz
•
5th Grade