美文网首页
2018-12-30 自定义函数案例

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

作者: 化石0305 | 来源:发表于2018-12-30 00:16 被阅读0次
    
    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)
    
    

    相关文章

      网友评论

          本文标题:2018-12-30 自定义函数案例

          本文链接:https://www.haomeiwen.com/subject/gkpmlqtx.html