PYTHON BASICS • LESSON 20
Python Basics Final Project
Put your Python fundamentals together in a practical sales analytics project. You will work with variables, lists, dictionaries, conditions, loops, functions, filtering, calculations, and debugging.
FINAL PROJECT
Sales Performance Analyzer
Imagine you are a junior data analyst. A company gives you a small sales dataset and asks you to analyze revenue, identify high-value transactions, calculate averages, and determine whether sales targets were achieved.
1. Project Dataset
Start with a list of sales transactions:
sales = [85000, 125000, 140000, 45000, 210000]
Each number represents the revenue generated by one transaction.
CHECK YOUR UNDERSTANDING
How many transactions are in the dataset?
2. Calculate Total Revenue
total_revenue = sum(sales) print(total_revenue)
The sum() function calculates the total of the numeric values.
CHECK YOUR UNDERSTANDING
What is the total revenue?
3. Calculate Average Revenue
average_revenue = sum(sales) / len(sales) print(average_revenue)
CHECK YOUR UNDERSTANDING
What is the average transaction value?
CHECK YOUR UNDERSTANDING
Correct calculation: What is ₹605,000 divided by 5?
To find the number of sales values, use ___(sales).
4. Find the Highest Sale
highest_sale = max(sales) print(highest_sale)
CHECK YOUR UNDERSTANDING
What is the highest transaction?
5. Find the Lowest Sale
lowest_sale = min(sales) print(lowest_sale)
CHECK YOUR UNDERSTANDING
What is the lowest transaction?
6. Identify High-Value Sales
Management wants to know how many transactions are at least ₹100,000.
high_sales = []
for sale in sales:
if sale >= 100000:
high_sales.append(sale)
print(high_sales)CHECK YOUR UNDERSTANDING
Which list will high_sales contain?
7. Count High-Value Sales
count = 0
for sale in sales:
if sale >= 100000:
count += 1
print(count)CHECK YOUR UNDERSTANDING
How many high-value transactions are there?
8. Represent a Sales Record
sale = {
"customer": "Aman",
"region": "North",
"revenue": 125000
}
print(sale["revenue"])CHECK YOUR UNDERSTANDING
What does sale['region'] return?
9. Work with Multiple Records
sales_data = [
{"customer": "Aman", "region": "North", "revenue": 125000},
{"customer": "Riya", "region": "South", "revenue": 85000},
{"customer": "Karan", "region": "East", "revenue": 140000},
{"customer": "Neha", "region": "West", "revenue": 210000}
]
for sale in sales_data:
print(sale["customer"], sale["revenue"])CHECK YOUR UNDERSTANDING
How many sales records are in sales_data?
10. Create a Reusable Function
Instead of repeatedly writing the same calculation, create a function.
def calculate_profit(revenue, cost):
return revenue - cost
profit = calculate_profit(125000, 75000)
print(profit)CHECK YOUR UNDERSTANDING
What is the profit?
11. Create a Function for Average Sales
def average_sales(values):
return sum(values) / len(values)
sales = [100000, 120000, 80000]
print(average_sales(sales))CHECK YOUR UNDERSTANDING
What is the average sales value?
12. Debug the Project
Find the logical error:
def calculate_profit(revenue, cost):
return revenue + cost
profit = calculate_profit(200000, 125000)
print(profit)CHECK YOUR UNDERSTANDING
What should be changed?
13. The Complete Analysis Workflow
- Store the data.
- Inspect the data.
- Calculate totals and averages.
- Filter important records.
- Use functions for repeated calculations.
- Check the results.
- Debug incorrect calculations.
A function is defined using the ___ keyword.
MINI CHALLENGE
Target Achievement
A sales representative generated ₹180,000 against a target of ₹150,000.
def target_percentage(sales, target):
return (sales / target) * 100CHECK YOUR UNDERSTANDING
What percentage of the target was achieved?
FINAL PROJECT CHALLENGE
Build the Sales Analyzer
Your final task is to combine everything you have learned. Consider this dataset:
sales = [85000, 125000, 140000, 45000, 210000]
Your program should:
- Calculate total revenue.
- Calculate average revenue.
- Find the highest sale.
- Find the lowest sale.
- Count sales of ₹100,000 or more.
- Use at least one reusable function.
CHECK YOUR UNDERSTANDING
What is the correct combination for this dataset?
Your Python Basics Journey
You have now worked through the core building blocks needed to start writing practical Python programs.
What Comes Next?
Python Basics is the foundation. The next courses can focus on specialized Python libraries and data analytics workflows.
NumPy
Numerical computing and arrays.
Pandas
DataFrames, cleaning, transformation and analysis.
Matplotlib
Data visualization with Python.
Seaborn
Statistical visualization and analytical charts.
Python Basics Complete
You have completed the 20-lesson Python Basics curriculum. You are now ready to move from core Python syntax into Python libraries used for data analytics.