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?

Fill in the Blank

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

  1. Store the data.
  2. Inspect the data.
  3. Calculate totals and averages.
  4. Filter important records.
  5. Use functions for repeated calculations.
  6. Check the results.
  7. Debug incorrect calculations.
Fill in the Blank

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) * 100

CHECK 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:

  1. Calculate total revenue.
  2. Calculate average revenue.
  3. Find the highest sale.
  4. Find the lowest sale.
  5. Count sales of ₹100,000 or more.
  6. Use at least one reusable function.
def analyze_sales(values):
    total = sum(values)
    average = total / len(values)
    highest = max(values)
    lowest = min(values)
    high_count = 0
    for v in values:
        if v >= 100000:
            high_count += 1
    return {
        "total": total,
        "average": average,
        "highest": highest,
        "lowest": lowest,
        "high_count": high_count,
    }

result = analyze_sales(sales)
print(result)
# {'total': 605000, 'average': 121000.0,
#  'highest': 210000, 'lowest': 45000,
#  'high_count': 3}

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.

Variables & Data Types
Conditions & Logic
Loops
Lists, Tuples, Dictionaries & Sets
Functions & Arguments
Errors & Debugging
Data Processing
Basic Data Analysis

FREQUENTLY ASKED QUESTIONS

Common questions about the final project

How do I know my analysis is actually correct?+
Cross-check every number against a second method. Compute the total with sum() and also by adding values by hand for a small list. If both agree, the calculation is almost certainly right. Analysts trust results that survive two independent checks.
Should I split my project into functions or write one long script?+
Split it. Every time you find yourself copying a calculation, wrap it in a function. Functions make the project easier to test, easier to debug, and reusable on the next dataset — which is exactly the point of this final project.
What if my script runs but the numbers look wrong?+
Add print statements after each stage: print the raw list, print the total, print the filtered list. Compare each one against what you expect. The first stage where the output diverges from your expectation is where the bug lives.
What should I do if my output disagrees with a business expectation?+
Treat it as a question, not a failure. Check the raw data first, then the calculation, then any assumptions baked into the code. Very often the 'wrong' number is actually correct and the expectation was wrong — either way, you now have something to report.
Where do I go after Python Basics?+
Move into the analytics libraries: NumPy for numerical arrays, Pandas for tabular data, and Matplotlib or Seaborn for visualization. Everything you learned here — lists, loops, conditions, functions — is still the underlying mental model for those tools.

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.