绩点与等级的对应关系 = { 'A': 4.0, 'B': 3.0, 'C': 2.0, 'D': 1.0, 'F': 0 } sum_grade = 0 sum_credit = 0 while True: # 输入等级 grade = input() if grade.lower() == 'false': break # 输入学分 credit = int(input()) sum_grade += credit * 绩点与等级的对应关系[grade] sum_credit += credit # 计算平均绩点 average_grade = sum_grade / sum_credit print('%.2f' % average_grade)