diff --git a/month1_student_management/main.py b/month1_student_management/main.py index 2ce37ee..aacac6d 100644 --- a/month1_student_management/main.py +++ b/month1_student_management/main.py @@ -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.") \ No newline at end of file +from student_data import main +if __name__ == "__main__": + main() + diff --git a/month1_student_management/student_data.py b/month1_student_management/student_data.py index 38ded7e..7bbb410 100644 --- a/month1_student_management/student_data.py +++ b/month1_student_management/student_data.py @@ -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 \ No newline at end of file + \ No newline at end of file diff --git a/month2_minimart_analysis/python/__pycache__/report_generator.cpython-313.pyc b/month2_minimart_analysis/python/__pycache__/report_generator.cpython-313.pyc new file mode 100644 index 0000000..327f995 Binary files /dev/null and b/month2_minimart_analysis/python/__pycache__/report_generator.cpython-313.pyc differ diff --git a/month2_minimart_analysis/python/__pycache__/utils.cpython-313.pyc b/month2_minimart_analysis/python/__pycache__/utils.cpython-313.pyc new file mode 100644 index 0000000..c52c870 Binary files /dev/null and b/month2_minimart_analysis/python/__pycache__/utils.cpython-313.pyc differ diff --git a/month2_minimart_analysis/python/customers.csv b/month2_minimart_analysis/python/customers.csv new file mode 100644 index 0000000..866748a --- /dev/null +++ b/month2_minimart_analysis/python/customers.csv @@ -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 diff --git a/month2_minimart_analysis/python/main.py b/month2_minimart_analysis/python/main.py index 583f1c8..27bf516 100644 --- a/month2_minimart_analysis/python/main.py +++ b/month2_minimart_analysis/python/main.py @@ -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}") diff --git a/month2_minimart_analysis/python/order_items.csv b/month2_minimart_analysis/python/order_items.csv new file mode 100644 index 0000000..66f9adf --- /dev/null +++ b/month2_minimart_analysis/python/order_items.csv @@ -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 diff --git a/month2_minimart_analysis/python/orders.csv b/month2_minimart_analysis/python/orders.csv new file mode 100644 index 0000000..eefbb0d --- /dev/null +++ b/month2_minimart_analysis/python/orders.csv @@ -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, diff --git a/month2_minimart_analysis/python/products.csv b/month2_minimart_analysis/python/products.csv new file mode 100644 index 0000000..ac5ab38 --- /dev/null +++ b/month2_minimart_analysis/python/products.csv @@ -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 diff --git a/month2_minimart_analysis/python/report_generator.py b/month2_minimart_analysis/python/report_generator.py index fb6ddb8..a0b5a5e 100644 --- a/month2_minimart_analysis/python/report_generator.py +++ b/month2_minimart_analysis/python/report_generator.py @@ -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 + } \ No newline at end of file diff --git a/month2_minimart_analysis/python/utils.py b/month2_minimart_analysis/python/utils.py index 7049a76..612c368 100644 --- a/month2_minimart_analysis/python/utils.py +++ b/month2_minimart_analysis/python/utils.py @@ -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']}") diff --git a/month2_minimart_analysis/sql/Script-18.sql b/month2_minimart_analysis/sql/Script-18.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-19.sql b/month2_minimart_analysis/sql/Script-19.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-20.sql b/month2_minimart_analysis/sql/Script-20.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-21.sql b/month2_minimart_analysis/sql/Script-21.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-22.sql b/month2_minimart_analysis/sql/Script-22.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-23.sql b/month2_minimart_analysis/sql/Script-23.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-24.sql b/month2_minimart_analysis/sql/Script-24.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-25.sql b/month2_minimart_analysis/sql/Script-25.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/Script-6.sql b/month2_minimart_analysis/sql/Script-6.sql new file mode 100644 index 0000000..e69de29 diff --git a/month2_minimart_analysis/sql/create_tables.sql b/month2_minimart_analysis/sql/create_tables.sql deleted file mode 100644 index 1411bac..0000000 --- a/month2_minimart_analysis/sql/create_tables.sql +++ /dev/null @@ -1 +0,0 @@ --- SQL script to create necessary tables diff --git a/month2_minimart_analysis/sql/insert_data.sql b/month2_minimart_analysis/sql/insert_data.sql deleted file mode 100644 index 97dc4da..0000000 --- a/month2_minimart_analysis/sql/insert_data.sql +++ /dev/null @@ -1 +0,0 @@ --- SQL script to insert sample data diff --git a/month2_minimart_analysis/sql/queries.sql b/month2_minimart_analysis/sql/queries.sql deleted file mode 100644 index 883d8ae..0000000 --- a/month2_minimart_analysis/sql/queries.sql +++ /dev/null @@ -1 +0,0 @@ --- SQL queries for retrieving insights