Improved version
Here is an improved version of your code, user3551354. It accomplishes exactly the same result (with regards to the contents of Lst_New), as your original code.
def grade_to_letter(grade):
if grade > 90: return 'A'
if grade > 80: return 'B'
if grade > 70: return 'C'
if grade > 60: return 'D'
return 'F'
lst = [[90,80,70,60], [10,81,50, 65]]
Lst_New=[]
for student in lst:
avg = sum(student) / len(student)
print(avg)
New_grade = grade_to_letter(avg)
Lst_New.append(New_grade)
print(Lst_New)
An even more improved version
I took the liberty to rewrite my first version of the program to follow some of the best industry standards, such as proper variable naming (following a convention using underscores), avoiding redundant code, and avoiding redundant variables by utilizing dictionaries. I also added comments, which is the golden industry standard when it comes to designing excellent code.
I hope this example (or revision of your program) helps you!
# Helper function: calculate a letter grade based on a given average score
def grade_to_letter(grade):
if grade > 90: return 'A'
if grade > 80: return 'B'
if grade > 70: return 'C'
if grade > 60: return 'D'
return 'F'
# Define the list of students,
# where each element of the list is a dictionary representing a single student
students = [
{
'scores': [ 90, 80, 70, 60 ],
'average_score': None,
'letter_grade': None
},
{
'scores': [ 10, 81, 50, 65 ],
'average_score': None,
'letter_grade': None
}
]
# Iterate over the students list
for student in students:
avg = sum(student['scores']) / len(student['scores'])
# Update the score and grade values in the dictionary (i.e., the student)
student['average_score'] = avg
student['letter_grade'] = grade_to_letter(avg)
# Now the `students` dictionary contains the updated averages and letter grades
print(students)