Lesson 1: Getting Started
In Python, we use the print() function to display information.
π― Learning Target
I can use the print() function to display a message.
print("Hello, world!")
βοΈ Your Turn
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.
π οΈ Steps for Completion
- Open the
111-str.pyfile from your Domain 1 Student folder within Visual Studio. - Note the two variables with strings containing a first and last name.
-
Add a
printstatement on line 3 to output a full name.- You may choose "First Last" or "Last, First" format.
- If using "Last, First", include a comma between the names.
- Run the code to confirm correct output.
- Python supports single or double quotes around strings.
-
Why does this cause an error?
print('Jason's turn') - Save the file as
111-str-completed.py. - Open the
112-numbers.pyfile. - Numbers stored as strings (inside quotes) can't be used in calculations.
-
On line 4, add this to check the data type of
number_of_tries:print(type(number_of_tries))
- Run the file to confirm it's an integer.
- Save it as
112-numbers-completed.py.
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.
βοΈ Steps for Completion
- Open the
113-numbers.pyfile from your Domain 1 Student folder. - Observe that the variable
multiplieron line 2 is a float. - Add a
printstatement on line 4 that calculatesnumber_of_tries + multiplier. Run the code. -
What data type is returned from this addition?
- Change the operator to
/(division) and run the code again. -
What data type is returned now?
- Save the updated file as
113-numbers-completed.py. - Floats are useful for tracking scores, currency, and measurements in games.
- Open the
114-boolean.pyfile. - Check out the
char_lifevariable. Itβs set toTrue. Run the code to see what it does. - Save the file as
114-boolean-completed.py. - β οΈ Reminder: Python is case-sensitive. Booleans must use capital
TrueandFalse.
π Project Details
- Files: 113-numbers.py, 114-boolean.py
- Time: 10β15 minutes
- Video Reference: Domain 1 β Data Types: float and bool
π Objectives Covered
- 1.1 Evaluate expressions to identify the data types Python assigns to variables
- 1.1.3 float
- 1.1.4 bool
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)
βοΈ Your Turn
Create a variable for your favorite movie or show. Then print a message using it.
Lesson: Data Type Conversion
- Open the
121-conversion.pyfile from your Domain 1 Student folder. - Notice that the variable on line 2 stores a user rating (expected to be a whole number). Run the code.
- Try entering a float value between 1 and 5 in the terminal. Run the code again.
- What data type is stored in the
inputvariable by default?
Lesson: Indexing
- Open the
122-indexing.pyfile from your Domain 1 Student folder. - Line 1 lists categories for users to choose from. Line 2 prints the entire list.
- Copy the code from line 2 and paste it into line 4. Edit it to print only the first category:
Early Bronze Age. - Change the index value to 2 and run the code again.
- Which item in the list was returned?
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)
βοΈ Your Turn
Create two variables with numbers and print their product.
π Slicing
- Open the
123-slicing.pyfile from your Domain 1 Student folder. - Notice the variable
serial_numberon line 1. It's a series of 16 numbers. - Add a
print()function on line 2 to show only the first 4 characters. - On line 4, print only the last 4 characters.
- On line 5, print the 8 middle characters.
π¦ 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: 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"
π Try It: Modify the Code
- Open
126-list_operations.pyfrom your Domain 1 Student folder. - Use
append()to add"Sacramento"to thecapitalslist. Run the code. - Use
insert()to place"Little Rock"before"Sacramento". Rerun the code. - What is the object and method in
capitals.append("Sacramento")?- Object: capitals
- Method: append
- Save the file as
126-list_operations-completed.py.
π§ Deeper Thinking
- Why does
"Little Rock"appear twice when you run the program? - What are two ways you could fix this?
- a. ______
- b. ______
π§ͺ Practice and Analyze
- Open
126-analyze.py. - What will the
print()statement on line 2 output? - What kind of data structure is used on line 4?
- How would you change the
coinslist to use"bronze"instead of"platinum"?
π Project Summary
- Files: 126-list_operations.py, 126-analyze.py
- Estimated Time: 10β15 minutes
- Objectives:
- 1.2.5 Use lists to store data
- 1.2.6 Perform operations on lists
π 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.")
βοΈ Your Turn
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.
- Review the code and answer the following:
- What will happen when this code is run?
Print will disply as x is now: 8. 5+3=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?
- In what sequence are comparisons evaluated?
- What happens if part of a comparison is false?
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. and
- b. or
- c. not
- Review the code and answer the following:
- What will happen when this code is run?
π 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 + "!")
βοΈ Your Turn
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.
Steps for Completion
- List the order of operations from first to last.
- a. ()
- b. **
- c. *
- d. / & //
- e. +
- f. -
- Open the
134-arithmetic.pyfile from your Domain 1 Student folder. - Run the code. What is the result?
Project Details
Project file: 134-arithmetic.py
Estimated completion time: 10 minutes
Video reference: Domain 1 Topic: Sequence of Execution Subtopic: Arithmetic Order
Objectives covered:
- 1 Operations Using Data Types and Operators
- 1.3 Determine the sequence of execution based on operator precedence
- 1.3.4 Arithmetic
Notes
You should completed projects and show an opening parenthesis added before the base variable and a closing parenthesis added after the bonus variable.
Steps for Completion (Continued)
- 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?
- Save the file as
134-arithmetic-completed.
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.
Project Details
Project file: N/A
Estimated completion time: 5 minutes
Video reference: Domain 1 Topic: Sequence of Execution Subtopic: Containment Order
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)
Notes
Ensure You understand why one may want to use a containment operator.
Questions
- What result will the code on line 3 output?
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. ()
- b. x[index] & [index:index]
- c. **
- d. -x & +x //
- e. str
- f. %
- What supersedes all operators in the order of operations?
- a. ()
- What is the order of preference for logical operators?
- a. and
- b. or
- c. not
- What is the order of operations for arithmetic operators?
- a. ()
- b. **
- c.
- d.
- e.
- f.
Project Details
Project file: N/A
Estimated completion time: 15 minutes
Video reference: Domain 1 Topic: Sequence of Execution Subtopic: Containment Order; Review on 1.3
Objectives covered:
- 1 Operations Using Data Types and Operators
- 1.3 Determine the sequence of execution based on operator precedence
Notes
Make sure You understand not only the order of operations but how to analyze code using order of operations to either generate a result or see how a result was found.
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))
βοΈ Your Turn
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")
βοΈ Your Turn
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!")
βοΈ Your Turn
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")
βοΈ Your Turn
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)
βοΈ Your Turn
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
βοΈ Your Turn
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.")
βοΈ Your Turn
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
Your Turn!
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: