- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBMI.py
More file actions
Latest commit
64 lines (50 loc) · 2.09 KB
/
Copy pathBMI.py
File metadata and controls
64 lines (50 loc) · 2.09 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
definput_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.")
whilesex!='M'andsex!='F'andsex!='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.")
whileunit_weight!='1'andunit_weight!='2':
print("Incorrect choice.")
unit_weight=input("Press 1 for kilograms, 2 for pounds.")
ifunit_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")
whileunit_weight!='1'andunit_weight!='2':
print("Incorrect choice.")
unit_height=input("Press 1 for meters and centimeters, 2 for feet and inches")
ifunit_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
returnname, age, sex, weight_in_kg, height_in_m
defcalculate_BMI(info):
wt=info[3]
ht=info[4]
BMI=wt/(ht**2)
returnBMI
deffind_body_state(BMI):
ifBMI<18.5:
body_state='underweight'
elifBMI<24.9:
body_state='normal'
elifBMI<29.9:
body_state='overweight'
else:
body_state='obese'
returnbody_state
defoutput():
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()