-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript44_Lec12_Digit_Average.py
More file actions
50 lines (38 loc) · 970 Bytes
/
Script44_Lec12_Digit_Average.py
File metadata and controls
50 lines (38 loc) · 970 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# In the name of God
# Mohammad Hossein Zehtab
# python-evens-17
# Lec 12: Mean of Digits Function
import math
def test(did_pass: bool):
'''
Print the result of a test.
'''
if did_pass:
print('True')
else:
print('Failed')
def test_suite():
'''
Run the suite of tests for code in this module.
'''
test(find_mean_of_digits_in(1326) == 3.0)
test(find_mean_of_digits_in(56789) == 7.0)
def find_mean_of_digits_in(number:int) -> float:
'''
Returns digits of a number in a list and
Returns the mean of digits
'''
dig = ''
count = 0
while True:
d = number % 10
dig += str(d)
number //= 10
count += 1
if number == 0:
break
digits = dig[::-1]
print(list(map(int, digits)))
return sum(list(map(int, digits))) / count
### Driver Code ###
test_suite()