Home >Backend Development >Python Tutorial >Design a multi-tier decision-making system to determine the eligibility criteria for a scholarship.
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.
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:
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))
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()
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))
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.")
Let's review the proposed solution and analyze the reasons for its selection as well as potential flaws:
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))
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
The above is the detailed content of Design a multi-tier decision-making system to determine the eligibility criteria for a scholarship.. For more information, please follow other related articles on the PHP Chinese website!