def getGradeInfo():
numStudent = int(input('Total number of students: '))
getGrades = input(f'Enter {numStudent} scores: ')
gradeListNum = getGrades.split(' ')
maxScore = int(max(gradeListNum[0:numStudent]))
gradeListLetter = []
for grade in gradeListLetter:
if int(grade) >= maxScore - 10:
gradeListLetter.append('A')
elif int(grade) >= maxScore - 20:
gradeListLetter.append('B')
elif int(grade) >= maxScore - 30:
gradeListLetter.append('C')
elif int(grade) >= maxScore - 40:
gradeListLetter.append('D')
else:
gradeListLetter.append('F')
a = 1
while a<= numStudent:
print(f'Student{a} score is {gradeListNum[a-1]} and grade is')
a =1
getGradeInfo()
I can get the input for the number of students in the code but can't figure out how to assign the letter to each of the student's grades for the print statement
CodePudding user response:
You are iterating over gradeListLetter
which is empty, try iterating over gradeListNum
instead.
You also aren't printing the letter grade in your print statement.
CodePudding user response:
As Adam Oppenheimer
said,
for grade in gradeListLetter:
should be
for grade in gradeListNum:
Also,
print(f'Student{a} score is {gradeListNum[a-1]} and grade is')
should be
print(f'Student {a}: score is {gradeListNum[a - 1]} and grade is {gradeListLetter[a - 1]}')