I am working on a teacher grading system in Django. I want functionality in which there is some entry like subject id and student's marks from the frontend. My app on the backend takes these two-parameter and creates a list of dictionaries with subject id and marks and pass it on another function and that function will sum up all the marks and give me a total and next average and percentage etc. But right now, I am stuck with total only so, when I pass this list of dictionaries in a function it gives me an error.
def marks_calculation(marks_entry):
total = sum(item['marks'] for item in marks_entry)
return total
class Student_marks:
def entry(subject_id, marks):
while True:
value = input("Need to enter marks, Press 'y' for Yes, 'n' for No: ").lower()
if value == 'n':
break
try:
subject_id = int(input(f'Enter subject id: '))
marks=int(input(f'Enter marks: '))
except ValueError:
print(f'You can only try integers:')
continue
marks_entry=[]
marks_entry.append({
"subject_id": subject_id,
"marks": marks
})
total_marks = marks_calculation(marks_entry)
return total_marks
marks=0
subject_id= 0
b= Students_marks
b.entry(marks, subject_id)
error is:
It is not giving me a total marks
"c:/Users/Lenovo/Documents/TGS/controller.py"
Enter subject id: 1
Enter marks: 58
PS C:\Users\Lenovo\Documents\TGS>