-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmi_calculator.py
More file actions
64 lines (58 loc) · 2.09 KB
/
bmi_calculator.py
File metadata and controls
64 lines (58 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
import os
import sys
def calculate_bmi():
while True:
try:
h = float(input('Your height in meters (ex. 1.73): '))
break
except ValueError:
print('Height must be a number.\n')
while True:
try:
w = float(input('Your weight in kilograms (ex. 75): '))
break
except ValueError:
('Weight must be a number.\n')
normal_bmi = 'Normal BMI is from 18.50 to 24.90.'
bmi = w / (h**2)
bmi = round(bmi, 2)
if bmi < 18.49:
print('\nYour BODY MASS INDEX is {:0.2f} and classified as SEVERELY UNDERWEIGHT.'.format((bmi)))
print(normal_bmi)
elif bmi == 18.49:
print('\nYour BODY MASS INDEX is {:0.2f} and classified as UNDERWEIGHT.'.format((bmi)))
print(normal_bmi)
elif bmi <= 24.99:
print('\nYour BODY MASS INDEX is {:0.2f} and classified as NORMAL.'.format((bmi)))
elif bmi <= 29.99:
print('\n\nYour BODY MASS INDEX is {:0.2f} and classified as OVERWEIGHT.'.format((bmi)))
print(normal_bmi)
elif bmi <= 34.99:
print('\nYour BODY MASS INDEX is {:0.2f} and classified as SEVERELY OVERWEIGHT.'.format((bmi)))
print(normal_bmi)
elif bmi <= 39.99:
print('\nYour BODY MASS INDEX is {:0.2f} and classified as OBESE.'.format((bmi)))
print(normal_bmi)
else:
print('\nYour BODY MASS INDEX is {:0.2f} and classified as SEVERELY OBESE.'.format((bmi)))
print(normal_bmi)
return
def main():
os.system('cls' if os.name == 'nt' else 'clear')
app_name = 'BMI Calculator'
print(f'{"-" * 48}')
print(f'{" " * 12}{app_name}{" " * 12}')
print(f'{"-" * 48}')
calculate_bmi()
while True:
response = input('\nDo you want to continue? (Y/N) ')
if response == 'y' or response == 'Y':
main()
elif response == 'n' or response == 'N':
print('\nThank you and have a great day.\n')
sys.exit()
else:
print('\nError: Please select y or n.\n')
continue
if __name__ == '__main__':
main()