Do not add stuff to read_data function it should only do that.
If add average function that you have it would look like this.
Then make also a function for total sum.
If add average function that you have it would look like this.
Then make also a function for total sum.
def average(numbers): avg = sum(numbers) / len (numbers) print(f"Average = {avg:.2f}") def read_data(file_in): try: with open(file_in) as nums_file: numbers = [] for line in nums_file: numbers.append(int(line)) return numbers except OSError: return f"Could not read file: {file_in}" if __name__ == '__main__': file_in = 'nums.txt' numbers = read_data(file_in) average(numbers)