-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbmi.py
34 lines (27 loc) · 877 Bytes
/
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
from colored import stylize, fg
# decoration
print(stylize("\n---- | Get Body-Mass-Index | ----\n", fg("red")))
# class
class BMI:
def __init__(self, w, h):
self.w = w
self.h = h
# output magic method
def __repr__(self):
bmi = self.calculate(self.w, self.h)
print(stylize(f"\nYour BMI is {bmi}.", fg("red")))
if bmi < 18.5:
return "You are underweight.\n"
elif bmi < 24.9:
return "You are normal weight.\n"
else:
return "You are overweight.\n"
# methods
def calculate(self, weight, height):
return round(weight / (height**2), 2)
# main execution
if __name__ == "__main__":
# user interaction
weight = float(input("Weight in kg: "))
height = float(input("Height in meter: "))
print(BMI(weight, height))