forked from linuxacademy/content-python-for-sys-admins
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbmi
More file actions
executable file
·23 lines (20 loc) · 823 Bytes
/
bmi
File metadata and controls
executable file
·23 lines (20 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/python
def gather_info():
height = float(raw_input("What is your height? (inches or meters) "))
weight = float(raw_input("What is your weight? (pounds or kilograms) "))
unit = raw_input("Are your mearsurements in metric or imperial units? ").lower().strip()
return (height, weight, unit)
def calculate_bmi(weight, height, unit='metric'):
if unit == 'metric':
bmi = (weight / (height ** 2))
else:
bmi = 703 * (weight / (height ** 2))
print("Your BMI is %s" % bmi)
while True:
height, weight, unit = gather_info()
if unit.startswith('i'):
calculate_bmi(weight, unit='imperial', height=height)
elif unit.startswith('m'):
calculate_bmi(weight, height)
else:
print("Error: Unknown measurement system. Please use imperial or metric.")