Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions month1_student_management/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# Entry point for the student management system
from student_data import students, add_student, view_students, get_average_grade

print("📚 Welcome to the Student Record System")

while True:
print("\n1. Add student\n2. View students\n3. Get average grade\n4. Exit")
choice = input("Choose an option: ")

if choice == "1":
add_student()
elif choice == "2":
view_students()
elif choice == "3":
print(f"📊 Average Grade: {get_average_grade():.2f}")
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid option.")
from student_data import main
if __name__ == "__main__":
main()

107 changes: 91 additions & 16 deletions month1_student_management/student_data.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,95 @@
students = []

def add_student():
"""
TODO: Prompt the user to enter student name, age, and grade.
Append the student as a dictionary to the students list.
"""
pass

while True:
name = input("Enter student name: ")
marks = int(input("Enter student marks: "))
student = {"name": name, "marks":marks}
students.append(student)
print(f"{name} has been added.\n")
another = input("Do you want to add another student? (yes/no): ").strip().lower()
if another != "yes":
break
def view_students():
"""
TODO: Loop through the students list and print each student's info.
"""
pass
if len(students) == 0:
print("No students to display.\n")
else:
print("Student List:")
for student in students:
print(f"Name: {student['name']}, marks: {student['marks']}")
print()
def get_average_marks():
if len(students) == 0:
print("No students to calculate average grade.\n")
return 0
total_marks = sum(student['marks'] for student in students)
average_marks = total_marks / len(students)
return average_marks
def convert_marks_to_grade(mark):
if mark >= 90:
return "A"
elif mark >= 85:
return "A-"
elif mark >= 80:
return "B+"
elif mark >= 75:
return "B"
elif mark >= 70:
return "B-"
elif mark >= 65:
return "C+"
elif mark >= 60:
return "C"
elif mark >= 55:
return "C-"
elif mark >= 50:
return "D+"
elif mark >= 45:
return "D"
elif mark >= 40:
return "D-"
else:
return "F"
def show_class_statistics():
if len(students) == 0:
print("No students to show statistics.\n")
return
average = get_average_marks()
average_grade = convert_marks_to_grade(average)
print("=== Class Statistics ===")
print(f"Total Students: {len(students)}")
print(f"Average Marks: {average:.2f} (Grade: {average_grade})")
def main():
print("Welcome to Student Data Management System!")
while True:
print("\nMenu Options:")
print("1. Add Student")
print("2. View All Students")
print("3. Show Class Statistics")
print("4. Exit")
try:
choice = input("\nEnter your choice (1-4): ").strip()
if choice == "1":
add_student()
elif choice == "2":
view_students()
elif choice == "3":
show_class_statistics()
elif choice == "4":
print("Thank you for using Student Data Management System!")
print("Goodbye!")
break
else:
print("Invalid choice! Please enter a number between 1 and 4.\n")

except KeyboardInterrupt:
print("\n\nProgram interrupted. Goodbye!")
break
except Exception as e:
print(f"An error occurred: {e}")
print("Please try again.\n")

if __name__ == "__main__":
main()


