Anonymous user
Averages/Arithmetic mean: Difference between revisions
→{{header|Python}}: Gave Python 2.5 compatable version
(→{{header|Python}}: Gave Python 2.5 compatable version) |
|||
Line 300:
=={{header|Python}}==
{{works with|Python|2.5}}
<python>def average(x):
print avg([3,1,4,1,5,9])▼
Output:
<python>3.83333333333333</python>
▲ return sum(data)/float(len(data)) if len(data)!=0 else 0
{{works with|Python|2.4}}
<python>def avg(data):
if len(data)==0:
return 0
else:
return sum(data)/float(len(data))
print avg([3,1,4,1,5,9])</python>
Output:
<python>3.83333333333333</python>
=={{header|Ruby}}==
|