Back

Activity 1.2: Console Output

divider

Activity 1.2

Console Output

Key Concepts

Displaying Text Output

The print() function

The print() Function

print() displays a message in a terminal.

The print() Function

demo.py
print("Hello world!")
Demo
Hello world!

# Comments

Comments serve two key roles:

  • Documenting code
  • Disabling it temporarily for testing

# Comments

Comments are completely ignored by Python when the program is executed.

demo.py
# This line prints a friendly greeting to the console
print("Python is my favorite language!")
# print("This line is disabled for testing purposes.")
print() # Print a blank line
print("My second favorite language is ...")
Demo
Python is my favorite language!
My second favorite language is ...

Today's Objectives

  • Writing and executing code
  • Displaying console output
  • Reading and writing comments

Key Terms

Function
Code that performs a specific action.
Output
Information that a program produces.
Console Output
Text displayed by a program in a command-line interface, like a terminal.
Comments
Notes written within the code that are ignored by Python, used to explain or clarify the code.

'F' → Fullscreen

divider

Build

Create a new Python program named 1-2-output.py.


Task 1: Write and Test

  • Write each line of code, one at a time.
  • Run and test your program to ensure it executes as intended.
1-2-output.py
print("Hello, world!")
print("This class is taught by Mr. Mortimer.")
print("You are currently visiting: https://skynest.nexus")
print() # Display a blank line
#

Task 2: Add More Code

  • Write the additional sections of output under your current code.
  • Remember to run and test your project to ensure it executes as intended.
  • There is a section of code that is 'commented out'. Uncomment the code so that it executes when your program runs.
  • Note: The green lines with a + sign denote new code. Don't actually write the + sign.
1-2-output.py
print("Hello, world!")
print("This class is taught by Mr. Mortimer.")
print("You are currently visiting: https://skynest.nexus")
print() # Display a blank line
print("What is the answer to life, the universe, and everything?")
print("The answer is 42.")
print()
print("Sally sells seashells by the seashore.")
print("Sally wants to invite you to invest in a money making opportunity.")
print()
print("If you start to feel overwhelmed, just remember:")
print("Mortimers don't quit, we get fired!")
print()
print()
print("Sincerely,")
print("Mr. Mortimer")
# Display this message for 0.1 extra credit point
# print()
# print("PS Mr. Mortimer is the greatest teacher that ever lived.")
#

Challenge (Optional): Write a Custom Section

  • Output a three-line paragraph of your choice somewhere in the program. Keep it school appropriate.
  • Remember to run and test your project to ensure it executes as intended.
divider

Checkpoint

Verify your program works correctly.

Example Output
Hello, world!
This class is taught by Mr. Mortimer.
You are currently visiting: https://skynest.nexus
What is the answer to life, the universe, and everything?
The answer is 42.
Sally sells seashells by the seashore.
Sally wants to invite you to invest in a money making opportunity.
If you start to feel overwhelmed, just remember:
Mortimers don't quit, we get fired!
Sincerely,
Mr. Mortimer
PS Mr. Mortimer is the greatest teacher that ever lived.
I also accept the following items for extra credit:
1. Expired mayonaise
2. A preserved eyeball
3. A VHS tape of a movie that nobody has heard of
divider

Reflection

Answer the following questions before submitting your work.

  1. What is the primary purpose of the print() function?
  2. Imagine you typed prnint() by mistake. What do you think would happen when you try to run your program?
  3. What was the most challenging part of writing your first program?
divider

Submit

Submit the required files to the appropriate dropbox.

Activity Complete