0

0

设计多层决策系统来确定奖学金的资格标准

WBOY

WBOY

发布时间:2024-07-12 19:52:01

|

657人浏览过

|

来源于dev.to

转载

设计多层决策系统来确定奖学金的资格标准

问题

使用 if-else 语句设计一个多层决策系统,可用于确定奖学金的资格标准。该系统应考虑多种因素,例如成绩、课外活动和财务需求。

思考过程

要设计一个多层决策系统来根据成绩、课外活动和财务需求确定奖学金资格,您需要一种结构化的方法来评估和分配奖学金金额。以下是如何使用 if-else 语句创建决策系统的逐步细分:

奖学金决定标准

  • 财务状况:确定学生的经济困难程度。
  • 课外活动:衡量学术之外的参与程度。
  • 成绩:反映学业表现。

奖学金决定逻辑

  • 确定财务需求:检查学生是否属于高、中或低财务需求类别。
  • 评估课外活动参与情况:在每个财务需求类别中,检查学生在课外活动中的活跃程度。
  • 评估成绩:最后评估学生的成绩,以决定确切的奖学金金额。

奖学金金额

  • 高需求,高课外活动,高成绩:最高奖学金。
  • 高需求,中等课外活动,中等成绩:中等奖学金。
  • 高需求,低课外活动,低成绩:奖学金很少。
  • 中等需求,高课外活动,高成绩:大量奖学金。
  • 中等需要,中等课外活动,中等成绩:中等奖学金。
  • 中等需求,低课外活动,低成绩:最低奖学金。
  • 低需求,高课外活动,高成绩:中等奖学金。
  • 低需求,中等课外活动,中等成绩:小额奖学金。
  • 低需求,低课外活动,低成绩:无奖学金。

解决方案

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))

其他想法

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()

拒绝原因:

  1. 范围和冗余:scholarship()函数不带参数,因此它依赖于直接输入的全局变量(financial_cond、extrac_act、grades)。这种设计模块化程度较低,可能会导致代码维护和测试方面出现问题。
  2. 重叠和歧义:某些条件重叠或冗余。例如,多个 elif 分支检查相似的条件,但阈值或范围略有不同,这可能会使逻辑混乱且容易出错。
  3. 逻辑复杂性:使用具有重叠条件的多个 elif 语句会产生难以理解的复杂结构。目前尚不清楚哪种情况为真以及在各种情况下最终结果会是什么。

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))

拒绝原因:

  1. 代码冗余:确定奖学金的逻辑在不同的财务需求类别(high_financial、medium_financial、low_financial)中重复,导致代码冗余。这可以简化以避免重复并降低不一致的风险。
  2. 函数调用的复杂性:嵌套的函数调用和多层条件使代码更难以遵循和维护。分离成不同的函数有利于模块化,但由于嵌套条件的数量可能会过多且令人困惑。
  3. 奖学金金额不一致:不同经济需求水平之间的奖学金金额决定逻辑并不总是一致,这可能会导致人们对为什么要根据特定条件给予某些奖学金金额产生潜在的困惑。

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.")

拒绝原因

  1. 过于简单化:该方法过于简单化,因为它没有考虑一系列条件,而是使用单一的成绩阈值和财务需求的二进制检查。这可能会忽略确定资格和奖学金金额时的重要细微差别。
  2. 硬编码值:奖学金级别是根据 gpa 和财务需求的二进制检查进行硬编码的,而不考虑其他因素,例如课外参与程度或更细粒度的财务需求评估。
  3. 交互处理:如果用户不输入“是”或“否”,处理财务需求输入的循环可能会导致无限循环(尽管无限循环在实践中可能是一个罕见的问题,但它是一个潜在的缺陷)。

选择解决方案的原因及其潜在缺陷

让我们回顾一下所提出的解决方案并分析其选择的原因以及潜在的缺陷:

建议的解决方案

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))

选择理由

  1. 结构化方法:该解决方案采用多层决策流程,系统地评估财务状况、课外活动和成绩。这种结构化方法可以采用清晰、有组织的方法来确定奖学金资格。

  2. 详细评估:该解决方案涵盖了一系列具有特定阈值的条件,包括经济需求、课外活动和学业成绩,为分配奖学金金额提供了详细的框架。

  3. 模块化:通过分离不同级别的财务需求并评估这些级别内的其他标准,该解决方案引入了更易于管理和更新的模块化结构。

  4. 清晰的决策路径:嵌套的 if-else 语句创建了清晰的决策路径,明确了哪些条件导致了哪些奖学金金额。

