๐Ÿ Python Course 1: Getting Started

๐ŸŽฏ Learning Objectives

After completing this section, you will be able to:

โšก Prerequisites

  • Basic computer skills
  • Text editor installed
  • Python installed on your system
  • Understanding of basic math concepts

1. Your First Python Program

Basic Print Command

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

๐Ÿ“ 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.

Key Points

  • Each print statement creates a new line
  • Commands execute in sequence
  • Empty lines in code don't affect output
  • Use meaningful messages for users
๐Ÿ“ Exercise 2: Fix the Code - Seven Brothers (1 point)

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:

print(2 + 5) print(3 * 3) print(2 + 2 * 10)
7 9 22

Arithmetic Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • ** Exponentiation (power)
  • % Modulo (remainder)

More Examples

# Different operations print("Addition:", 15 + 27) print("Multiplication:", 4 * 12) print("Division:", 144 / 12) print("Power:", 2 ** 8) print("Remainder:", 17 % 5)
๐Ÿ“ 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:

Total points earned: 5/5

โฌ…๏ธ Previous

Python Basics

โžก๏ธ Next

Course 2: Information from the user

100%

โฌ…๏ธ Previous

Python Basics

โžก๏ธ Next

Python Course 2: Information from the user