0
Split to achieve gain
Please help
4 Réponses
+ 5
You have done some little mistakes including the "print" in last line.
See this I have corrected it👇
S = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
totalS = len(S)
totalA= len(A)
totalB= len(B)
p= 0
for i in S:
if i == 1:
p+=1
p=p/totalS
giniS = 2 * p* (1-p)
pL= 0
for e in A:
if e == 1:
pL+=1
pL=pL/totalA
giniL = 2 * pL* (1-pL)
pR = 0
for ee in B:
if ee == 1:
pR+=1
pR= pR/totalB
giniR = 2 * pR* (1-pR)
iG = giniS-(totalA/totalS)*giniL-(totalB/totalS)*giniR
print(round(iG,5))
+ 4
S = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
p1=sum(S)/len(S)
imp1=2*p1*(1-p1)
p2=sum(A)/len(A)
imp2=2*p2*(1-p2)
p3=sum(B)/len(B)
imp3=2*p3*(1-p3)
i=imp1-len(A)/len(S)*imp2-len(B)/len(S)*imp3
print(round(i,5))
0
S = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
SL = len(S)
BL=len(B)
AL = len(A)
one = S.count(1)
zero = S.count(0)
giniP = one/(one+zero)
giniInit = 2*giniP*(1-giniP)
one = A.count(1)
zero = A.count(0)
giniP = one/(one+zero)
giniLeft = 2*giniP*(1-giniP)
one = B.count(1)
zero = B.count(0)
giniP = one/(one+zero)
giniRight= 2*giniP*(1-giniP)
IG= giniInit -(giniLeft*(AL/SL))-(giniRight*(BL/SL))
print (giniInit,5)
0
import numpy as np
S = np.array([int(x) for x in input().split()])
A = np.array([int(x) for x in input().split()])
B = np.array([int(x) for x in input().split()])
print(round(( 2* (len(S[S==1])/len(S)) * (len(S[S==0])/len(S)) ) - (len(A)/len(S))*(( 2* (len(A[A==1])/len(A)) * (len(A[A==0])/len(A)) )) - (len(B)/len(S))*( 2* (len(B[B==1])/len(B)) * (len(B[B==0])/len(B)) ),5) )