Skip to content

About

🐍 Python programming assessment focusing on algorithmic problem solving, conditional control flow, iterative data processing, and foundational data structures.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

🐍 Python Programming Quiz: Applied Business Logic & Data Transformation (Quiz 01)

Open In Colab Python Version Jupyter Notebook Domain Status

An applied Python coding assessment demonstrating real-world algorithmic logic across e-commerce discount mechanics, ETL string parsing & KYC applicant validation, and enterprise performance-driven payroll compensation modeling.


πŸ“Œ Table of Contents


πŸ“– Overview

In modern analytics engineering, Python is frequently used to transform dirty operational inputs, enforce validation boundaries, and calculate dynamic financial metrics. This repository showcases solutions to 3 realistic enterprise problem domains:

  1. Dynamic Cart Invoicing: Handling multi-tiered discounts, string coupon normalization, and customer tier exemptions.
  2. Data Cleansing & KYC Screening: Splitting raw delimited logs, typecasting, validating integrity, and executing compliance checks.
  3. Incentive Compensation Systems: Multi-variable KPI rate calculations, CSAT score quality gates, and bonus payouts.

🎯 Core Competencies Assessed

  • String Manipulation & Sanitization: Using .strip(), .lower(), .title(), and .split() to parse unstructured or dirty strings into structured variables.
  • Type Safety & Data Integrity: Guarding against casting crashes using .isdigit() prior to numeric conversion.
  • Compound Financial Logic: Applying percentage-based thresholds and compounding promotional incentives.
  • Conditional Quota Attainment: Calculating achievement ratios and segmenting employees into discrete performance tiers.

πŸ’Ό Real-World Scenarios & Solutions

Scenario 1: E-Commerce Dynamic Checkout & Promotion Engine

Business Case: Calculate an order's net checkout total by applying spending threshold discounts (10% on orders $\ge$ 1,000 EGP), verifying promotional coupon codes (save15), and waiving delivery fees for VIP subscribers.

total_spent = 1200.0
promo_code = " save15 "
is_vip = False

# 1. Base threshold discount
base_discount_rate = 0.0
if total_spent >= 1000:
    base_discount_rate = 0.10

# 2. Promo code normalization & application
promo_bonus = 0.0
cleaned_promo = promo_code.strip().lower()
if cleaned_promo == "save15":
    promo_bonus = 0.15

# 3. Discount calculation
total_discount_rate = base_discount_rate + promo_bonus
discount_amount = total_spent * total_discount_rate

# 4. VIP shipping fee policy
shipping_fee = 0.0
if not is_vip:
    shipping_fee = 50.0

final_total = total_spent - discount_amount + shipping_fee

print("=== CUSTOMER CHECKOUT SUMMARY ===")
print("Original Amount : EGP " + str(total_spent))
print("Discount Rate   : " + str(total_discount_rate * 100) + "%")
print("Discount Amount : EGP " + str(discount_amount))
print("Shipping Fee    : EGP " + str(shipping_fee))
print("Final Total     : EGP " + str(final_total))

Console Output:

=== CUSTOMER CHECKOUT SUMMARY ===
Original Amount : EGP 1200.0
Discount Rate   : 25.0%
Discount Amount : EGP 300.0
Shipping Fee    : EGP 50.0
Final Total     : EGP 950.0

Scenario 2: ETL Pipeline: String Parsing, Sanitization & KYC Validation

Business Case: Ingest a raw, pipe-delimited data string representing applicant information (" 8801 | mohamed ali | 24 "), extract constituent fields, clean whitespace, title-case names, validate age datatype, and apply compliance age gates ($\ge 21$).

raw_user_record = " 8801 | mohamed ali | 24 "

# 1. Delimited tokenization & normalization
fields = raw_user_record.split("|")
user_id = fields[0].strip()
full_name = fields[1].strip().title()
age_str = fields[2].strip()

