AI-Guided Tutorial: Python Expressions
Instead of reading a textbook chapter, you’ll learn about Python expressions through hands-on AI-guided exploration. This interactive approach will help you understand concepts more deeply through practice and immediate feedback.
Learning Objectives
By the end of this tutorial, you should understand:
- What expressions are and how they work in Python
- Different types of expressions (arithmetic, string, boolean)
- Operator precedence and evaluation order
- How to use variables in expressions
- Common expression patterns and best practices
🎯 Important: Learning with AI Guidelines
To ensure you truly learn from this AI-guided tutorial, follow these essential practices:
Before Using AI:
- Think First: Attempt each practice task on your own before asking AI for help
- Set Learning Goals: Decide what you want to understand, not just what code you need
- Use AI after to Check: When you do a practice task, ask AI to check your answer e.g. “If the legal age for drinking is 21, is
age > 21 a correct Python expression to check if age meets the legal age for drinking?”
When Using AI:
- Challenges Yourself
- Ask “Why” Questions: Don’t just ask for code - ask “Why does this work?” or “What would happen if I changed X?”
- Request Explanations: Always ask Copilot to explain the logic behind suggestions
- Test Variations: Try modifying AI suggestions to see what happens
- Compare Approaches: Ask “Is there another way to do this?” to see different solutions
After AI Helps:
- Explain It Back: Try to explain the AI’s solution in your own words
- Apply It Differently: Use the same concept with your own different data
- Identify Patterns: Look for common structures or approaches you can reuse
- Debug on Purpose: Intentionally break the code to understand error messages
Red Flags - Stop and Think If You:
- ❌ Copy code without understanding what it does
- ❌ Can’t explain any line of code in your own words
- ❌ Haven’t tried the task yourself first
- ❌ Don’t know what would happen if you changed part of the expression
Tutorial Instructions
Part 1: Getting Started with AI Assistance
- Open VS Code and create a new Python file called
expressions_tutorial.py in your course folder
- Open GitHub Copilot Chat (Ctrl+Shift+I or Cmd+Shift+I) Set it to “Ask” mode
- Start with this prompt:
I want to learn about Python expressions. Can you explain what an expression is and give me 5 simple examples I can try in Python? Please include arithmetic, string, and comparison expressions.
Part 2: Exploring Arithmetic Expressions
Ask Copilot Chat:
Show me examples of Python arithmetic expressions using +, -, *, /, //, %, and **. Explain what each operator does and show me how operator precedence works with examples.
Practice Task: Calculate your personal statistics using arithmetic expressions:
- Your age in days (age × 365)
- Monthly expenses if you spend $X per week (weekly_spending × 52 ÷ 12)
- How many hours you’ve been alive
- Your GPA on a 100-point scale if it’s currently on a 4.0 scale
- Create at least 5 more expressions using your birth year, graduation year, or other personal numbers
💡 Learning Focus:
- Before asking AI: Try writing these expressions yourself first, even if they’re wrong
- With AI: Ask “Why do I need parentheses here?” and “What happens without them?”
- After AI helps: Change the numbers and verify the results make sense
Part 3: Working with Variables in Expressions
Ask Copilot Chat:
How do I use variables in Python expressions? Show me examples of assigning expression results to variables and using variables in more complex expressions.
Practice Task: Create a personal profile using variables and expressions:
- Store your name, age, hometown, and major in separate variables
- Create expressions that combine these variables (e.g., “My name is [name] and I’m [age] years old”)
- Calculate meaningful combinations like years until graduation, age when you started college
- Use your student ID number in mathematical expressions
- Create at least 3 complex expressions using your personal data
💡 Learning Focus:
- Before asking AI: Attempt to create variables and basic combinations yourself
- With AI: Ask “What’s the difference between using + vs f-strings for combining text?”
- After AI helps: Try creating expressions AI didn’t show you using the same principles
Part 4: String Expressions and Operations
Ask Copilot Chat:
What are string expressions in Python? Show me how to concatenate strings, repeat strings, and use string formatting in expressions. Include examples with f-strings.
Practice Task: Build your digital identity with string expressions:
- Create a professional email signature using your name, major, and graduation year
- Format your address in different styles (single line, multi-line, formal)
- Build social media usernames by combining your initials, birth year, or favorite number
- Create personalized messages like birthday wishes using your friends’ names
- Use f-strings to create a “About Me” paragraph with your hobbies, hometown, and goals
💡 Learning Focus:
- Before asking AI: Try basic string concatenation with + first
- With AI: Ask “When should I use f-strings vs other string methods?” and “What are the pros/cons?”
- After AI helps: Create 2 more examples using completely different personal information
Part 5: Boolean Expressions and Comparisons
Ask Copilot Chat:
Explain boolean expressions in Python. Show me comparison operators (==, !=, <, >, <=, >=) and logical operators (and, or, not) with practical examples.
Practice Task: Create personal decision-making boolean expressions:
- Compare your current age to legal milestones (18 for voting, 21 for drinking, 25 for car rental)
- Check if your GPA meets scholarship requirements or graduation criteria
- Create expressions for course prerequisites (e.g., “completed Math 140 AND GPA > 2.0”)
- Build eligibility checks for internships using your class standing and major
- Write boolean expressions that represent real decisions you make (budget constraints, time management, etc.)
💡 Learning Focus:
- Before asking AI: Think about what True/False means in each context
- With AI: Ask “What’s the difference between ‘and’ vs ‘or’?” with specific examples
- After AI helps: Create opposite expressions (e.g., “NOT eligible” conditions) to test understanding
Part 6: Advanced Expression Concepts
Ask Copilot Chat:
What is operator precedence in Python expressions? Show me examples where parentheses change the result, and explain the order of operations.
Practice Task: Apply operator precedence to real financial and academic scenarios:
- Calculate your total semester costs: (tuition + fees) × credit_hours + (housing + meals)
- Determine your final course grade: (homework_avg × 0.3) + (exam_avg × 0.7)
- Plan your monthly budget: income - (rent + utilities + groceries + entertainment)
- Compare study time allocation: hours_per_week ÷ number_of_courses vs. recommended_hours
- Create expressions where parentheses change your GPA calculation or graduation timeline
💡 Learning Focus:
- Before asking AI: Write expressions without parentheses first, then add them where needed
- With AI: Ask “Show me how the result changes when I remove these parentheses”
- After AI helps: Create an expression where parentheses placement significantly changes the result
Self-Assessment Checkpoint
Before moving on, ensure you can:
Reflection Questions
After completing the tutorial, use Copilot Chat to help you answer:
- Ask Copilot: “What’s the difference between an expression and a statement in Python?”
- Ask Copilot: “When should I use parentheses in expressions?”
- Ask Copilot: “What are some common mistakes beginners make with Python expressions?”
Assessment
Create a Python file with:
- 5 arithmetic expressions showing different operators
- 3 string expressions using concatenation and f-strings
- 4 boolean expressions using comparison and logical operators
- 2 complex expressions that demonstrate operator precedence
- Comments explaining what each expression does
Do this without prompting AI (you can use Co-pilot completion suggestions).
Submission: Save your expressions_tutorial.py file and be prepared to discuss your examples in class.
Additional Exploration (Optional)
If you want to learn more, ask Copilot Chat:
- “What are some advanced Python expression features I should know about?”
- “How do expressions work with lists and dictionaries?”
- “Show me some real-world examples where complex expressions are useful.”