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
Binary file not shown.
3 changes: 2 additions & 1 deletion month1_student_management/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
elif choice == "2":
view_students()
elif choice == "3":
print(f"📊 Average Grade: {get_average_grade():.2f}")
get_average_grade()
# print(f"📊 Average Grade: {get_average_grade():.2f}")
elif choice == "4":
print("Goodbye!")
break
Expand Down
68 changes: 54 additions & 14 deletions month1_student_management/student_data.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,60 @@
students = []

grades = ['A', 'B', 'C', 'D', 'E', 'F']
gradeValues = {
'A' : 5.00, 'B':4.00, 'C':3.00, 'D':2.00,'E':1.00,'F':0.00
}
# Prompt the user to enter student name, age, and grade.
# Append the student as a dictionary to the students list.
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
name = input('Enter Student name: ').title()
age = int(input ('Enter the age: '))
while True:
grade = input('Enter the grade (A-F): ').upper()
if grade in grades:
break
print("Invalid grade, enter between A to F")

student= {
'name': name,
'age' : age,
'grade': grade
}
students.append(student)
print(f"Student with details: '{name}', age '{age}' and grade '{grade}' added successfully!")


# Loop through the students list and print each student's info.
def view_students():
"""
TODO: Loop through the students list and print each student's info.
"""
pass
if not students:
print("Oops! Students list Empty")
else:
print("\n STUDENTS LIST ")
for index, student in enumerate(students, start = 1):
print (f"{index}. {student} ")


# Return the average grade of all students.
def get_average_grade():
"""
TODO: Return the average grade of all students.
"""
pass
if not students:
print('No students in the list to calculate average grade!\n')
else:
total = 0
for student in students:
total += gradeValues[student['grade']]

average = total/len(students)
#Converting to grade
if average >= 4.50:
averageGrade = 'A'
elif average >= 3.50:
averageGrade = 'B'
elif average >= 3.00:
averageGrade ='C'
elif average >= 2.00:
averageGrade ='D'
elif average >= 1.00:
averageGrade ='E'
else :
averageGrade ='F'
print(f"\n Average letter Grade is:{averageGrade}")
print(f"\n Average number Grade is:{average:.2f}")
Binary file not shown.
Binary file not shown.
56 changes: 56 additions & 0 deletions month2_minimart_analysis/python/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
# Entry point for the MiniMart data reporting system
from utils import convert_currency, apply_discount, flag_large_orders
from report_generator import generate_report, print_report
products = [
{'product_id': 1, 'product_name': '50g peak Milk', 'category': 'Dairy', 'price': 5000.00},
{'product_id': 2, 'product_name': 'Bokku Bread', 'category': 'Bakery', 'price': 1300.00},
{'product_id': 3, 'product_name': 'Egg', 'category': 'Dairy', 'price': 300.00},
{'product_id': 4, 'product_name': 'Apples', 'category': 'fruit', 'price': 1000.00},
{'product_id': 5, 'product_name': 'Coke 50cl', 'category': 'Drinks', 'price': 500.00},
{'product_id': 6, 'product_name': 'Table water', 'category': 'Drinks', 'price': 200.00}
]

customers = [
{'customer_id': 1, 'name': 'Opeyemi Ayeni', 'email': '[email protected]','date':'2023-01-15','phone':'08165114690' },
{'customer_id': 2, 'name': 'Michael Chinedu', 'email': '[email protected]','date':'2023-02-20','phone':'08166004690'},
{'customer_id': 3, 'name': 'Emma Orunkoyi', 'email': '[email protected]','date':'2023-05-05','phone':'08175114690'},
{'customer_id': 4, 'name': 'Kim Dave', 'email': '[email protected]','date':'2023-05-05','phone':'08175114690'},
{'customer_id': 5, 'name': 'Ayeni Moyinoluwa', 'email': '[email protected]','date':'2023-06-17','phone':'08165114100'}
]

# Simulate new orders
orders = [
{'customer_id': 1, 'product_id': 3, 'quantity': 2, 'order_date': '2023-11-01'},
{'customer_id': 2, 'product_id': 1, 'quantity': 1, 'order_date': '2024-10-02'},
{'customer_id': 3, 'product_id': 4, 'quantity': 3, 'order_date': '2023-11-02'},
{'customer_id': 1, 'product_id': 2, 'quantity': 2, 'order_date': '2024-11-03'},
{'customer_id': 4, 'product_id': 5, 'quantity': 6, 'order_date': '2024-11-03'},
{'customer_id': 5, 'product_id': 6, 'quantity': 15, 'order_date': '2024-11-04'} # New large order
]

# Process orders
for order in orders:
product = next(p for p in products if p['product_id'] == order['product_id'])
original_price = product['price']

# Convert to USD (assuming 1 USD = 1500 Naira)
usd_price = convert_currency(original_price, 1/1500)

# Apply quantity discount
discounted_price = apply_discount(original_price, order['quantity'])

# Calculate total
order['total'] = discounted_price * order['quantity']
order['original_total'] = original_price * order['quantity']
order['usd_total'] = convert_currency(order['total'], 1/1500)

# Flag large orders
orders = flag_large_orders(orders, threshold=500)

# Generate and display report
report = generate_report(orders, products, customers)
print_report(report)

# Saving report to JSON
from utils import save_to_json
save_to_json(report, 'minimart_report.json')
print("\nReport saved to 'minimart_report.json'")
76 changes: 76 additions & 0 deletions month2_minimart_analysis/python/report_generator.py
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
# Code to generate dictionary summary reports
from typing import Dict, List
from utils import save_to_json

def generate_report(orders: List[Dict], products: List[Dict], customers: List[Dict]) -> Dict:
"Generating a comprehensive sales report"
# Initialize report dictionary
report = {
'total_products_sold': 0,
'most_popular_product': None,
'revenue_per_customer': [],
'total_revenue': 0
}

# Return empty report if no orders exist
if not orders:
return report

# Calculate total products sold
report['total_products_sold'] = sum(order['quantity'] for order in orders)

# Find most popular product
product_sales = {}
for order in orders:
product_id = order['product_id']
product_sales[product_id] = product_sales.get(product_id, 0) + order['quantity']

if product_sales: # Only try to find most popular if there are sales
most_popular_product_id = max(product_sales, key=product_sales.get)
most_popular_product = next(
p for p in products if p['product_id'] == most_popular_product_id
)
report['most_popular_product'] = {
'product_id': most_popular_product['product_id'],
'product_name': most_popular_product['product_name'],
'quantity_sold': product_sales[most_popular_product_id]
}
# Calculate revenue per customer
revenue_per_customer = {}
for order in orders:
customer_id = order['customer_id']
revenue = order['total']
revenue_per_customer[customer_id] = revenue_per_customer.get(customer_id, 0) + revenue

return {
'total_products_sold': total_products_sold,
'most_popular_product': {
'product_id': most_popular_product['product_id'],
'product_name': most_popular_product['product_name'],
'quantity_sold': product_sales[most_popular_product_id]
},
'revenue_per_customer': [
{
'customer_id': cust_id,
'revenue': revenue,
'customer_name': next(
c['name'] for c in customers if c['customer_id'] == cust_id
)
}
for cust_id, revenue in revenue_per_customer.items()
],
'total_revenue': sum(revenue_per_customer.values())
}

def print_report(report: Dict) -> None:
"Print a nicely formatted report summary"
print("\n=== MINIMART SALES REPORT ===")
print(f"Total Products Sold: {report['total_products_sold']}")
print(f"\nMost Popular Product:")
print(f" - Name: {report['most_popular_product']['product_name']}")
print(f" - Quantity Sold: {report['most_popular_product']['quantity_sold']}")

print("\nRevenue by Customer:")
for customer in report['revenue_per_customer']:
print(f" - {customer['customer_name']}: ₦{customer['revenue']:.2f}")

print(f"\nTotal Revenue: ₦{report['total_revenue']:.2f}")
25 changes: 25 additions & 0 deletions month2_minimart_analysis/python/utils.py
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# Utility functions for data conversion and filtering
import json
from typing import Dict, List, Tuple

def convert_currency(price: float, exchange_rate: float) -> float:
"Convert product price to another currency"
return round(price * exchange_rate, 2)

def apply_discount(price: float, quantity: int) -> float:
"Apply conditional discount based on quantity"
if quantity > 10:
return price * 0.9 # 10% discount for bulk orders
elif quantity > 5:
return price * 0.95 # 5% discount for medium orders
return price

def flag_large_orders(orders: List[Dict], threshold: float = 500) -> List[Dict]:
"Flag orders with total amount exceeding threshold"
for order in orders:
order['is_large_order'] = order['total'] > threshold
return orders

def save_to_json(data: Dict, filename: str) -> None:
"Saving report data to JSON file"
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
25 changes: 25 additions & 0 deletions month2_minimart_analysis/sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
-- SQL script to create necessary tables
create table customers(
customer_id serial primary key,
name varchar(100) not null,
email varchar(100) unique,
join_date date default current_date
);
alter table customers add column phone VARCHAR(11);
--alter table customers to add phone number

create table products(
product_id serial primary key,
product_name VARCHAR(100) not null,
category VARCHAR(50) not null,
price decimal(10,2) not null check(price > 0)
);

create table orders(
order_id serial primary key,
customer_id int not null,
product_id int not null,
quantity int not null,
order_date date not null,
foreign key(customer_id) references customers(customer_id)on delete restrict,
foreign key(product_id) references products(product_id)on delete restrict
);
21 changes: 21 additions & 0 deletions month2_minimart_analysis/sql/insert_data.sql
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
-- SQL script to insert sample data
INSERT INTO customers (name, email, join_date, phone) VALUES
('Opeyemi Ayeni', '[email protected]', '2023-01-15','08165114690'),
('Michael Chinedu', '[email protected]', '2023-02-20','08166004690'),
('Emma Orunkoyi', '[email protected]', '2023-05-05','08175114690'),
('Kim Dave', '[email protected]', '2023-04-10','07065114690'),
('Ayeni Moyinoluwa', '[email protected]','2025-06-17','08165114100' );

INSERT INTO products (product_name, category, price) VALUES
('50g peak Milk', 'Dairy', 5000.00),
('Bokku Bread', 'Bakery', 1300.00),
('Egg', 'Dairy', 300.00),
('Apples', 'fruit', 1000.00),
('Coke 50cl', 'Drinks', 500.00),
('Table water', 'Drinks', 200.00);

INSERT INTO orders (customer_id, product_id, quantity, order_date) VALUES
(1, 3, 2, '2023-11-01'),
(2, 1, 1, '2024-10-02'),
(3, 4, 3, '2023-11-02'),
(1, 2, 2, '2024-11-03'),
(4, 5, 6, '2024-11-03');
37 changes: 37 additions & 0 deletions month2_minimart_analysis/sql/queries.sql
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
-- SQL queries for retrieving insights

--Basic queries
select * from customers;
select * from products where category = 'Dairy';
select * from orders order by order_date desc;

--Aggregation
select count(*) as Total_Orders from orders;

--Using SUM() to calculate revenue per product (price × quantity)
select p.product_id,p.product_name,sum (p.price * o.quantity)
as product_revenue
from products p join orders o on p.product_id = o.product_id
group by p.product_id
order by product_revenue desc;

--Using AVG() to find the average product price
select avg(price) as average_product_price from products;

--Joins
--Using INNER JOIN to get detailed order information (with customer and product details).
select o.order_id, c.name as Customer_name,email,p.product_name,price,quantity, (p.price*o.quantity) as Total, order_date
from customers c
inner join orders o on c.customer_id = o.customer_id
inner join products p on p.product_id = o.product_id
order by order_date desc;

--Using LEFT JOIN to list all customers and include their orders (if any)
select c.customer_id,name,email,o.order_id,quantity, order_date
from customers c
left join orders o on c.customer_id = o.customer_id
order by name desc;

--Using LEFT JOIN to show products even if they haven’t been ordered.
select p.product_id,p.product_name
from products p
left join orders o on p.product_id = o.product_id;