leandurus leandurus - 2 years ago 58
Python Question

Python - Make avarage variables without 0

A = 0
B = 10
C = 20
N = [(A, B, C)]

Avarage = (A + B + C) / sum(1 for i in N if i != 0)


Avarage = 30??

Need Avarage = 15.

Any idea?

Answer Source

You need to remove ( and ) from your list N

a = 0
b = 10
c = 20
n = [a, b, c]

list_avg = sum(n) / sum(1 for i in n if i != 0)

Output:

>>> list_avg
15
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download