所以我的编码作业遇到了麻烦,我正在尝试制作一个 GPA 计算器,我认为它大部分都完成了,但它不起作用,因为它一直告诉我列表索引超出范围在第 8 行。
def main():
file_name = input("Enter filename: ")
file = open(file_name, "r")
total = [0, 0]
count = [0, 0]
for line in file:
sline = line[:-1].split(" ")
grade = sline[1] # Here
units = sline[2]
grade_points = (ord("E") - ord(grade))
print(grade, units, grade_points)
total = units * grade_points
gpa = total / units
print(total)
main()