Data Science with python ( Pandas Pandas Pandas ) Project test case #3 | Sololearn: Learn to code for FREE!


Data Science with python ( Pandas Pandas Pandas ) Project test case #3

test case #3 always fails. checked everything. older discussions are saying case #3 checks the 'None' output, which works perfectly in my code. Can anyone spot the bug? Thank you!

4/15/2021 8:00:44 PM

Nader Nabil

4 Answers

New Answer


import numpy as np n = int(input()) X=[] for i in range(n): X.append([float(x) for x in input().split()]) x1 = np.array([0, 0]) x2 = np.array([2, 2]) X=np.array(X) a=[] b=[] for i in range(n): if np.sqrt(((X[i]-x1)**2).sum()) <= np.sqrt(((X[i]-x2)**2).sum()): a.append(X[i]) elif np.sqrt(((X[i]-x1)**2).sum()) > np.sqrt(((X[i]-x2)**2).sum()): b.append(X[i]) a=np.array(a) b=np.array(b) sum_a_1=0 sum_a_2=0 sum_b_1=0 sum_b_2=0 for i in range(len(a)): sum_a_1+=a[i][0] sum_a_2+=a[i][1] for i in range(len(b)): sum_b_1+=b[i][0] sum_b_2+=b[i][1] if (len(a)!=0): sum_a_1/=len(a) sum_a_2/=len(a) sum_a_1 = sum_a_1.round(2) sum_a_2 = sum_a_2.round(2) if (len(b)!=0): sum_b_1/=len(b) sum_b_2/=len(b) sum_b_1 = sum_b_1.round(2) sum_b_2 = sum_b_2.round(2) c=[] c.append(sum_a_1) c.append(sum_a_2) d=[] d.append(sum_b_1) d.append(sum_b_2) c=np.array(c) d=np.array(d) if len(a)==0: print(None) else: print(c) if len(b)==0: print(


#try this code credit to Namrata Dattani import numpy as np first = np.array([[0., 0.]]) second = np.array([[2., 2.]]) n = int(input()) data = [] for i in range(n): data.append([float(i) for i in input().split()]) data = np.array(data).reshape((-1,2)) for i in range(n): dist1 = np.sqrt(((data[i]-first[0])**2).sum()) dist2 = np.sqrt(((data[i]-second[0])**2).sum()) if (dist1) <= (dist2): first = np.vstack((first,data[i])) else: second = np.vstack((second,data[i])) if first.size > 2: mean1 = np.mean(first[1:], axis=0) print(np.around(mean1, decimals=2)) else: print(None) if second.size > 2: mean2 = np.mean(second[1:], axis=0) print(np.around(mean2, decimals=2)) else: print(None)


Jonnie Sagarino thank you! Worked like a charm


shortest answer :