-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise15_math.py
More file actions
49 lines (38 loc) · 1.13 KB
/
exercise15_math.py
File metadata and controls
49 lines (38 loc) · 1.13 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
def math_divisive (n,m):
if n%m == 0:
return True
else:
return False
def math_mean (numbers):
sum = 0
for mun in numbers:
sum = sum + mun
return sum/len(numbers)
def math_medium (numbers):
if len(numbers) == 0:
return None
if len(numbers) == 1:
return numbers[0]
else:
sorted_numbers = sorted(numbers)
print sorted_numbers
if len(sorted_numbers)%2 == 0:
return (sorted_numbers[len(sorted_numbers)/2 -1] + sorted_numbers[len(sorted_numbers)/2])/2
else:
return sorted_numbers[len(sorted_numbers)/2]
if __name__ == '__main__':
# print math_divisive(10,1)
# print math_divisive(10,2)
# print math_divisive(10,3)
# print math_divisive(10,4)
# print math_divisive(10,5)
# print math_divisive(10,6)
# print math_divisive(21,2)
# print math_divisive(21,3)
# print math_divisive(21,7)
# print math_divisive(21,21)
# print math_mean ([10,11,20,99,200,33,56,80])
print math_medium ([10,11,20,99,200,33,56,80])
print math_medium ([10.00,11.00,20.00,99.00,200.00,33.00,56.00,80.00])
print math_medium ([10.00,11.00,20.00,99.00,200.00,33.10,56.77,80.00])
print math_medium ([10,11,20,99,200,33,56,80,75])