潜在缺陷

  1. 冗余和复杂性:代码包含大量冗余。例如,对成绩和课外活动的检查会重复多次。这种冗余增加了代码的复杂性,并使其更难以维护和理解。

    Skybox AI
    Skybox AI

    一键将涂鸦转为360°无缝环境贴图的AI神器

    下载
  2. 代码重复:每个范围的financial_cond的决策逻辑都有相似的模式,但阈值略有不同。可以通过整合通用逻辑并减少重复的代码块来避免这种重复。

  3. 硬编码值:奖学金金额和阈值是硬编码的,这使得它不灵活。如果需要更改标准或金额,则必须手动更新代码。使用配置文件或常量可以提高灵活性。

  4. 缺乏输入验证:代码不会验证输入以确保它们在预期的范围或类型内。例如,financial_cond、extra_act 和grades 预计在 1 到 100 之间,但代码不会强制或验证这一点。

  5. 边缘情况:该解决方案不能稳健地处理边缘情况。例如,如果 financial_cond、extra_act 或 grades 正好位于边界值上(例如,正好 40、60 或 80),则处理有些不明确。更清晰地处理边界情况将使决策逻辑更精确。

  6. 没有反馈或解释:该解决方案仅提供奖学金金额,并没有解释为什么给予一定金额。添加反馈或解释可以提高用户理解和透明度。

您能根据现代标准改进建议的解决方案吗? [提示:重构冗余、实现输入验证、使用常量并增强用户反馈]

高级解决方案:https://insightshub.in/design-a-multi-tier-decision-making-system-to-define-the-eligibility-criteria-for-a-scholarship/#h-advanced-solution

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
java基础知识汇总
java基础知识汇总

java基础知识有Java的历史和特点、Java的开发环境、Java的基本数据类型、变量和常量、运算符和表达式、控制语句、数组和字符串等等知识点。想要知道更多关于java基础知识的朋友,请阅读本专题下面的的有关文章,欢迎大家来php中文网学习。

1502

2023.10.24

typedef和define区别
typedef和define区别

typedef和define区别在类型检查、作用范围、可读性、错误处理和内存占用等。本专题为大家提供typedef和define相关的文章、下载、课程内容,供大家免费下载体验。

109

2023.09.26

define的用法
define的用法

define用法:1、定义常量;2、定义函数宏:3、定义条件编译;4、定义多行宏。更多关于define的用法的内容,大家可以阅读本专题下的文章。

338

2023.10.11

if什么意思
if什么意思

if的意思是“如果”的条件。它是一个用于引导条件语句的关键词,用于根据特定条件的真假情况来执行不同的代码块。本专题提供if什么意思的相关文章,供大家免费阅读。

779

2023.08.22

全局变量怎么定义
全局变量怎么定义

本专题整合了全局变量相关内容,阅读专题下面的文章了解更多详细内容。

81

2025.09.18

python 全局变量
python 全局变量

本专题整合了python中全局变量定义相关教程,阅读专题下面的文章了解更多详细内容。

96

2025.09.18

http与https有哪些区别
http与https有哪些区别

http与https的区别:1、协议安全性;2、连接方式;3、证书管理;4、连接状态;5、端口号;6、资源消耗;7、兼容性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2115

2024.08.16

C++ 设计模式与软件架构
C++ 设计模式与软件架构

本专题深入讲解 C++ 中的常见设计模式与架构优化,包括单例模式、工厂模式、观察者模式、策略模式、命令模式等,结合实际案例展示如何在 C++ 项目中应用这些模式提升代码可维护性与扩展性。通过案例分析,帮助开发者掌握 如何运用设计模式构建高质量的软件架构,提升系统的灵活性与可扩展性。

8

2026.01.30

c++ 字符串格式化
c++ 字符串格式化

本专题整合了c++字符串格式化用法、输出技巧、实践等等内容,阅读专题下面的文章了解更多详细内容。

8

2026.01.30

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号