NP47. 牛牛的绩点
描述
A | 4.0 |
B | 3.0 |
C | 2.0 |
D | 1.0 |
F | 0 |
输入描述
输出描述
均绩保留两位小数。示例1
输入:
A 3 B 4 C 2 False
输出:
3.11
Python 解法, 执行用时: 14ms, 内存消耗: 3096KB, 提交时间: 2022-06-23
dict = {"A":0,"B":0,"C":0,"D":0,"F":0} dict_jd = {"A":4.0,"B":3.0,"C":2.0,"D":1.0,"F":0} sum = 0.0 num = 0 while True: a = raw_input() if a != "False": b = input() dict[a] += b else: break for i in dict.keys(): num += dict[i] sum += dict[i] * dict_jd[i] result = sum/num print '%.2f'%result
Python 解法, 执行用时: 14ms, 内存消耗: 3128KB, 提交时间: 2022-07-31
dict = {"A":0,"B":0,"C":0,"D":0,"F":0} dict_jd = {"A":4.0,"B":3.0,"C":2.0,"D":1.0,"F":0} sum = 0.0 num = 0 while True: a = raw_input() if a != "False": b = input() dict[a] += b else: break for i in dict.keys(): num += dict[i] sum += dict[i] * dict_jd[i] result = sum/num print '%.2f'%result
Python 解法, 执行用时: 15ms, 内存消耗: 3048KB, 提交时间: 2022-07-08
sumScore = 0 sumAll = 0 while 1: name = raw_input() if name == 'False': print('%.2f'%(sumAll/sumScore)) break score = float(input()) if name == 'A': sumAll += score * 4 elif name == 'B': sumAll += score * 3 elif name == 'C': sumAll += score * 2 elif name == 'D': sumAll += score * 1 else: pass sumScore += score
Python 解法, 执行用时: 16ms, 内存消耗: 3080KB, 提交时间: 2022-07-04
dict1 = {'A':4,'B':3,'C':2,'D':1,'F':0} dict2 = {'A':0,'B':0,'C':0,'D':0,'F':0} num1 = 0 num2 = 0 while True : a = raw_input() if a == 'False' : break b = input() num1 += dict1[a] * b num2 += b s = float(num1) ss = float(num2) print '%.2f'%(s/ss)
Python 3 解法, 执行用时: 38ms, 内存消耗: 4540KB, 提交时间: 2022-07-30
grade_dict = {'A':4.0,'B':3.0,'C':2.0,'D':1.0,'F':0,} grade_list =[] scores_list = [] while True: grade = input() if grade =='False': break else: scores = int(input()) grade_list.append(grade_dict[grade] * scores) scores_list.append(scores) avg_score = sum(grade_list)/sum(scores_list) print('%.2f'%avg_score)