我一直得到這個GPA計算器的錯誤,該計算器應該根據4個等級來計算您的GPA。此外,只要輸入了一封未命名爲A,B,C,D,F的信件,我就不知道該怎麼辦了,該程序需要終止。GPA Calc Python
def GetName():
name = raw_input ("Enter the student's name ")
grade1 = raw_input ("Enter a grade: ")
grade2 = raw_input ("Enter a grade: ")
grade3 = raw_input ("Enter a grade: ")
grade4 = raw_input ("Enter a grade: ")
return name, grade1, grade2, grade3, grade4
def GetGrades(grade1, grade2, grade3, grade4):
if [grade1, grade2, grade3, grade4] == 'A' or [grade1, grade2, grade3, grade4] == 'a':
[g1, g2, g3, g4] =4
elif [grade1, grade2, grade3, grade4] == 'B' or [grade1, grade2, grade3, grade4] == 'b':
[g1, g2, g3, g4] =3
elif [grade1, grade2, grade3, grade4] == 'C' or [grade1, grade2, grade3, grade4] == 'd':
[g1, g2, g3, g4] =2
elif [grade1, grade2, grade3, grade4] == 'D' or [grade1, grade2, grade3, grade4] == 'd':
[g1, g2, g3, g4] =1
elif [grade1, grade2, grade3, grade4] == 'F' or [grade1, grade2, grade3, grade4] == 'f':
[g1, g2, g3, g4] =0
else:
return 'invalid grade'
return g1, g2, g3, g4
def CalcGPA(g1,g2,g3,g4):
GPA = (g1,g2,g3,g4)/4
return GPA
def main(name, GPA):
print "The GPA for", name,"is",GPA
return 0
GetName()=name,grade1,grade2,grade3,grade4
GetGrades(grade1,grade2,grade3,grade4)=g1,g2,g3,g4
CalcGPA(g1,g2,g3,g4)=GPA
main(name,GPA)=0
究竟發生了什麼?向我們顯示完整的錯誤消息。 – user2357112
我嘗試運行該程序,它說:「你的程序中有一個錯誤:***不能分配給函數調用線34 – user3317056