Skip to content

Commit 3b5316b

Browse files
bites 191
1 parent 04aa1ac commit 3b5316b

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@
4646
/78/README.md
4747
/162/README.md
4848
/203/README.md
49+
/191/README.md

191/bmi.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from textwrap import dedent
2+
3+
data = """Luke Skywalker,172,77
4+
C-3PO,167,75
5+
R2-D2,96,32
6+
Darth Vader,202,136
7+
Leia Organa,150,49
8+
Owen Lars,178,120
9+
Beru Whitesun lars,165,75
10+
R5-D4,97,32
11+
Biggs Darklighter,183,84
12+
Obi-Wan Kenobi,182,77
13+
Anakin Skywalker,188,84
14+
Chewbacca,228,112
15+
Han Solo,180,80
16+
Greedo,173,74
17+
Jek Tono Porkins,180,110
18+
Yoda,66,17
19+
Palpatine,170,75
20+
Boba Fett,183,78.2
21+
IG-88,200,140
22+
Bossk,190,113
23+
"""
24+
# mass/ height
25+
# print(float(17) / ((int(66) / 100) ** 2))
26+
27+
28+
def person_max_bmi(data=data):
29+
"""Return (name, BMI float) of the character in data that
30+
has the highest BMI (rounded on 2 decimals)"""
31+
BMIdict = dict()
32+
for line in data.splitlines():
33+
line = dedent(line)
34+
entry=line.split(',')
35+
name = entry[0]
36+
height = entry[1]
37+
mass = entry[2]
38+
BMI = float(mass) / ((int(height) / 100) ** 2)
39+
BMIdict.update({name:round(BMI,ndigits=2)})
40+
sortedbmilist = sorted(BMIdict.items(),key= lambda x: x[1])
41+
return sortedbmilist[-1]

191/test_bmi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from bmi import person_max_bmi, data
2+
3+
4+
def test_person_max_bmi():
5+
assert person_max_bmi() == ('Yoda', 39.03)
6+
7+
8+
def test_person_max_bmi_smaller_dataset():
9+
newdata = '\n'.join(data.splitlines()[:10])
10+
assert person_max_bmi(newdata) == ('Owen Lars', 37.87)
11+
12+
13+
def test_person_max_bmi_another_smaller_dataset():
14+
newdata = '\n'.join([row for row in data.splitlines()
15+
if row.lstrip()[:4] not in ('Owen', 'Yoda')])
16+
assert person_max_bmi(newdata) == ('IG-88', 35.0)

0 commit comments

Comments
 (0)