Lesson 1: Print()
In Python, we use the print() function to display information.
Learning Target
I can use the print() function to display a message.
Tasks:
- Write a Python statement to print your name and your favorite emoji.
Lesson 1.1: Strings and Integers
Strings and integers are data types that can be added to variables within Python code. A variable is a container that stores a value, like a string of text, a number, or other data types.
Strings of text go inside quotation marks and can be used in various ways. An integer is a numeric data type that represents a whole number.
Variable names can contain letters, numbers, and underscores, but not symbols or spaces. Python’s standard naming convention is all lowercase characters with underscores replacing spaces.
Purpose
Understand how to use strings and integers in Visual Studio using Python.
Tasks:
- Using
111-str.pyadd a print statement to line to output the full name. You can use “First Last” or “Last,First” format -
Why does this code cause an error?
print('Jason's turn') - open
112-numbers.pyand on the 4th line add the check data type of number_of_tires
Lesson: Floats and Booleans
Floats and booleans are additional data types in Python. While integers represent whole numbers,
floats (short for "floating point numbers") are numbers with decimals, like 3.14 or 0.75.
The boolean (or bool) data type only has two values: True or False.
These are often used to control game logic, such as whether a player is alive or has won.
Learning Target
I can use floats and booleans in basic operations and identify their data types in Python.
Tasks:
- open
113-numbers.pyand add a print state on the 4th line that adds the number of tires and the multiplier.
What data type is returned from this addition? - Change the operator to
/(division) and run the code again. -
What data type is returned now?
- open
114-boolean.pyad rune the code to see what happens. - ⚠️ Reminder: Python is case-sensitive. Booleans must use capital
TrueandFalse.
Project: Analyze Data Types
Purpose
By completing this project, you will strengthen your understanding of Python data types and improve your ability to identify them correctly in code.
Steps for Completion
- Open the
114-analyze.pyfile from your Domain 1 Student folder. - Review the five
printstatements in the file. - Identify the data type used in each statement and record your answers below:
Reflect
Think about what you just explored. Understanding data types is a key part of writing error-free, logical code.
- Why is it important to know the data type of a variable?
- What can go wrong if you assume the wrong type?
- Which data type do you find easiest to recognize? Which is trickiest?
Lesson 2: Variables
Variables store information in Python. You create a variable by giving it a name and assigning it a value using the = sign.
Learning Target
I can store and reuse data in variables.
name = "Ava"
print("Hi " + name)
Tasks:
- Create a variable for your favorite movie or show. Then print a message using it.
Lesson: Data Type Conversion
- Open
121-conversion.pyand run the code. Enter a float between 1 and 5 then run the code again. - What data type is stored in the
inputvariable by default?
Lesson: Indexing
- Open
122-indexing.pyObserve that line 1 has the lists and line 2 prints the list. - Copy and paste the code from line 2 and edit it to print only the first category:
Early Bronze age.After that change the index to 2 and run the code again. - Which item is returned in the list
Lesson 3: Numbers and Math
Python can do math just like a calculator. Use + to add, - to subtract, * to multiply, and / to divide.
Learning Target
I can use variables to perform math operations.
a = 5
b = 3
print(a + b)
Tasks:
- Create two variables with numbers and print their product
Slicing
- Open
123-slicing.pyand observe that the variableserial_numberand how many digits are in it. Add a print statement to only print the first 4 characters. Then add 2 other print statements that print the last 4 digits and the 8 middle digits.
Data Structures
- Strings are a type of data structure because they are collections of characters.
- Match each code example to the correct data structure:
- A. Dictionary
- B. Set
- C. Tuple
Lesson 4: Lists and Their Operations
A list is a collection of items stored in a specific order. Instead of creating a separate variable for each value, you can store them all in one list. Lists can grow and change using built-in methods like .append() and .insert().
Learning Target
I can store and manipulate multiple values using lists in Python.
Your Turn: Thinking About Lists
In the code below, each value is stored in a separate variable. Why might someone do this instead of using a list?
city1 = "Dallas"
city2 = "Austin"
city3 = "Houston"
Task:
- Open
126-list_operations.pyuseappend()to add “sacramento” to the list and then useinsertto add “Little rock” before “sacarmento”
capitals.append("Sacramento")?
- Object: Sacramento
- Method: append
🧠 Deeper Thinking
- Why does
"Little Rock"appear twice when you run the program? - What are two ways you could fix this?
- a. Remove item one of the little rocks
- b. check if the index is right
Tasks:
- Open
126-analyze.py. What will theprint()do? - What kind of data structure is used on line 4?
- How would you change the
coinslist to use"bronze"instead of"platinum"?
Notes
- Append:
capitals.append("Sacramento") - Insert before:
capitals.insert(3, "Little Rock") - Reinforce that
.accesses a method of the object before it. - Have You should verbalize how list operations affect code flow and output.
Lesson 5: String + Number
You can use str() to convert numbers into strings so they can be combined with text.
Learning Target
I can display numbers in sentences using str().
age = 12
print("I am " + str(age) + " years old.")
Tasks:
Create a variable for a number, convert it to a string, and print it in a sentence.
Lesson: Assignment, Comparison & Logical Operators
Assignment Operators
Operators perform calculations and evaluate conditions. The six main types in Python are arithmetic, containment, comparison, identity, logical, and assignment. Assignment operators are used to set values to variables.
Purpose
Understand how assignment operators work and in what sequence they are executed.
Steps for Completion
- Name the six types of operators in the order of execution--->assignment operators,logical operators, identity operators comparison operators,membership operators, and Arithmetic operators.
- Review the code and answer the following:
- What will happen when this code is run--->#-----It will print that x is equal to 8
x = 5 x += 3 print("x is now:", x)
Notes
- Explain that variables take the most recent value assigned.
- The variable on the left side of
=is set to the value on the right side.
Comparison Operators
Comparison operators compare two values: equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to. They help determine whether a condition is met.
Purpose
Understand how Python uses comparison operators to evaluate expressions.
Steps for Completion
- What type of value do comparisons return--->True and False
- In what sequence are comparisons evaluated--->left to right
- What happens if part of a comparison is false-->it returns false or is skipped in a conditional
a = 10
b = 20
print(a == b) # False
print(a < b) # True
Logical Operators
Logical operators in Python include not, and, and or. These operators follow a specific order of precedence and are essential for controlling flow based on multiple conditions.
Purpose
Learn how logical operators influence the flow of logic in code.
Steps for Completion
- List the logical keywords in order of precedence:
- a. not
- b. and
- c. or
- Review the code and answer the following:
- What will happen when this code is run---> it will return true for line 2 and false for line 3
Notes
- If time permits, share additional examples of logical operators in Python code.
x = 7
print(x > 5 and x < 10) # True
print(not x == 7) # False
Lesson 6: Input from the User
You can ask the user questions using the input() function. The user's response is stored as a string.
Learning Target
I can get and use input from a user in a program.
name = input("What is your name? ")
print("Hello, " + name + "!")
Tasks:
Ask the user their favorite color and print a message with their answer.
Arithmetic
Arithmetic has an order of operations when performing calculations. This order ensures that calculations are performed the same way every time to provide consistent results.
Purpose
Upon completing this project, you will better understand the order of operations.
- List the order of operations from first to last.
- a. parentheses
- b. exponenets
- c. multiplication
- d. divison
- e. addition
- f. subtraction
Steps for Completion:
- Open the
134-arithmetic.pyfile from your Domain 1 Student folder. - Run the code. What is the result--->5500
- Edit the code so that the base and bonus variables are added together before being multiplied by the rank variable.
- Run the code. What is the result--->13500
- Save the file as
134-arithmetic-completed.
Objectives covered:
- 1 Operations Using Data Types and Operators
- 1.3 Determine the sequence of execution based on operator precedence
- 1.3.4 Arithmetic
Identity Operator
Two variables can appear equal, but one can use the identity operator to determine if they are truly the same. The identity operator determines if two variables share the same memory location.
Purpose
Upon completing this project, you will better understand the identity operator.
Steps for Completion
- The is keyword is used to identify whether two variables share the same memory space.
- In the order of operations, the identity operation happens before logical and assignment operations but after arithmetic and comparison operations.
- If two variables share the same memory space, they will have the same values.
Containment Operator
Containment is often used for lists, sets, tuples, and dictionaries. The containment operator checks whether a value is contained within a list of values.
Purpose
Upon completing this project, you will better understand the containment operator.
Steps for Completion
- Containment operations happen after identity operations.
- Review the code, then answer the question about the containment operator.
Objectives covered:
- 1 Operations Using Data Types and Operators
- 1.3 Determine the sequence of execution based on operator precedence
- 1.3.6 Containment (in)
Questions
- What result will the code on line 3 output--->it will return True
Review 1.3
Purpose
Upon completing this project, you will better understand the order of operations across categories of operators and within a category of operators.
Steps for Completion
- What is the order for the six types of operators?
- a. Arithmetic operators
- b. Assignment operators
- c. comparison operators
- d. logical operators
- e. Identity operators
- f. Membership operators
- What supersedes all operators in the order of operations?
- a. parentheses
- What is the order of preference for logical operators?
- a. not
- b. and
- c. or
- What is the order of operations for arithmetic operators?
- a. parentheses
- b. exponents
- c. multiplication
- d. division
- e. addition
- f. subtraction
Lesson 7: Integers from Input
You can turn input into a number using int(). This allows you to do math with it.
Learning Target
I can collect numbers from a user and use them in calculations.
age = int(input("How old are you? "))
print("Next year you’ll be " + str(age + 1))
Tasks:
Ask the user how many siblings they have. Then print double that number in a sentence.
Lesson 8: More Math
You can perform different operations like subtraction, multiplication, division, and remainders using -, *, /, and %.
Learning Target
I can perform and understand different types of math operations in Python.
apples = 9
friends = 2
print("Each friend gets", apples // friends, "apples")
Tasks:
Ask the user how many cookies they have and how many friends they’ll share with. Show how many each friend gets using division.
Lesson 9: Using Comments
Use # to add comments. These lines are ignored by Python but help humans understand the code.
Learning Target
I can use comments in my code to explain what it does.
# This line prints a greeting
print("Hello!")
Tasks:
Write a small program with at least two comments that explain what each part does.
Lesson 10: Syntax and Errors
Python will give an error if it doesn’t understand your code. These are called syntax errors.
Learning Target
I can recognize and fix syntax errors in Python code.
# Incorrect: missing parenthesis
print("Hello"
# Fixed version
print("Hello")
Tasks:
Fix this line of code with a syntax error:
print("What's up"
Lesson 11: Debugging
Sometimes your code runs but doesn’t do what you expect. Use print() to see what’s happening and find bugs.
Learning Target
I can use print statements to debug and fix code.
num = 10
# We expect this to print 20, but it prints 30!
print(num + 20)
Tasks:
Use print() to figure out what's wrong in a small buggy program. Then fix it.
Lesson 12: Order of Operations
Python follows PEMDAS rules for math: parentheses, exponents, multiplication/division, addition/subtraction.
Learning Target
I can use parentheses to control the order of operations in math expressions.
print(3 + 2 * 4) # 11
print((3 + 2) * 4) # 20
Tasks:
Write two print statements: one with parentheses and one without, using different math operations.
Lesson 13: Mini-Project
Let's combine everything we’ve learned into a short interactive project.
Learning Target
I can write a program that uses input, variables, math, and output.
name = input("What's your name? ")
birth_year = int(input("What year were you born? "))
age = 2025 - birth_year
print("Hi " + name + "! You are " + str(age) + " years old.")
Tasks:
Make your own short program! Use input, math, and strings to tell the user something fun or helpful.
Lesson 14: More Data Types and String Slicing
Learning Target
I can use booleans, floats, the modulus operator, and slice strings in Python.
Booleans
Booleans represent truth values: True or False. They are often used in conditions.
is_raining = True
print("Bring an umbrella:", is_raining)
Floats
Floats are numbers with decimal points.
price = 4.99
tax = 0.40
total = price + tax
print("Total:", total)
Modulus Operator
The modulus operator % returns the remainder of a division.
print(10 % 3) # Output: 1
print(15 % 4) # Output: 3
String Slicing
You can extract parts of a string using slicing.
word = "Python"
print(word[0:3]) # Output: Pyt
print(word[2:]) # Output: thon
print(word[-1]) # Output: n
Tasks:
Try writing a program that:
- Defines a float variable for a meal price
- Calculates tax using a float
- Prints whether the total is over \$10 using a boolean
- Prints the first 3 letters of a string using slicing
Try it here: