Reputation: 13
Everything else seems to be working fine. The requirements were that I use a for loop to get gather input for the students' grades, display a name for each student, compute and display the average of those 5 grades, and display the highest grade. I'm really not sure where I am going wrong here. Please help! Here is the program below:
#this program will compute average quiz grade for a group of 5 students
#prompt user for quiz grade using a for loop for each of the 5 students
#assign names to student list
students = ["John", "Jake", "Jane", "Sally", "Susie"]
#grades: 90-100=A, 80-90=B, 70-80=C, 60-70=D, <60=F
#prompt user for student grades
for student in students:
grades = eval(input(f"Enter the grade for {student}: "))
grades = []
sum = 0
for i in range(0,5):
for i in grades:
sum+=i
avg_grade=sum/5
#print average grade of students
if(avg_grade >=90):
print("Average Grade: A")
elif(avg_grade>=80 and avg_grade<90):
print("Average Grade: B")
elif(avg_grade>=70 and avg_grade<80):
print("Average Grade: C")
elif(avg_grade>=60 and avg_grade<70):
print("Average Grade: D")
else:
print("Average Grade: F")
#print highest grade
max_grade=max(grades)
for i in grades:
if(max_grade>=90):
print("Highest Grade: A")
elif(max_grade>=80 & max_grade<90):
print("Highest Grade: B")
elif(max_grade>=70 & max_grade<80):
print("Highest Grade: C")
elif(max_grade>=60 & max_grade<70):
print("Highest Grade: D")
else:
print("Highest Grade: F")
Upvotes: 0
Views: 55
Reputation: 107
Try this, because your grades is empty:
grades = []
for student in students:
grade = eval(input(f"Enter the grade for {student}: "))
grades.append(grade)
Upvotes: 0
Reputation: 1270
This means that the list grades
is empty, as you have not appended any values into the list. You can fix it by doing:
grades = []
for student in students:
grade = eval(input(f"Enter the grade for {student}: "))
grades.append(grade)
Note that this change is at the top part of the code.
Upvotes: 2