Python averaging problem.

Asked 2 years ago, Updated 2 years ago, 17 views

def solution(arr):

    sum(arr)/len(arr)

If you run it with the code above, it says it's wrong when you submit the answer, but I don't know why.

--Problem--

https://programmers.co.kr/learn/courses/30/lessons/12944 (Programmers Algorithm Practice Problem.)

A function that returns the average value of an array arr containing an integer Complete the solution.

Restrictions

arr is an array of length greater than or equal to 1 and less than or equal to 100.

The element of arr is an integer greater than or equal to -10,000 and less than or equal to 10,000.

python

2022-09-22 12:02

2 Answers

I got it right because I did the same thing, but if you submitted it as it is, I think the problem is that you didn't use return.


2022-09-22 12:02

float Check if it is being used.

arr = [9,9,8];
print(sum(arr)/len(arr)); // 8
print(sum(arr)*1.0/len(arr)); // 8.66666666667


2022-09-22 12:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.