Estimated Time : 30 minutes
Course : AI-1 Data Analysis and Data Science
Activity : 1
Master Python fundamentals through hands-on exercises! This activity introduces variables, data types, and basic operations - the building blocks of data analysis.
By the end of this activity, you will be able to:
Understand and apply Variables (assignment, naming conventions)
Understand and apply Data types (int, float, string, boolean)
Understand and apply Basic operations (arithmetic, string concatenation)
Use print() effectively for debugging and output
Choose your development environment based on your needs:
Best for : Local development with cloud runtime consistency
Setup (first time only):
Open in VS Code :
bash
code activity-01-intro-to-python.ipynb
Select Google Colab Kernel :
Click "Select Kernel" (top-right) OR
Press Cmd+Shift+P -> Type "Select Kernel" -> Choose "Google Colab"
Authenticate :
Browser opens for Google login
Grant permissions
Return to VS Code (kernel connects automatically)
Run First Cell :
Click the play button on any code cell
Code executes on Colab's cloud runtime
Output appears directly in VS Code
Advantages :
✅ Runtime consistency with student environment (same library versions)
✅ Familiar IDE with extensions and shortcuts
✅ Git integration for version control
✅ Offline editing (execution requires internet)
First Connection : ~30-60 seconds
Subsequent Connections : ~10-15 seconds
Best for : Quick access from any device, no setup required
Setup :
Open in Browser :
Go to: https://colab.research.google.com
Click "File" -> "Upload notebook"
Select activity-01-intro-to-python.ipynb
Run Cells :
Click "Runtime" -> "Run all" to execute all cells
Or run cells individually: Shift+Enter
Advantages :
✅ No installation needed (works on Chromebooks, tablets)
✅ Shareable via link
✅ Auto-save to Google Drive
Note : Web Colab has the same free tier limits as VS Code integration
Best for : Offline work, quick edits, familiar environment
Setup :
bash
pip install -r requirements.txt
jupyter notebook activity-01-intro-to-python.ipynb
jupyter lab activity-01-intro-to-python.ipynb
Advantages :
✅ Offline development
✅ Fastest iteration for quick changes
Limitations :
⚠️ Library version differences vs Colab (may see different output)
⚠️ Different environment than students will use
Use When : Quick edits, no internet, testing local changes
Colab (cloud) : ~2 minutes
Local Jupyter : ~2 minutes
Peak RAM : <100MB
Colab Free Tier : 12GB available ✅ Sufficient
This Activity : ❌ Not needed (basic Python operations)
Free Tier : ✅ Sufficient for this activity
Pro Tier : Not necessary
Before starting, understand these session limits:
Limit
Value
Impact
Session Duration
12 hours max
Restart every 12 hours
Idle Timeout
90 minutes
Disconnects if inactive
RAM
12GB
Sufficient for this activity
💡 Tips :
Save frequently : Press Cmd+S (Mac) or Ctrl+S (Windows)
Avoid long breaks : Colab disconnects after 90 min idle
Re-run from top : After disconnection, run cells from beginning to restore state
65% of the code is implemented for you:
✅ Python environment configured (Jupyter/Colab kernel ready)
✅ Examples provided (see working code in action)
✅ Code structure set up (organized cells with clear instructions)
✅ print() demonstrations (learn by example)
⚠️ Variable exercises (5 TODOs for you to complete)
⚠️ Data type exercises (3 TODOs for you to complete)
⚠️ Operations exercises (4 TODOs for you to complete)
Before jumping into TODOs:
Run all cells to see what's already implemented
Examine the output of completed examples
Read the explanations to understand Python syntax
Review the print() examples to see expected patterns
Estimated Time : 5 minutes
What You'll Build :
Create variables with different naming conventions and assign values.
Success Criteria :
✅ Create 3 variables with descriptive names
✅ Assign different types of values (number, text, boolean)
✅ Print variable values to verify assignment
✅ Follow Python naming conventions (lowercase, underscores)
Hints :
💡 Variable names should describe what they store: user_age, is_valid, product_name
💡 Use = for assignment: my_variable = value
💡 Print to verify: print(my_variable)
Expected Output :
Key Concepts :
Variable Assignment : Using = to store values in memory
Naming Conventions : snake_case for variables in Python
Dynamic Typing : No need to declare types explicitly
Code Location : Cell 3 (search for # TODO 1:)
Estimated Time : 5 minutes
What You'll Build :
Work with Python's four basic data types: int, float, string, and boolean.
Success Criteria :
✅ Create variables for each data type
✅ Use type() to check variable types
✅ Print both value and type for each variable
✅ Understand differences between int and float
Hints :
💡 Integers: whole numbers like 42
💡 Floats: decimal numbers like 3.14
💡 Strings: text in quotes like "Hello"
💡 Booleans: True or False (capitalized!)
💡 Check type: type(variable_name)
Expected Output :
python
42 <class 'int' >
3.14 <class 'float' >
Hello World <class 'str' >
True <class 'bool' >
Key Concepts :
Integer (int) : Whole numbers without decimals
Float : Numbers with decimal points
String (str) : Text data enclosed in quotes
Boolean (bool) : True/False values for logic
Code Location : Cell 5 (search for # TODO 2:)
Estimated Time : 10 minutes
What You'll Build :
Perform addition, subtraction, multiplication, division, and modulo operations.
Success Criteria :
✅ Complete 5 arithmetic operations
✅ Store results in variables
✅ Print results with descriptive labels
✅ Understand modulo (%) operator
Hints :
💡 Addition: a + b
💡 Subtraction: a - b
💡 Multiplication: a * b
💡 Division: a / b (returns float)
💡 Modulo: a % b (remainder after division)
💡 Use f-strings for clear output: print(f"Result: {result}")
Expected Output :
makefile
Sum: 15
Difference: 5
Product: 50
Quotient: 2.0
Remainder: 1
Key Concepts :
Arithmetic Operators : +, -, *, /, %
Operator Precedence : Multiplication/Division before Addition/Subtraction
Integer vs Float Division : / always returns float, // for integer division
Code Location : Cell 7 (search for # TODO 3:)
Estimated Time : 5 minutes
What You'll Build :
Concatenate strings and use string methods.
Success Criteria :
✅ Combine strings with + operator
✅ Use .upper() and .lower() methods
✅ Get string length with len()
✅ Create formatted output with f-strings
Hints :
💡 Concatenation: "Hello" + " " + "World"
💡 Methods: text.upper(), text.lower()
💡 Length: len(text)
💡 F-strings: f"Name: {name}, Age: {age}"
Expected Output :
makefile
Hello World
HELLO WORLD
hello world
Length: 11
Key Concepts :
String Concatenation : Joining strings with +
String Methods : Built-in functions like .upper(), .lower()
F-strings : Modern way to format strings with variables
Code Location : Cell 9 (search for # TODO 4:)
Estimated Time : 5 minutes
What You'll Build :
Create a simple program that uses variables, operations, and output together.
Success Criteria :
✅ Create a scenario (e.g., shopping cart calculator)
✅ Use multiple variables with meaningful names
✅ Perform calculations
✅ Format output with f-strings
Hints :
💡 Think of a real-world scenario (shopping, temperature conversion, age calculator)
💡 Use descriptive variable names
💡 Show your calculation steps with print statements
💡 Make output readable with labels
Expected Output (example for shopping cart):
yaml
Item: Python Book
Price: $29.99
Quantity: 3
---
Subtotal: $89.97
Tax (8%): $7.20
Total: $97.17
Key Concepts :
Program Flow : Combining multiple concepts into a cohesive program
Real-World Application : Using Python for practical calculations
Output Formatting : Creating clear, readable results
Code Location : Cell 11 (search for # TODO 5:)
Run All Cells :
Variable Validation :
Output Validation :
Issue : "ModuleNotFoundError: No module named 'X'"
Solution :
python
pip install -r requirements.txt
Issue : "Kernel not found" or "No kernel selected"
Solution :
VS Code + Colab : Click "Select Kernel" -> Choose "Google Colab"
Local Jupyter : Install kernel: python -m ipykernel install --user
Web Colab : Runtime -> Change runtime type -> Save
Issue : "Session disconnected" or "Kernel restarting"
Solution :
Colab disconnects after 90 minutes idle
Action : Re-run cells from top to restore state
Prevention : Save frequently (Cmd+S / Ctrl+S)
Issue : "NameError: name 'variable_name' is not defined"
Solution :
Variable was not defined in previous cells
Fix : Run cells in order from top to bottom
Check : Ensure variable assignment cell executed successfully
Issue : "SyntaxError: invalid syntax"
Solution :
Check for common typos:
Missing quotes: "text should be "text"
Unmatched parentheses: print("hello" should be print("hello")
Wrong capitalization: true should be True
Fix : Read error message carefully - it points to the line with the issue
Issue : Output doesn't match expected results
Solution :
Check variable values : Add print(variable) to debug
Check data types : Use type(variable) to verify
Check calculations : Break complex operations into steps
Compare with examples : Review working code in earlier cells
Read Error Messages Carefully :
Python tells you exactly what went wrong
Error messages include line numbers and error types
Use print() Statements :
python
print (f"Variable x: {x} " )
print (f"Variable type: {type (x)} " )
Test One Step at a Time :
Break complex operations into smaller cells
Verify each step before proceeding
Run Cells in Order :
Variables must be defined before use
Always run from top to bottom initially
Restart and Re-run :
If state becomes confusing: Runtime -> Restart runtime
Then run all cells from beginning
Completed the main activity? Try these bonus challenges:
Challenge 1 : Create a temperature converter (Celsius <-> Fahrenheit) [+10 min]
Challenge 2 : Build a simple calculator with all operations (+, -, *, /, %) [+15 min]
Challenge 3 : Create a personal info formatter (name, age, city) with nice output [+15 min]
Challenge 4 : Calculate compound interest with principal, rate, and time [+30 min]
Challenge 5 : Create a unit converter (km<->miles, kg<->lbs, cm<->inches) [+30 min]
Challenge 6 : Build a grade calculator (average of scores, letter grade) [+45 min]
Challenge 7 : Create a simple text-based game using variables and operations [+1 hour]
Challenge 8 : Implement a tip calculator with split bill functionality [+1 hour]
Your activity is complete when:
✅ All 5 TODO exercises completed
✅ All cells execute without errors
✅ Outputs match expected results
✅ Variables have descriptive names
✅ Code follows Python naming conventions
✅ Extension challenges attempted (optional but encouraged)
Complete all TODOs in the notebook
Verify all cells run without errors (Runtime -> Run all, or Kernel -> Restart & Run All)
Save your notebook :
VS Code: Cmd+S / Ctrl+S
Web Colab: File -> Save
Local Jupyter: File -> Save and Checkpoint
Download completed notebook (if using web Colab):
File -> Download -> Download .ipynb
Submit via course portal (follow course-specific instructions)
Activity 02 - Jupyter Notebooks : Learn notebook shortcuts, markdown, and magic commands
Once you complete this activity, you'll have:
✅ Mastered Python variable assignment
✅ Understood Python's basic data types
✅ Practiced essential arithmetic operations
✅ Created your first Python programs
This activity is the foundation of your data analysis journey. Everything you build in AI-1 will use these fundamental concepts!
Stuck on a TODO?
Re-read the hints section
Check the examples in earlier cells
Review the expected output format
Still stuck after 15 minutes?
Post in the course discussion forum
Ask during office hours
Email instructor with:
Specific TODO number
Error message screenshot
What you've tried so far
Pro Tips :
💡 Python is case-sensitive: True != true
💡 Strings need quotes: "text" not text
💡 Use descriptive variable names: student_age not x
Remember : Learning Python is a journey, not a race. It's OK to:
❌ Get errors (they teach you debugging)
❌ Need multiple attempts (mastery takes practice)
❌ Ask for help (collaboration is encouraged!)
Happy coding! 🚀📊✨
This activity follows the 65-70% implementation methodology: core examples provided, students complete targeted learning exercises