Design a multi-tier decision-making system to determine the eligibility criteria for a scholarship.
Tags: python, beginners, programming
Published: 2024-07-12 09:43:21

## Question
Design a multi-tier decision-making system using if-else statements that can be used to determine the eligibility criteria for a scholarship. The system should take into account multiple factors like grades, extracurricular activities, and financial need.

## Thought Process
To design a multi-tier decision-making system for determining scholarship eligibility based on grades, extracurricular activities, and financial need, you need a structured approach to evaluate and assign scholarship amounts. Here’s a step-by-step breakdown of how to create a decision-making system using if-else statements:

### Criteria for Scholarship Decision

- Financial Condition: Determines how financially needy the student is.
- Extracurricular Activities: Measures involvement outside academics.
- Grades: Reflects academic performance.

### Scholarship Decision Logic

- Determine Financial Need: Check if the student falls into high, medium, or low financial need categories.
- Assess Extracurricular Involvement: Within each financial need category, check how active the student is in extracurricular activities.
- Evaluate Grades: Finally, assess the student's grades to decide the exact scholarship amount.

### Scholarship Amounts

- High Need, High Extracurricular, High Grades: Maximum scholarship.
- High Need, Medium Extracurricular, Medium Grades: Moderate scholarship.
- High Need, Low Extracurricular, Low Grades: Minimal scholarship.
- Medium Need, High Extracurricular, High Grades: Substantial scholarship.
- Medium Need, Medium Extracurricular, Medium Grades: Moderate scholarship.
- Medium Need, Low Extracurricular, Low Grades: Minimal scholarship.
- Low Need, High Extracurricular, High Grades: Moderate scholarship.
- Low Need, Medium Extracurricular, Medium Grades: Small scholarship.
- Low Need, Low Extracurricular, Low Grades: No scholarship.

## Solution

```
def scholarship(financial_cond, extra_act, grades):
    if financial_cond >=80:
        if extra_act >=80:
            if grades >=80:
                return 5000
            if grades>= 60 and grades <80:
                return 3000
            if grades>= 40 and grades <60:
                return 2000
        if extra_act >= 60 and extra_act < 80:
            if grades >=80:
                return 4000
            if grades>= 60 and grades <80:
                return 2000
            if grades>= 40 and grades <60:
                return 1000
        if extra_act >= 40 and extra_act <60:
            if grades >=80:
                return 3000
            if grades>= 60 and grades <80:
                return 1000
            if grades>= 40 and grades <60:
                return 000
    if financial_cond >=60 and financial_cond <80:
        if extra_act >=80:
            if grades >=80:
                return 4000
            if grades>= 60 and grades <80:
                return 2000
            if grades>= 40 and grades <60:
                return 1000
        if extra_act >= 60 and extra_act < 80:
            if grades >=80:
                return 3000
            if grades>= 60 and grades <80:
                return 1000
            if grades>= 40 and grades <60:
                return 0000
        if extra_act >= 40 and extra_act <60:
            if grades >=80:
                return 2000
            if grades>= 60 and grades <80:
                return 0000
            if grades>= 40 and grades <60:
                return 000
    if financial_cond >= 40 and financial_cond <60:
        if extra_act >=80:
            if grades >=80:
                return 3000
            if grades>= 60 and grades <80:
                return 1000
            if grades>= 40 and grades <60:
                return 000
        if extra_act >= 60 and extra_act < 80:
            if grades >=80:
                return 2000
            if grades>= 60 and grades <80:
                return 000
            if grades>= 40 and grades <60:
                return 000
        if extra_act >= 40 and extra_act <60:
            if grades >=80:
                return 1000
            if grades>= 60 and grades <80:
                return 000
            if grades>= 40 and grades <60:
                return 000
    else:
        return 0
        
financial_cond = float(input('Enter financial condition in 1 to 100 '))
extrac_act = float(input('Enter the extracurricular participation in 1 to 100 '))
grades= float(input('Enter the grades of the student '))

print(scholarship(financial_cond, extrac_act, grades))
```

## Other Ideas

### 1

```
financial_cond = float(input('Enter financial condition in 1 to 100 '))
extrac_act = float(input('Enter the extracurricular participation in 1 to 100 '))
grades= float(input('Enter the grades of the student '))
def scholarship():
    if financial_cond >= 80 and extrac_act >= 80 and grades >= 80:
        return 10000
    elif financial_cond >= 80 and extrac_act >= 80 and grades >= 60 and grades <80:
        return 5000
    elif financial_cond >= 80 and extrac_act >= 80 and grades >= 40 and grades < 60:
        return 2000
    elif financial_cond >= 80 and extrac_act >= 60 and extrac_act < 80 and grades >= 80:
        return 5000
    elif financial_cond >=80 and extrac_act >=60 and extrac_act < 80 and grades >= 60 and grades < 80:
        return 2000
    elif financial_cond >= 80 and extrac_act >=50 and extrac_act < 60 and grades >= 60 and grades < 80:
        return 1000
    elif financial_cond >= 60 and financial_cond < 80 and extrac_act >= 80 and grades >=80:
        return 5000
    elif financial_cond >=60 and financial_cond < 80 and extrac_act >=60 and extrac_act < 80 and grades >= 80:
        return 2000
    elif financial_cond >=60 and financial_cond < 80 and extrac_act >= 60 and extrac_act < 80 and grades >= 60 and grades < 80:
        return 1000
    else:
        return 0
        
scholarship()
```

