The print() function displays text on the screen. Here's your first program:
print("Hi there!")
Expected output:
Hi there!
Important Syntax Rules
Text must be enclosed in quotes
Use either single 'text' or double "text" quotes
Don't forget the parentheses ()
Python is case-sensitive
โ Common Mistakes to Avoid
print(Hi there!) - Missing quotes around text
Print("Hi there!") - Wrong capitalization
print("Hi there!" - Missing closing parenthesis
print 'Hi there!' - Missing parentheses
๐ Exercise 1: Emoticon (1 point)
Write a program that prints out an emoticon: :-)
# Write your code here
2. Multiple Commands
Python executes commands in order from top to bottom. Here's a program with multiple print statements:
Example Program
print("Welcome to Introduction to Programming!")
print("First we will practice using the print command.")
print("This program prints three lines of text on the screen.")
Output
Welcome to Introduction to Programming!
First we will practice using the print command.
This program prints three lines of text on the screen.
This program should print the names of the seven brothers in alphabetical order. Fix the program:
# Fix the order of these names to be alphabetical
print("Simeoni")
print("Juhani")
print("Eero")
print("Lauri")
print("Aapo")
print("Tuomas")
print("Timo")
3. Arithmetic Operations
Basic Math in Python
You can perform arithmetic operations directly in print statements:
๐ Exercise 3: Row, Row, Row Your Boat (1 point)
Write a program that prints out the following lyrics exactly:
Row, row, row your boat,
Gently down the stream.
Merrily, merrily, merrily, merrily,
Life is but a dream.
# Write your code here
4. Adding Comments
What are Comments?
Comments are lines of text that Python ignores. They help explain what the code does:
# This is a comment - Python will ignore this line
print("This line will be printed")
# Another comment explaining the calculation below
print(365 * 24) # 365 days, 24 hours in each day
Why Use Comments?
Explain complex calculations
Document what functions do
Leave notes for other programmers
Make code easier to understand later
Temporarily disable code
๐ Exercise 4: Minutes in a Year (1 point)
Calculate and print the number of minutes in a year. Use the comment to explain your calculation:
# Write your code here
๐ Exercise 5: Print Some Code (1 point)
Write a program that prints out: print("Hello there!")
# Write your code here
๐ Summary
You've completed the first Python course! You now know how to: