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
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
90 changes: 90 additions & 0 deletions Sales_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Python Tasks Implementation

# 1. Create lists/dictionaries to simulate new order data
new_orders = [
{
'customer': {'id': 6, 'name': 'Bola Adekunle', 'email': 'bola@example.com'},
'order_date': '2025-06-05',
'items': [
{'product_id': 1, 'name': 'Phone', 'price': '2.99', 'quantity': 3},
{'product_id': 5, 'name': 'Chicken', 'price': '5.99', 'quantity': 2}
]
},
{
'customer': {'id': 7, 'name': 'Yemi Alade', 'email': 'yemi@example.com'},
'order_date': '2025-06-06',
'items': [
{'product_id': 3, 'name': 'Eggs', 'price': '3.49', 'quantity': 5}
]
}
]

# 2. Use if, and, or to identify customers who placed large orders
print("Customers with large orders:")
for order in new_orders:
total = sum(float(item['price']) * item['quantity'] for item in order['items'])
if total > 15 or (order['customer']['name'].startswith('B') and total > 10):
print(f"{order['customer']['name']} placed a large order worth ${total:.2f}")

# 3. Convert product prices from string to float and apply discounts
print("\nApplying 10% discount to all products:")
for order in new_orders:
for item in order['items']:
original_price = float(item['price'])
discounted_price = original_price * 0.9 # 10% discount
item['price'] = str(discounted_price)
print(f"{item['name']}: ${original_price:.2f} → ${discounted_price:.2f}")

# 4. Create a dictionary report summarizing sales
def generate_sales_report(orders):
report = {
'total_products_sold': 0,
'products': {},
'customers': {},
'most_popular_product': {'name': '', 'quantity': 0},
'total_revenue': 0.0
}

for order in orders:
customer_name = order['customer']['name']
if customer_name not in report['customers']:
report['customers'][customer_name] = {'total_spent': 0.0, 'items': 0}

for item in order['items']:
# Update product stats
product_name = item['name']
quantity = item['quantity']
price = float(item['price'])

if product_name not in report['products']:
report['products'][product_name] = 0
report['products'][product_name] += quantity

# Update customer stats
report['customers'][customer_name]['total_spent'] += price * quantity
report['customers'][customer_name]['items'] += quantity

# Update totals
report['total_products_sold'] += quantity
report['total_revenue'] += price * quantity

# Check for most popular product
if report['products'][product_name] > report['most_popular_product']['quantity']:
report['most_popular_product'] = {'name': product_name, 'quantity': report['products'][product_name]}

return report

# Generate and display the report
sales_report = generate_sales_report(new_orders)
print("\nSales Report:")
print(f"Total products sold: {sales_report['total_products_sold']}")
print(f"Most popular product: {sales_report['most_popular_product']['name']} ({sales_report['most_popular_product']['quantity']} units)")
print(f"Total revenue: ${sales_report['total_revenue']:.2f}")

print("\nRevenue by customer:")
for customer, data in sales_report['customers'].items():
print(f"{customer}: ${data['total_spent']:.2f} (for {data['items']} items)")

print("\nProducts sold:")
for product, quantity in sales_report['products'].items():
print(f"{product}: {quantity} units")
99 changes: 99 additions & 0 deletions Student_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Initialize a global list to store all students
students = []

def add_student():
"""
Adds students to the database until user enters 'stop'
"""
print("\nAdd Student Mode (enter 'stop' as name to finish)")

while True:
print("\nPlease enter student information:")
name = input("Name: ")

if name.lower() == 'stop':
print("\nStudent registration completed!")
break

age = input("Age: ")

# Validate grade input
while True:
grade = input("Grade (0-100): ")
try:
grade = float(grade)
if 0 <= grade <= 100:
break
else:
print("Grade must be between 0 and 100!")
except ValueError:
print("Please enter a valid number for grade!")

# Add student to global list
students.append({
"name": name,
"age": age,
"grade": grade
})

print(f"\nStudent {name} added successfully!")
print(f"Total students: {len(students)}")

def view_students():
"""
Displays all students in the database
"""
if not students:
print("\nNo students in the database!")
return

print("\nSTUDENT DATABASE")
print("=" * 40)
for i, student in enumerate(students, 1):
print(f"\nStudent #{i}")
print(f"Name: {student['name']}")
print(f"Age: {student['age']}")
print(f"Grade: {student['grade']}")
print("\n" + "=" * 40)
print(f"Total students: {len(students)}")

def get_average_grade():
"""
Calculates and returns the average grade
"""
if not students:
return 0.0

total = sum(student['grade'] for student in students)
return total / len(students)

def main_menu():
"""
Main program interface
"""
while True:
print("\n" + "=" * 30)
print("STUDENT MANAGEMENT SYSTEM")
print("=" * 30)
print("\n1. Add Students")
print("2. View All Students")
print("3. View Average Grade")
print("4. Exit")

choice = input("\nEnter your choice (1-4): ")

if choice == '1':
add_student()
elif choice == '2':
view_students()
elif choice == '3':
avg = get_average_grade()
print(f"\nAverage Grade: {avg:.2f}")
elif choice == '4':
print("\nThank you for using the system. Goodbye!")
break
else:
print("\nInvalid choice! Please enter 1-4")

if __name__ == "__main__":
main_menu()
2 changes: 2 additions & 0 deletions _Task 5-- Total orders_.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"total_orders"
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"order_id","order_date"
1,"2025-06-01"
3,"2025-06-03"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"total_revenue"
44.830000000000005
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"customer_name","order_date","product_name","quantity","price","item_total"
Kola Aderoju,"2025-06-01",Phone,2,2.99,5.98
Kola Aderoju,"2025-06-01",Cars,1,1.99,1.99
Ishola Rokibat,"2025-06-02",Eggs,1,3.49,3.49
Ishola Rokibat,"2025-06-02",Corn,5,0.99,4.95
Kola Aderoju,"2025-06-03",Chicken,2,5.99,11.98
Oladele Joseph,"2025-06-03",Phone,3,2.99,8.97
Omotosho Mubarak,"2025-06-04",Cars,2,1.99,3.98
Omotosho Mubarak,"2025-06-04",Eggs,1,3.49,3.49
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"product_name","price","total_quantity_sold","total_revenue"
Cars,1.99,3,5.97
Chicken,5.99,2,11.98
Corn,0.99,5,4.95
Eggs,3.49,2,6.98
Phone,2.99,5,14.950000000000001
1 change: 1 addition & 0 deletions first-semester-projects
Submodule first-semester-projects added at 38d49c
Empty file added postgres
Empty file.
106 changes: 106 additions & 0 deletions second_examination.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- Task 1: Creating the tables
CREATE TABLE customers (
customer_id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT,
join_date DATE NOT NULL
);

CREATE TABLE products (
product_id INT PRIMARY KEY,
name TEXT NOT NULL,
price REAL NOT NULL,
category TEXT
);

CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);

CREATE TABLE order_items (
item_id INT PRIMARY KEY,
order_id INT,
product_id INT,
quantity INT,
FOREIGN KEY (order_id) REFERENCES orders(order_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);

-- Task 2: Altering one of the tables to add a new column
ALTER TABLE products ADD COLUMN stock INTEGER DEFAULT 0;

-- Task 3: Inserting at 5 rows into each table

-- Insert customers
INSERT INTO customers VALUES
(1, 'Kola Aderoju', 'kolaaderoju@example.com', '2025-01-15'),
(2, 'Ishola Rokibat', 'isholarokibat@example.com', '2025-02-20'),
(3, 'Oladele Joseph', 'josephola@example.com', '2025-03-10'),
(4, 'Omotosho Mubarak', 'omotoshomubarak@example.com', '2025-04-05'),
(5, 'Abiade Zainab', 'abiadezainab@example.com', '2025-05-12');

-- Insert products
INSERT INTO products VALUES
(1, 'Phone', 2.99, 'Telecommunications', 50),
(2, 'Cars', 1.99, 'Automobiles', 100),
(3, 'Eggs', 3.49, 'Dairy', 75),
(4, 'Corn', 0.99, 'Cereals', 200),
(5, 'Chicken', 5.99, 'Meat', 30);

-- Insert orders
INSERT INTO orders VALUES
(1, 1, '2025-06-01'),
(2, 2, '2025-06-02'),
(3, 1, '2025-06-03'),
(4, 3, '2025-06-03'),
(5, 4, '2025-06-04');

-- Insert order items
INSERT INTO order_items VALUES
(1, 1, 1, 2),
(2, 1, 2, 1),
(3, 2, 3, 1),
(4, 2, 4, 5),
(5, 3, 5, 2),
(6, 4, 1, 3),
(7, 5, 2, 2),
(8, 5, 3, 1);

-- Task 4: Retrieving all orders made by a specific customer
SELECT o.order_id, o.order_date
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE c.name = 'Kola Aderoju';

-- Task 5: Get the total number of orders
SELECT COUNT(*) AS total_orders FROM orders;

-- Task 6: Calculate the total revenue from all orders
SELECT SUM(p.price * oi.quantity) AS total_revenue
FROM order_items oi
JOIN products p ON oi.product_id = p.product_id;

-- Task 7: Using INNER JOIN to show order details including customer and product names
SELECT c.name AS customer_name,
o.order_date,
p.name AS product_name,
oi.quantity,
p.price,
(p.price * oi.quantity) AS item_total
FROM order_items oi
JOIN orders o ON oi.order_id = o.order_id
JOIN customers c ON o.customer_id = c.customer_id
JOIN products p ON oi.product_id = p.product_id;

-- Task 8: Using LEFT JOIN to show all products and any related order (even if not sold)
SELECT p.name AS product_name,
p.price,
COALESCE(SUM(oi.quantity), 0) AS total_quantity_sold,
COALESCE(SUM(p.price * oi.quantity), 0) AS total_revenue
FROM products p
LEFT JOIN order_items oi ON p.product_id = oi.product_id
GROUP BY p.name, p.price;