### Reasons for Rejection:

1. Scope and Redundancy: The scholarship() function does not take parameters, so it relies on global variables (financial_cond, extrac_act, grades) that are input directly. This design is less modular and can lead to issues in maintaining and testing the code.
2. Overlap and Ambiguity: Some conditions overlap or are redundant. For instance, multiple elif branches check similar conditions with slight differences in thresholds or ranges, which can make the logic confusing and error-prone.
3. Logic Complexity: The use of multiple elif statements with overlapping conditions creates a complex structure that is hard to follow. It's not immediately clear which condition will be true and what the final result will be in various scenarios.

### 2 

```

def scholarship(financial_cond, extra_act, grades):
    if financial_cond >= 80:
        return high_financial(extra_act, grades)
    elif financial_cond >= 60:
        return medium_financial(extra_act, grades)
    elif financial_cond >= 40:
        return low_financial(extra_act, grades)
    else:
        return 0

def high_financial(extra_act, grades):
    if extra_act >= 80:
        if grades >= 80:
            return 5000
        elif grades >= 60:
            return 3000
        elif grades >= 40:
            return 2000
    elif extra_act >= 60:
        if grades >= 80:
            return 4000
        elif grades >= 60:
            return 2000
        elif grades >= 40:
            return 1000
    elif extra_act >= 40:
        if grades >= 80:
            return 3000
        elif grades >= 60:
            return 1000
        elif grades >= 40:
            return 0

def medium_financial(extra_act, grades):
    if extra_act >= 80:
        if grades >= 80:
            return 4000
        elif grades >= 60:
            return 2000
        elif grades >= 40:
            return 1000
    elif extra_act >= 60:
        if grades >= 80:
            return 3000
        elif grades >= 60:
            return 1000
        elif grades >= 40:
            return 0
    elif extra_act >= 40:
        if grades >= 80:
            return 2000
        elif grades >= 60:
            return 0
        elif grades >= 40:
            return 0

def low_financial(extra_act, grades):
    if extra_act >= 80:
        if grades >= 80:
            return 3000
        elif grades >= 60:
            return 1000
        elif grades >= 40:
            return 0
    elif extra_act >= 60:
        if grades >= 80:
            return 2000
        elif grades >= 60:
            return 0
        elif grades >= 40:
            return 0
    elif extra_act >= 40:
        if grades >= 80:
            return 1000
        elif grades >= 60:
            return 0
        elif grades >= 40:
            return 0

financial_cond = float(input('Enter financial condition in 1 to 100: '))
extra_act = float(input('Enter the extracurricular participation in 1 to 100: '))
grades = float(input('Enter the grades of the student: '))

print(scholarship(financial_cond, extra_act, grades))
```

### Reasons for Rejection:

1. Code Redundancy: The logic for determining scholarships is repeated across different financial need categories (high_financial, medium_financial, low_financial), leading to redundant code. This could be simplified to avoid repetition and reduce the risk of inconsistencies.
2. Complexity in Function Calls: The nested function calls and multiple layers of conditions make the code harder to follow and maintain. The separation into different functions is good for modularity but can be excessive and confusing due to the amount of nested conditions.
3. Inconsistent Scholarship Amounts: The decision logic for scholarship amounts between different financial need levels is not always consistent, leading to potential confusion about why certain scholarship amounts are given based on specific conditions.

### 3

```

grades = float(input("Enter the applicant's GPA : "))
extracurriculars = int(input("Enter the number of extracurricular activities: "))
financial_need = input("Is there a financial need? (yes/no): ").strip().lower()

eligible = True

grade_thresholds = [3.5, 3.0, 2.5] 
scholarship_level = None

for threshold in grade_thresholds:
    if grades >= threshold:
        if threshold == 3.5:
            scholarship_level = "Full Scholarship"
        elif threshold == 3.0:
            scholarship_level = "Partial Scholarship"
        elif threshold == 2.5:
            scholarship_level = "Basic Scholarship"
        break
else:
    eligible = False
    print("Applicant does not meet the minimum grade requirement.")

if eligible:
    extracurricular_threshold = 2  # Minimum number of activities required
    if extracurriculars < extracurricular_threshold:
        eligible = False
        print("Applicant does not meet the extracurricular activities requirement.")

if eligible:
    while financial_need not in ['yes', 'no']:
        financial_need = input("Please enter 'yes' or 'no' for financial need: ").strip().lower()
    
    if financial_need == 'no':
        scholarship_level = "Merit-based Scholarship"  # Adjust the scholarship type based on no financial need

if eligible:
    print(f"The applicant is eligible for the {scholarship_level}.")
else:
    print("The applicant is not eligible for the scholarship.")
```

