def calculate_average(numbers):
total = sum(numbers)
average = total / len(numbers)
return average
print(average)
calculate_average([34, 30, 12])
Output shows that average is not defined which I dont understand why. Can someone explain why to me? I already know I can use this line print(calculate_average([34, 30, 12])) to print out. But I want to know why my code is not working. I understand return will pass the data outside of the function and end the function, but I dont understand how to print it out as output. Please write down the corrected version and explain me to me. Thank you so much.
I try to use python tutor and also ask chatgpt but still dont understand why or how to make it functioning.