Not passing all the test cases | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Not passing all the test cases

I was doing the exercise for the course "Data Science" named "Average of Rows". I am able to pass the first three test cases, but I am not able to pass the last two of them. Here is the code for that: import numpy as np n, p = [int(x) for x in input().split()] list_ = [] for i in range(n): a = input().split() sum_ = 0 for i in a: sum_ += float(i) ans = sum_/len(a) list_.append(ans) list_ = np.array(list_) print(list_) please help me debug the answer.

4th Jul 2021, 5:52 PM
Nehul Patel
Nehul Patel - avatar
3 Answers
+ 1
Your second loop when u storing data in a . I think a should be list type becz at a time u can store one value . Length of (a) what it will print last value of a which can be a any values suppose your last entered values is 5 so a will be 5 . i dont have much more idea of python
4th Jul 2021, 6:47 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
It's much easier to use numpy to get the mean values, and then also use numpy.around to round the hole list to two decimals. I suggest you take a look at W3Schools to find out how to do that.
4th Jul 2021, 7:02 PM
Jan
Jan - avatar
0
Your trick worked. I rounded off using numpy array and passed all the test cases. But I was just wondering, if I rounded of the same list using round(number, decimals) I got wrong answer in the last test case. Does numpy.round_(number, decimals) and simple round(number, decimals) works differently ??
14th Oct 2021, 11:20 PM
Nehul Patel
Nehul Patel - avatar