Week 1 Lab

BANA 4080: Introduction to Data Mining with Python

Week 1 Lab

Week 1 Lab: Python Setup & Basics

Today you’ll:

  • Get started in Google Colab
  • Run your first Python code
  • Practice with:
    • print() statements
    • Python data types
    • Variables & comparison operators
  • Build a simple event summary using what you’ve learned

Note

📘 Based on Chapters 2 & 3

Our Coding Environment

Colab

Google Colab is a free, cloud-based tool that lets you run Python code in your browser. It requires no setup and is perfect for getting started.

  1. Go to: https://colab.research.google.com/

  2. Sign in with your Google account (you’ll need one).

  3. Click on “New Notebook.”

  4. In the cell that appears, type:

    print("Hello World")
  5. Press Shift + Enter to run the cell.

Ask AI

Combining Text & Code


  • Within our notebooks we can include both text and code.

  • This is great because it allows us to add context around our analysis directly in the same place we are writing code.

  • Let’s add a title and some simple text to our notebook

Note

Don’t worry, we’ll go into more detail on Markdown in next week’s readings.

Colab is great but…

You’ll want to eventually install a local IDE


Anaconda

VS Code

Tip

See the Anaconda Installation and/or VS Code Installation guide in the book appendix

Some Python Basics

Lab Notebook

Open the lab notebook in Colab:

Open in Colab

🍕 Pizza Math: Which Is a Better Deal?

We’re using:
💡 \(A = \pi \times r^2\) and π ≈ 3.14159



🧮 12-Inch Pizza

diameter_12 = 12
radius_12 = diameter_12 / 2
area_12 = 3.14159 * radius_12 ** 2
cost_12 = 8.00
cost_per_sqin_12 = cost_12 / area_12

print("12-inch cost per sq in:", round(cost_per_sqin_12, 4))
12-inch cost per sq in: 0.0707

🧮 15-Inch Pizza

diameter_15 = 15
radius_15 = diameter_15 / 2
area_15 = 3.14159 * radius_15 ** 2
cost_15 = 12.00
cost_per_sqin_15 = cost_15 / area_15

print("15-inch cost per sq in:", round(cost_per_sqin_15, 4))
15-inch cost per sq in: 0.0679

Final Exercise – Solution

# Step 1: Create variables
event_name = "Python for Everyone"
tickets_sold = 56
ticket_price = 10.50
revenue_goal = 600


# Step 2: Calculate total revenue
total_revenue = tickets_sold * ticket_price


# Step 3: Print summary report
print("The event \"" + event_name + "\" sold " + str(tickets_sold) + 
      " tickets at $" + str(ticket_price) + " each.")
print("Total revenue: $" + str(total_revenue))
print("Met or exceeded goal:", total_revenue >= revenue_goal)
The event "Python for Everyone" sold 56 tickets at $10.5 each.
Total revenue: $588.0
Met or exceeded goal: False


# Step 4: Optional stretch goal (conditional message)
if total_revenue >= revenue_goal:
    print("Yaaah! We met our goal!")
else:
    print("Booo! We missed our goal.")
Booo! We missed our goal.

Questions & Reflections

🙋 End of Class – Questions or Thoughts?


Before we wrap up…

  • ❓ What questions do you still have about:

    • Colab?
    • Python basics?
    • Variables or comparisons?
  • 💬 What surprised you about writing code today?

  • 🧠 What’s one thing you feel more confident about now?

✅ Coming Next:


  • More about Jupyter notebooks
  • Python data structures (lists, tuples, sets)
  • Packages, Libraries, Modules



See you Tuesday!