-
Notifications
You must be signed in to change notification settings - Fork 7
/
BMI.py
64 lines (50 loc) · 2.09 KB
/
BMI.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def input_variables():
print("Name:")
name = input("Enter the name of the person.")
print("Age:")
age = int(input("Enter the age of the person."))
print("Sex:")
sex = input("Enter sex: M for male, F for female, O for non binary.")
while sex!= 'M' and sex!='F' and sex!='O':
print("Incorrect choice.")
sex = input("Enter sex: M for male, F for female, O for non binary.")
print("Weight:")
unit_weight = input("Press 1 for kilograms, 2 for pounds.")
while unit_weight!= '1' and unit_weight!='2':
print("Incorrect choice.")
unit_weight = input("Press 1 for kilograms, 2 for pounds.")
if unit_weight == '1':
weight_in_kg = float(input("Enter the weight of the person in kilograms."))
else:
weight_in_kg = float(input("Enter the weight of the person in pounds."))*0.453592
print("Height:")
unit_height = input("Press 1 for meters and centimeters, 2 for feet and inches")
while unit_weight!= '1' and unit_weight!='2':
print("Incorrect choice.")
unit_height = input("Press 1 for meters and centimeters, 2 for feet and inches")
if unit_height == '1':
height_in_m = float(input("Enter the height of the person in meters.")) + float(input("Enter the remaining height of the person in centimeters"))*0.01
else:
height_in_m = (float(input("Enter the height of the person in feet"))*12 + float(input("Enter the remaining height of the person in inches")))*0.0254
return name, age, sex, weight_in_kg, height_in_m
def calculate_BMI(info):
wt = info[3]
ht = info[4]
BMI = wt/(ht**2)
return BMI
def find_body_state(BMI):
if BMI<18.5:
body_state = 'underweight'
elif BMI<24.9:
body_state = 'normal'
elif BMI<29.9:
body_state = 'overweight'
else:
body_state = 'obese'
return body_state
def output():
info = input_variables()
BMI = calculate_BMI(info)
body_state = find_body_state(BMI)
print("Name: {}\nAge: {}\nGender: {}\nWeight(in kg): {:.3f}\nHeight(in m): {:.2f}\nBody Mass Index: {:.2f}\nAcoording to your body mass index, you are {}.".format(info[0], info[1], info[2], info[3], info[4], BMI, body_state))
output()