-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodewars7.py
More file actions
37 lines (23 loc) · 831 Bytes
/
codewars7.py
File metadata and controls
37 lines (23 loc) · 831 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
#Write function bmi that calculates body mass index (bmi = weight / height ^ 2).
#if bmi <= 18.5 return "Underweight"
#if bmi <= 25.0 return "Normal"
#if bmi <= 30.0 return "Overweight"
#if bmi > 30 return "Obese"
def bmi(weight, height):
bmi = weight / (height) ** 2
if bmi <= 18.5 :
return "Underweight"
elif bmi <= 25.0 :
return "Normal"
elif bmi <= 30.0 :
return "Overweight"
else:
return "Obese"
print(bmi(50, 1.80))
#intriguing examples
def bmi(weight, height):
b = weight / height ** 2
return ['Underweight', 'Normal', 'Overweight', 'Obese'][(b > 30) + (b > 25) + (b > 18.5)]
def bmi(weight, height):
bmi = weight / height ** 2
return 'Underweight' if bmi <= 18.5 else 'Normal' if bmi <= 25.0 else 'Overweight' if bmi <= 30.0 else "Obese"