代码部分:
def get_rule(): r = open("rule.txt") rules = [] for line in r.readlines(): line = line.strip('\n') score, point = line.split(' ') high, low = score.split('~') high = int(high) low = int(low) point = float(point) rule = [high, low, point] rules.append(rule) return rules def get_score(): s = open("score.txt") scores = [] for line in s.readlines(): line = line.strip('\n') score, point = line.split(' ') score = int(score) point = float(point) ans = [score, point] scores.append(ans) return scores def calculation(rules, scores): all_credit = 0 gpa = 0 for i in scores: score, credit = i[0], i[1] all_credit += i[1] for j in rules: high, low, p = j[0], j[1], j[2] if low <= score <= high: gpa += credit * p gpa /= all_credit print(gpa) def main(): rule = get_rule() score = get_score() calculation(rule, score) if __name__ == '__main__': main()
讯享网
rule.txt:
100~95 4.3
94~90 4
89~85 3.7
84~82 3.3
81~78 3
77~75 2.7
74~72 2.3
71~68 2
67~65 1.7
64~64 1.5
63~61 1.3
60~60 1
60~0 0
score.txt:(第一列为成绩,第二列为学分)
87 2.3
79 3.5
87 3
91 2.5
92 3

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/78319.html