add tag
anoldmaninthesea
I'm trying to solve the following challenge
https://www.hackerrank.com/challenges/s10-weighted-mean/problem?h_r=next-challenge&h_v=zen


On my Jupyter notebook the following function solves it:
 
```
def weightedMean(X, W):  
     # Write your code here  
     dotprd=sum([x*w for (x,w) in zip(X,W)])  
     return dotprd/sum(W)
```


However, on the site of the challenge, my function returns nothing... 


> ~ no response on stdout ~

why is that?


Top Answer
Tejas Shetty
You need to call your function after defining it.
```
def weightedMean(X, W):  
     # Write your code here  
     dotprd=sum([x*w for (x,w) in zip(X,W)])  
     return dotprd/sum(W)
  
X1 = [1, 3 ,5, 78, 39] 
W1 = [0.1, 0.34, 0.49, 0.06, 0.01]

weightedMean(X1, W1)

```
will result in 
8.64

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.