Skip to main content

Section 16.9 Review - Output and print()

Practice using print() to display output, predict what programs print, and fix common output mistakes.

Subsection 16.9.1 Quick Reference

print() displays output to the screen. It can print strings, numbers, variables, and expression results. When you print multiple values separated by commas, Python places a space between them in the output.

Subsection 16.9.2 Part A: Recognize

Checkpoint 16.9.1.

Study the code below and answer the questions.
name = "Raya"
print("Hello")
print(name)
  1. Which line prints a string literal?
  2. Which line prints the value stored in a variable?
  3. What is the purpose of print()?

Subsection 16.9.3 Part B: Predict the Output

Checkpoint 16.9.3.

What is printed?
name = "Jordan"
print("Hello, " + name + "!")

Subsection 16.9.4 Part C: Explain

Checkpoint 16.9.6.

Explain the difference between each pair.
  1. print("5") and print(5)
  2. print(name) and print("name")
  3. print("Age:", 18) and print("Age: " + "18")

Subsection 16.9.5 Part D: Fix

Checkpoint 16.9.7.

Rewrite the code so it works correctly.

Checkpoint 16.9.8.

Rewrite the code so it works correctly.

Checkpoint 16.9.9.

Rewrite the code so it prints the sentence β€œI am 18 years old.”

Subsection 16.9.6 Part E: Create

Checkpoint 16.9.10.

Write code for each task.
  1. Print the message β€œWelcome to CS1!”
  2. Create a variable named score with the value 95 and print it.
  3. Create a variable named name and print the greeting β€œHello, <name>!”
  4. Print the result of adding 8 and 2.

Subsection 16.9.7 Reflection

Checkpoint 16.9.11.

When should you print a value directly, and when is it helpful to store the value in a variable first?
You have attempted of activities on this page.