The Stock Analyzer
Welcome to Wall Street.
In the Digital Forest, you counted gold coins. In the Real World, numbers represent value that changes over time—like stock prices, temperature, or website traffic.
The Problem: You have a list of numbers, but raw numbers don't tell a story. The Goal: Extract Insights. What's the trend? What was the peak?
In this lab, you are becoming a Data Analyst.
Your job isn't just to store data, but to ask questions about it and get answers using Python's built-in math functions.
The Tools
Python creates statistics instantly with three spells:
prices = [10, 20, 30] # 1. sum() - Adds everything up total = sum(prices) # 60 # 2. len() - Counts the items count = len(prices) # 3 # 3. max() - Finds the biggest number highest = max(prices) # 30 # Average = Total / Count average = total / count # 20.0
Your Task
You are tracking the stock price of "HoppyCorp" over the last 7 days.
stock_prices = [120, 122, 115, 130, 128, 142, 135]
Calculate the Average Price of the week. (Hint: Use sum and len). Store it in a variable called avg_price.
Find the Highest Price of the week using max(). Store it in a variable called max_price.
Print a summary: "Average: [value], Max: [value]".
Suggested SolutionExpandCollapse
With just three lines of code, you can summarize millions of data points.
stock_prices = [120, 122, 115, 130, 128, 142, 135]
# 1. Calculate Average
total = sum(stock_prices)
count = len(stock_prices)
avg_price = total / count
# 2. Find Peak
max_price = max(stock_prices)
# 3. Report
print("Average Price:", avg_price)
print("Highest Price:", max_price)