Forums

Code not giving output after grouping in functions

Hello everyone, I am new to python, and started off by doing some excersises. I came with a working code, but after I tried to group it into functions, the code didn't give me the right output anymore. Can someone please show me what went wrong? Thanks in regards.

def averages(line, average_grade): if line == '': return name_grades = line.split('_') student_name = name_grades[0] grades = [float(n) for n in name_grades[-1].split(' ')] average_grades(student_name, grades) print('{} has an average grade of {:.2}'.format(student_name, average_grade))

def average_grades(grades): average_grade = sum(grades) / len(grades) averages(average_grade) return

file = open('geo_grades_1_input.txt').read().split('\n') print("Report for group 2b")

for line in file: averages(line)

print("End of report")

Debugging is a large part of programming, so it's a good thing to learn. Start by making sure that each of your functions is doing the thing that you expect in the way you expect and then, once you've found the function that has the issue, try adding prints to it to see what is going on inside it and why it is not returning what you expect.