题解 | 牛牛的绩点
牛牛的绩点
https://www.nowcoder.com/practice/de8bc3e736164786b07a4dd64ed172f7
# 映射字典
grad_map = {"A": 4.0, "B": 3.0, "C": 2.0, "D": 1.0, "F": 0.0}
# 初始化总成绩点与总学分
total_points = 0
total_credits = 0
# 循环读取输入,直到等级为’False‘ 结束
while True:
grad = input().strip()
# 判断等级是否为False
if grad == "False":
break
# 获取等级对应的学分
credit = float(input().strip())
total_points += grad_map[grad] * credit
total_credits += credit
# 判断总学分是否大于0
if total_credits > 0:
# 计算GPA
gpa = total_points / total_credits
print(f"{gpa:.2f}")
else:
print("0.00")
