bukowski - 7 months ago 78

Python Question

The question can be found here

I'm trying to calculate the weighted average but when I try to populate an array with for loop It just doing nothing ?

`size = raw_input()`

arr = raw_input()

w = raw_input()

deger = [1,2,2,2,2]

size = [int(i) for i in size.split()]

size = size[0]

arr = [int(i) for i in arr.split()]

w = [float(i) for i in w.split()]

def wm (x,y,s):

for i in range(0,s-1):

deger[i] = int(input(x[i]*y[i]))

return sum(deger)

print(wm(arr,w,size))

Answer

Just some modifications based on your code with proper indentation:

```
size = raw_input()
arr = raw_input()
w = raw_input()
#deger = [1,2,2,2,2] # not necessary to initialize 'deger' here
size = [int(i) for i in size.split()]
size = size[0]
arr = [int(i) for i in arr.split()]
w = [float(i) for i in w.split()]
def wm (x,y,s):
deger = [] # initialize empty 'deger' here
for i in range(0,s): # 's-1' will not include the last item of x and y
deger.append(x[i]*y[i])
return sum(deger) / sum(y)
print('%.1f'%wm(arr,w,size)) # as 1 decimal place is required
```

Source (Stackoverflow)