I'm a Python beginner trying write a program that will allow the user to input individuals names and test scores and I am supposed to give back a grade after finding the average so far I've been able to write the program but I am experiencing difficulties trying to debug it. my programs works fine until it starts to calculate the average, it usually displays an error message saying
"TypeError: 'float' object is not subscriptable"
Could somebody please help me why my codes are not working? Thank you for your help in advance!
def calcaverage(test1,test2,test3):
for count in range(numofstudent):
curraverage=((test1[count]+ test2[count]+ test3[count])/3)
if curraverage>= 90:
grade= "A"
return grade
else:
if curraverage >= 80 and curraverage < 90:
grade= "B"
return grade
else:
if curraverage >= 70 and curraverage < 80:
grade= "C"
return grade
else:
if curraverage < 70:
grade= "F"
return grade
numofstudent=int(input("How Many Students?: "))
students=[]
test1=[]
test2=[]
test3=[]
averagescore=[]
grade=[]
for count in range(numofstudent):
currstudent=input("Please enter name of student: ")
students.append(currstudent)
currstudenttest1= float(input("First test score?: "))
currstudenttest2= float(input("Second test score?: "))
currstudenttest3= float(input("Third test score?: "))
test1.append(currstudenttest1)
test2.append(currstudenttest2)
test3.append(currstudenttest3)
grade=calcaverage(test1,test2,test3)
averagescore.append(grade)
print([students], "your grade is " ,[grade])
elifclause onifstatements, which you can use to avoid the excessively nestedif/elses.range(curraverage)whencurraveragehas not been defined.