2018-12-30 自定义函数案例


def input_chengji():

    maths = int(input("请录入您的数学成绩:"))

    while maths < 0 or maths > 100:

        print("您的录入不正确!请重新输入!")

        maths = int(input("请录入您的数学成绩:"))

    enlish = int(input("请录入您的英语成绩:"))

    while enlish < 0 or maths > 100:

        print("您的录入不正确!请重新输入!")

        enlish = int(input("请录入您的英语成绩:"))

    history = int(input("请录入您的历史成绩:"))

    while history < 0 or maths > 100:

        print("您的录入不正确!请重新输入!")

        history = int(input("请录入您的历史成绩:"))

    return maths,enlish,history

def panduan_defeng_level(mscore,escore,hscore):

    if mscore >= 75:

        if mscore >= 85 :

            mlevel = "great"

        else:

            mlevel = "good"

    else:

        mlevel = "bad"

    if escore >= 80:

        if escore >= 90:

            elevel = "great"

        else:

            elevel = "good"

    else:

        elevel = "bad"

    if hscore >= 70:

        if hscore >= 78 :

            hlevel = "great"

        else:

            hlevel = "good"

    else:

        hlevel = "bad"

    return {'Maths':mlevel,'English':elevel,'History':hlevel}

def panduan_total_level(total):

    if total >= 270:

        result = "A+"

    elif total >= 240:

        result = "A"

    elif total >= 210:

        result = "B+"

    elif total >=190:

        result = "B"

    else:

        result = "C"

    return result

def bili_total_score(mscore,escore,hscore):

    return mscore*110/100 + escore*100/100+ hscore*80/100

def output_result(total,TotalLevel,SL):

    print('总分:',total)

    print('总分等级',TotalLevel)

    print('数学等级:',SL['Maths'],'英语等级:',SL['English'],'历史等级:',SL['History'])

if __name__ == "__main__":

    math,english,history = input_chengji()

    SubjectLevel = panduan_defeng_level(math,english,history)

    total = bili_total_score(math,english,history)

    result = panduan_total_level(total)

    output_result(total,result,SubjectLevel)

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容