### Reasons for Rejection

1. Oversimplification: The approach is too simplistic as it does not account for a range of conditions but rather uses a single threshold for grades and a binary check for financial need. This could overlook important nuances in determining eligibility and scholarship amounts.
2. Hard-Coded Values: Scholarship levels are hard-coded based on GPA and a binary check for financial need without considering other factors like the level of extracurricular involvement or more granular financial need assessments.
3. Interaction Handling: The loop for handling financial need input could potentially cause an infinite loop if the user does not enter 'yes' or 'no' (though the infinite loop might be a rare issue in practice, it is a potential flaw).

## Reasons for selecting solution and potential flaws in it

Let's review the proposed solution and analyze the reasons for its selection as well as potential flaws:

### Proposed Solution

```python
def scholarship(financial_cond, extra_act, grades):
    if financial_cond >=80:
        if extra_act >=80:
            if grades >=80:
                return 5000
            elif grades >= 60:
                return 3000
            elif grades >= 40:
                return 2000
        elif extra_act >= 60:
            if grades >=80:
                return 4000
            elif grades >= 60:
                return 2000
            elif grades >= 40:
                return 1000
        elif extra_act >= 40:
            if grades >=80:
                return 3000
            elif grades >= 60:
                return 1000
            elif grades >= 40:
                return 0
    elif financial_cond >=60:
        if extra_act >=80:
            if grades >=80:
                return 4000
            elif grades >= 60:
                return 2000
            elif grades >= 40:
                return 1000
        elif extra_act >= 60:
            if grades >=80:
                return 3000
            elif grades >= 60:
                return 1000
            elif grades >= 40:
                return 0
        elif extra_act >= 40:
            if grades >=80:
                return 2000
            elif grades >= 60:
                return 0
            elif grades >= 40:
                return 0
    elif financial_cond >= 40:
        if extra_act >=80:
            if grades >=80:
                return 3000
            elif grades >= 60:
                return 1000
            elif grades >= 40:
                return 0
        elif extra_act >= 60:
            if grades >=80:
                return 2000
            elif grades >= 60:
                return 0
            elif grades >= 40:
                return 0
        elif extra_act >= 40:
            if grades >=80:
                return 1000
            elif grades >= 60:
                return 0
            elif grades >= 40:
                return 0
    else:
        return 0
        
financial_cond = float(input('Enter financial condition in 1 to 100 '))
extra_act = float(input('Enter the extracurricular participation in 1 to 100 '))
grades = float(input('Enter the grades of the student '))

print(scholarship(financial_cond, extra_act, grades))
```

### Reasons for Selection

1. **Structured Approach**: The solution uses a multi-tier decision-making process that evaluates financial condition, extracurricular activities, and grades systematically. This structured approach allows for a clear, organized method of determining scholarship eligibility.

2. **Detailed Evaluation**: The solution covers a range of conditions with specific thresholds for financial need, extracurricular involvement, and academic performance, providing a detailed framework for assigning scholarship amounts.

3. **Modularity**: By separating different levels of financial need and evaluating other criteria within these levels, the solution introduces a modular structure that is easier to manage and update.

4. **Clear Decision Path**: The nested `if-else` statements create a clear path of decision-making, making it explicit which conditions lead to which scholarship amounts.

### Potential Flaws

1. **Redundancy and Complexity**: The code contains a lot of redundancy. For instance, the checks for grades and extracurricular activities are repeated multiple times. This redundancy increases the complexity of the code and makes it harder to maintain and understand.

2. **Code Duplication**: The decision-making logic for each range of `financial_cond` has similar patterns but with slightly different thresholds. This duplication could be avoided by consolidating common logic and reducing repetitive code blocks.

3. **Hardcoded Values**: The scholarship amounts and thresholds are hardcoded, which makes it inflexible. If the criteria or amounts need to change, the code must be updated manually. Using a configuration file or constants would improve flexibility.

4. **Lack of Input Validation**: The code does not validate the inputs to ensure they are within expected ranges or types. For example, `financial_cond`, `extra_act`, and `grades` are expected to be between 1 and 100, but the code does not enforce or validate this.

5. **Edge Cases**: The solution does not handle edge cases robustly. For example, if `financial_cond`, `extra_act`, or `grades` are exactly on the boundary values (e.g., exactly 40, 60, or 80), the handling is somewhat ambiguous. Clearer handling of boundary cases would make the decision logic more precise.

6. **No Feedback or Explanation**: The solution only provides the scholarship amount and does not explain why a certain amount was given. Adding feedback or an explanation could improve user understanding and transparency.

Can you improve the proposed solution as per modern standards? [Hint: Refactor Redundancy, Implement Input Validation, Use Constants, and Enhance User Feedback]

Advanced Solution at: https://insightshub.in/design-a-multi-tier-decision-making-system-to-determine-the-eligibility-criteria-for-a-scholarship/#h-advanced-solution