age_value = 0
application_status = ""

# 2. Datatype validation & compliance checks
is_valid_age = age_str.isdigit()
if is_valid_age:
    age_value = int(age_str)
if is_valid_age and age_value >= 21:
    application_status = "APPROVED"
if is_valid_age and age_value < 21:
    application_status = "REJECTED: Underage"
if not is_valid_age:
    application_status = "ERROR: Invalid Age Format"

print("=== APPLICANT VERIFICATION ===")
print("User ID      : " + str(user_id))
print("Full Name    : " + full_name)
print("Age          : " + str(age_value))
print("Application  : " + application_status)

Console Output:

=== APPLICANT VERIFICATION ===
User ID      : 8801
Full Name    : Mohamed Ali
Age          : 24
Application  : APPROVED

Scenario 3: HR & Payroll: KPI Quota Achievement & CSAT Bonus Model

Business Case: Evaluate sales executive performance by calculating quota achievement percentage ($125,000 / $100,000 = 125%$). Assign tier ratings, calculate bonus percentages based on both sales volume and Customer Satisfaction (CSAT $\ge 4.5$), apply penalty deductions for poor service quality, and compute net salary payout.

base_salary = 15000.0
sales_target = 100000.0
sales_achieved = 125000.0
csat_score = 4.8

achievement_rate = sales_achieved / sales_target

performance_rating = "Needs Improvement"
bonus_percentage = 0.0

# Performance tier & bonus tier evaluation
if achievement_rate >= 1.00:
    performance_rating = "Meets Expectations"
    bonus_percentage = 0.10
if achievement_rate >= 1.20 and csat_score >= 4.5:
    performance_rating = "Exceeds Expectations"
    bonus_percentage = 0.20

calculated_bonus = base_salary * bonus_percentage

# Quality penalty thresholding
if csat_score < 3.0:
    calculated_bonus = calculated_bonus * 0.5

total_payout = base_salary + calculated_bonus

print("=== EMPLOYEE PAYROLL EVALUATION ===")
print("Achievement Rate : " + str(achievement_rate * 100) + "%")
print("Performance Tier : " + performance_rating)
print("Calculated Bonus : EGP " + str(calculated_bonus))
print("Total Payout     : EGP " + str(total_payout))

Console Output:

=== EMPLOYEE PAYROLL EVALUATION ===
Achievement Rate : 125.0%
Performance Tier : Exceeds Expectations
Calculated Bonus : EGP 3000.0
Total Payout     : EGP 18000.0

πŸ“Š Business Logic Architecture

Scenario Input Parameters Validation / Logic Gates Output Metrics
1. Checkout Engine Spend, Promo Code, VIP Flag Spend $\ge 1000 \to 10%$, Code == 'save15' $\to +15%$ Net Payable Total
2. KYC ETL Pipeline Pipe-Delimited String Whitespace trim, .isdigit(), Age $\ge 21$ Verification Status Flag
3. Payroll Model Target, Actual Sales, CSAT Score Rate $\ge 1.20 \land \text{CSAT} \ge 4.5 \to 20%$ Bonus Total Compensation

πŸ’» Getting Started & Execution

Option 1: Run Online in Google Colab (Zero Setup)

Click the badge below to run the notebook instantly in Google Colab:

Open In Colab

Option 2: Run Locally via Git & Jupyter

  1. Clone the repository:

    git clone https://github.com/islamyasser424-design/Python-Quiz-01.git
    cd Python-Quiz-01
  2. Launch Jupyter:

    jupyter notebook Python_Quiz_01.ipynb

πŸ‘€ Author & Connect

Islam Yasser
Data Analyst & Business Intelligence Specialist


Part of the Python Programming & Data Analytics Portfolio series. Built with clean code standards and verified business logic.

About

🐍 Python programming assessment focusing on algorithmic problem solving, conditional control flow, iterative data processing, and foundational data structures.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages