-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMI-Calculator.py
48 lines (36 loc) · 1.14 KB
/
BMI-Calculator.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
import time
#Define BMI function
def bodymassindex(weight, height):
return round(weight / (height/100) ** 2, 2)
print("Welcome to the Body Mass Index (BMI) calculator!")
time.sleep(1)
print("Let's calculate your BMI")
time.sleep(1)
again = "y"
while again == "y":
#User input
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in cm: "))
#Display BMI
BMI = bodymassindex(weight, height)
print ("Your BMI is:", BMI)
if (BMI < 18.5):
print("You are underweight")
elif (BMI <= 24.9):
print("Your weight is within the normal range")
elif (BMI < 30):
print("You are overweight")
else:
print("You are obese")
while True:
again = input("Would you like to calculate your BMI again? Y/N ").lower()
try:
if again == "y":
break
elif again == "n":
print("Thank you for using the BMI calculator")
break
else:
raise Exception("Invalid input! Answer 'Y' or 'N' ")
except Exception as e:
print(e)