Sort by

recency

|

570 Discussions

|

  • + 0 comments
    def weightedMean(n,X, W):
        s=0
        for i in range(n):
            s+=X[i]*W[i]
        print(round(s/sum(W),1)) 
    
  • + 0 comments

    def weightedMean(X, W): # Write your code here we = [(x*w) for x,w in zip(X,W)] weight = 0 for item in we: weight += item print(round(weight/sum(W),1))

  • + 0 comments

    print(f"{sum([x*w for x,w in zip(X,W)]) / sum(W):.1f}")

  • + 0 comments

    This is kind of a problem where Python list comprehension shines.

  • + 0 comments
    def weightedMean(X, W):
        product = sum(list(map(lambda n: n[1] * W[n[0]], enumerate(X))))
        print(f"{product / sum(W):.1f}")