Python – Portfolio Tasks

Six extended projects to showcase practical skills—with copyable sample solutions.

Extended Portfolio Projects

Below are six extended projects that showcase your Python skills—from file/data handling to simple AI interactions. Use them as interview talking points or publish them on GitHub.

Extended Task 1: Student Grades Manager

Create a program for entering student names and grades, computing averages, and saving to a file.

  • Collect student names and a list of grades.
  • Calculate each student's average.
  • Save all data in a readable format.
View Sample Solution
def get_student_data():
    student = input("Enter student's name: ")
    grades = []
    num_assignments = int(input("Enter number of assignments: "))
    for i in range(num_assignments):
        grade = float(input(f"Grade {i+1}: "))
        grades.append(grade)
    return student, grades

def calculate_average(grades):
    return sum(grades) / len(grades)

def save_data(filename, data):
    with open(filename, "a") as file:
        for student, grades, avg in data:
            file.write(f"{student}: Grades: {grades}, Average: {avg:.2f}\n")

students_data = []
num_students = int(input("How many students? "))
for _ in range(num_students):
    name, grades = get_student_data()
    avg = calculate_average(grades)
    students_data.append((name, grades, avg))

save_data("StudentGrades.txt", students_data)
print("Student data saved successfully.")

Extended Task 2: Contact Book

Build a CLI contact manager with add/search/update/delete and simple persistence (optional).

View Sample Solution
contacts = {}

def add_contact():
    name = input("Enter contact name: ")
    phone = input("Enter phone number: ")
    email = input("Enter email address: ")
    contacts[name] = {"phone": phone, "email": email}
    print("Contact added.")

def search_contact():
    name = input("Enter name to search: ")
    if name in contacts:
        print("Contact found:", contacts[name])
    else:
        print("Contact not found.")

def update_contact():
    name = input("Enter the name of the contact to update: ")
    if name in contacts:
        phone = input("Enter new phone number: ")
        email = input("Enter new email address: ")
        contacts[name] = {"phone": phone, "email": email}
        print("Contact updated.")
    else:
        print("Contact not found.")

def delete_contact():
    name = input("Enter the name of the contact to delete: ")
    if name in contacts:
        contacts.pop(name)
        print("Contact deleted.")
    else:
        print("Contact not found.")

while True:
    print("\nOptions: add, search, update, delete, quit")
    choice = input("Select an option: ").lower()
    if choice == "add":
        add_contact()
    elif choice == "search":
        search_contact()
    elif choice == "update":
        update_contact()
    elif choice == "delete":
        delete_contact()
    elif choice == "quit":
        break
    else:
        print("Invalid option.")

Extended Task 3: Expense Tracker

Track expenses by category, output a summary, and save to file.

View Sample Solution
expenses = {}

def add_expense():
    category = input("Enter expense category (e.g., food, travel): ").lower()
    amount = float(input("Enter expense amount: "))
    if category in expenses:
        expenses[category] += amount
    else:
        expenses[category] = amount

def save_expenses(filename):
    with open(filename, "w") as file:
        for category, total in expenses.items():
            file.write(f"{category}: {total:.2f}\n")

while True:
    add_expense()
    cont = input("Add another expense? (yes/no): ").strip().lower()
    if cont != "yes":
        break

print("\nExpense Summary:")
for cat, total in expenses.items():
    print(f"{cat.capitalize()}: £{total:.2f}")

save_expenses("Expenses.txt")
print("Expenses saved to Expenses.txt")

Extended Task 4: AI-Powered Chatbot (Simulated)

Simple keyword-based responses (optionally integrate a real API later).

View Sample Solution
# Simulated keyword-based chatbot
responses = {
    "hello": "Hi there! How can I help you today?",
    "price": "Our products are competitively priced.",
    "order": "You can place your order online or by phone.",
    "thanks": "You're welcome!"
}

def get_response(message):
    message = message.lower()
    for key, response in responses.items():
        if key in message:
            return response
    return "I'm not sure I understand. Could you rephrase?"

print("Welcome to Tech Chatbot!")
while True:
    user_input = input("You: ")
    if user_input.lower() in ["exit", "quit"]:
        print("Chatbot: Goodbye!")
        break
    reply = get_response(user_input)
    print("Chatbot:", reply)

Extended Task 5: Inventory Management System

Add/update/remove items and view a formatted inventory.

View Sample Solution
inventory = {}

def add_item():
    item = input("Enter item name: ")
    quantity = int(input("Enter quantity: "))
    inventory[item] = inventory.get(item, 0) + quantity

def update_item():
    item = input("Enter item name to update: ")
    if item in inventory:
        new_qty = int(input("Enter new quantity: "))
        inventory[item] = new_qty
    else:
        print("Item not found.")

def remove_item():
    item = input("Enter item name to remove: ")
    if item in inventory:
        inventory.pop(item)
        print(item, "has been removed.")
    else:
        print("Item not found.")

def display_inventory():
    print("\nCurrent Inventory:")
    for item, qty in inventory.items():
        print(f"{item}: {qty}")

while True:
    print("\nOptions: add, update, remove, display, quit")
    action = input("Choose an action: ").lower()
    if action == "add":
        add_item()
    elif action == "update":
        update_item()
    elif action == "remove":
        remove_item()
    elif action == "display":
        display_inventory()
    elif action == "quit":
        break
    else:
        print("Invalid option.")

Extended Task 6: Tech T-Shirt Shop Order System

Validate quantities, compute totals, confirm order, and print a receipt.

  • Quantities for S/M/L (1–50)
  • Prices: S £15.99, M £17.99, L £19.99
  • Re-enter if not satisfied
View Sample Solution
def get_quantity(size):
    while True:
        try:
            qty = int(input(f"Enter quantity for {size} T-shirts (1-50): "))
            if 1 <= qty <= 50:
                return qty
            else:
                print("Quantity must be between 1 and 50. Please try again.")
        except ValueError:
            print("Invalid input. Please enter a whole number.")

prices = {"Small": 15.99, "Medium": 17.99, "Large": 19.99}

while True:
    print("\n--- Welcome to Tech T-Shirt Shop ---")
    small_qty = get_quantity("Small")
    medium_qty = get_quantity("Medium")
    large_qty = get_quantity("Large")

    total_small = small_qty * prices["Small"]
    total_medium = medium_qty * prices["Medium"]
    total_large = large_qty * prices["Large"]
    total_order = total_small + total_medium + total_large

    print("\nOrder Summary:")
    print(f"Small T-shirts:  {small_qty} x £{prices['Small']:.2f}  = £{total_small:.2f}")
    print(f"Medium T-shirts: {medium_qty} x £{prices['Medium']:.2f} = £{total_medium:.2f}")
    print(f"Large T-shirts:  {large_qty} x £{prices['Large']:.2f}  = £{total_large:.2f}")
    print(f"Total Order: £{total_order:.2f}")

    confirm = input("\nAre you happy with this order? (yes/no): ").strip().lower()
    if confirm == "yes":
        print("\nThank you for your order! Here is your receipt:")
        print("-" * 40)
        print(f"Small T-shirts:  {small_qty} x £{prices['Small']:.2f}  = £{total_small:.2f}")
        print(f"Medium T-shirts: {medium_qty} x £{prices['Medium']:.2f} = £{total_medium:.2f}")
        print(f"Large T-shirts:  {large_qty} x £{prices['Large']:.2f}  = £{total_large:.2f}")
        print("-" * 40)
        print(f"Total Amount: £{total_order:.2f}")
        break
    else:
        print("\nLet's re-enter your order. Please try again.")