def get_average_grade():
"""
TODO: Return the average grade of all students.
"""
pass

Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions month2_minimart_analysis/python/customers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"customer_id","name","phone","email","address","loyalty_points"
1,Achieng Otieno,"0721123456",achieng.otieno@gmail.com,Kisumu,0
2,James Mwangi,"0722123456",jamesmwangi@yahoo.com,Nairobi,0
3,Fatuma Hassan,"0733123456",fatuma.hassan@gmail.com,Mombasa,0
4,Brian Kipkoech,"0744123456",kipkoech.brian@yahoo.com,Eldoret,0
5,Grace Wambui,"0755123456",grace.wambui@gmail.com,Nakuru,0
6,Kevin Ndung’u,"0716123456",kevin.ndungu@gmail.com,Thika,0
7,Beatrice Atieno,"0707123456",beatrice.atieno@yahoo.com,Kisii,0
8,Mohammed Abdi,"0768123456",mohammed.abdi@gmail.com,Garissa,0
9,Sharon Njeri,"0729123456",sharon.njeri@gmail.com,Meru,0
10,Daniel Mutua,"0790123456",daniel.mutua@yahoo.com,Kitui,110
11 changes: 10 additions & 1 deletion month2_minimart_analysis/python/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Entry point for the MiniMart data reporting system
import pandas as pd
from report_generator import generate_report
from utils import apply_discount, load_csvs
customers, products, orders, order_items = load_csvs()
products["price"] = products["price"].astype(str)
products["discounted_price"] = products["price"].apply(lambda p: apply_discount(p, 10))
report = generate_report(customers, products, orders, order_items)
print("\n\U0001F4CA MiniMart Sales Report:")
for key, value in report.items():
print(f"{key}: {value}")
11 changes: 11 additions & 0 deletions month2_minimart_analysis/python/order_items.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"order_item_id","order_id","product_id","quantity","unit_price","total_price"
1,1,1,2,150.00,300.00
2,1,2,1,60.00,60.00
3,2,3,3,50.00,150.00
4,3,5,2,140.00,280.00
5,4,6,1,180.00,180.00
6,5,7,4,80.00,320.00
7,6,8,2,160.00,320.00
8,7,9,1,290.00,290.00
9,8,10,2,170.00,340.00
10,9,4,1,120.00,120.00
11 changes: 11 additions & 0 deletions month2_minimart_analysis/python/orders.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"order_id","customer_id","order_date","status","payment_method","shipping_address","delivery_date"
1,1,2025-06-01,Completed,M-Pesa,Kisumu,2025-06-02
2,2,2025-06-02,Completed,Cash,Nairobi,2025-06-03
3,3,2025-06-03,Pending,M-Pesa,Mombasa,
4,4,2025-06-04,Completed,Card,Eldoret,2025-06-05
5,5,2025-06-05,Shipped,M-Pesa,Nakuru,
6,6,2025-06-06,Completed,M-Pesa,Thika,2025-06-07
7,7,2025-06-07,Pending,Cash,Kisii,
8,8,2025-06-08,Completed,M-Pesa,Garissa,2025-06-09
9,9,2025-06-09,Completed,Card,Meru,2025-06-10
10,10,2025-06-10,Shipped,M-Pesa,Kitui,
11 changes: 11 additions & 0 deletions month2_minimart_analysis/python/products.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"product_id","name","price","category","stock_quantity","description"
1,Unga wa Dola (2kg),150.00,Food,100,Maize flour used for making ugali
2,Brookside Milk (500ml),60.00,Dairy,200,Pasteurized fresh milk
3,Royco Mchuzi Mix,50.00,Spices,150,Flavor enhancer for stews and soups
4,Blue Band (250g),120.00,Spreads,80,Popular margarine for breakfast
5,Soko Maize Flour (2kg),140.00,Food,100,Fine maize flour
6,Ketepa Tea (250g),180.00,Beverages,60,Popular Kenyan black tea
7,Menengai Bar Soap,80.00,Cleaning,120,Multipurpose cleaning soap
8,Ajab Wheat Flour (2kg),160.00,Food,90,Flour used for chapati and mandazi
9,Fresh Fry Cooking Oil (1L),290.00,Oil,75,Vegetable cooking oil
10,White Sugar (1kg),170.00,Food,110,Refined sugar used in drinks and baking
20 changes: 19 additions & 1 deletion month2_minimart_analysis/python/report_generator.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Code to generate dictionary summary reports
import pandas as pd

def generate_report(customers, products, orders, order_items):
order_items["total_price"] = order_items["unit_price"] * order_items["quantity"]

total_products_sold = order_items["quantity"].sum()

popular = order_items.groupby("product_id")["quantity"].sum().idxmax()
most_popular = products.loc[products["product_id"] == popular, "name"].values[0]

orders_with_customers = order_items.merge(orders, on="order_id") \
.merge(customers, on="customer_id")
revenue_per_customer = orders_with_customers.groupby("name")["total_price"].sum().to_dict()

return {
"Total Products Sold": total_products_sold,
"Most Popular Product": most_popular,
"Revenue per Customer": revenue_per_customer
}
34 changes: 33 additions & 1 deletion month2_minimart_analysis/python/utils.py
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# Utility functions for data conversion and filtering
import pandas as pd
import os

# Get the absolute directory of this script
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

def apply_discount(price_str, discount_pct):
try:
price = float(price_str)
return price * (1 - discount_pct / 100)
except:
return 0.0

def load_csvs():
customers = pd.read_csv(os.path.join(BASE_DIR, "customers.csv"))
products = pd.read_csv(os.path.join(BASE_DIR, "products.csv"))
orders = pd.read_csv(os.path.join(BASE_DIR, "orders.csv"))
order_items = pd.read_csv(os.path.join(BASE_DIR, "order_items.csv"))
return customers, products, orders, order_items

if __name__ == "__main__":
# Example order
new_order = {
"customer_id": 3,
"products": [
{"product_id": 2, "quantity": 5},
{"product_id": 5, "quantity": 3}
]
}

for item in new_order["products"]:
if item["quantity"] > 4 or (item["product_id"] == 2 and item["quantity"] >= 3):
print(f"Large order alert: Product ID {item['product_id']} - Quantity {item['quantity']}")
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 0 additions & 1 deletion month2_minimart_analysis/sql/create_tables.sql

This file was deleted.

1 change: 0 additions & 1 deletion month2_minimart_analysis/sql/insert_data.sql

This file was deleted.

1 change: 0 additions & 1 deletion month2_minimart_analysis/sql/queries.sql

This file was deleted.