forked from vtejapy/Beginners-Python-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmean.py
More file actions
37 lines (28 loc) · 745 Bytes
/
mean.py
File metadata and controls
37 lines (28 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: utf-8 -*-
# f(x) = s(x) / l(x) ______(e1)
# Functions below same principle as (e1)
#
# Here,
# Mean value can be float
# 'er is need to declare float values
# Function to get mean of given args
def mean_(*args):
sum_ = 0.0
length_ = 0.0
for arg in args:
sum_ += arg
length_ += 1.0
return sum_ / length_
# Function to get mean of array
def mean_ar(ar):
return float(sum(ar))/float(len(ar))
# Another feature can be start index
# and end index of array
# Test
# First function
if mean_(12, 445, 76, 23, 7, 9, 17, 19, 100) == 78.66666666666667:
print("First Function Works!")
# Second function
if mean_ar([12, 445, 76, 23, 7, 9, 17, 19, 10]) == 68.66666666666667:
print("Second Function Works!")