Skip to content

Commit f3ce47c

Browse files
Update bmicalculator.py
1 parent fd3c338 commit f3ce47c

1 file changed

Lines changed: 30 additions & 20 deletions

File tree

venv/bmicalculator.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# importing tkinter
1010
import tkinter as tk
11+
from tkinter import messagebox
1112

1213
class BmiCalculator:
1314
def __init__(self):
@@ -62,27 +63,36 @@ def findBMI(self):
6263
elif self.isValidDecimal(weight)==True and self.isValidDecimal(height)==True:
6364
# converted height in centimetre to metre
6465
heightMetre = float(height)/100
65-
# calculating bmi
66-
bmi = float("{:.2f}".format(float(weight)/heightMetre/heightMetre))
67-
# Displaying bmi through label 'bmiLabel'
68-
self.bmiLabel.config(text=f"BMI is {bmi}")
69-
# Category of BMI result
70-
if bmi<15:
71-
self.result.config(text="Very severely underweight",bg="purple",fg="white",font=("Georgia"))
72-
elif bmi>=15 and bmi<16:
73-
self.result.config(text="Severely underweight", bg="blue", fg="white",font=("Georgia"))
74-
elif bmi>=16 and bmi<18.5:
75-
self.result.config(text="Underweight", bg="#3377ff", fg="black",font=("Georgia",18))
76-
elif bmi>=18.5 and bmi<=24.9:
77-
self.result.config(text="Healthy", bg="green", fg="white",font=("Georgia",20))
78-
elif bmi>=25 and bmi<=29.9:
79-
self.result.config(text="Overweight", bg="yellow", fg="black",font=("Georgia",20))
80-
elif bmi>=30 and bmi<40:
81-
self.result.config(text="Obese", bg="orange", fg="black",font=("Georgia",20))
82-
elif bmi>=40:
83-
self.result.config(text="Extremely Obese", bg="red", fg="white",font=("Cambria",23))
66+
if float(height)>=100 and (weight!=0.0 or weight!=0):
67+
# calculating bmi
68+
bmi = float("{:.2f}".format(float(weight)/heightMetre/heightMetre))
69+
# Displaying bmi through label 'bmiLabel'
70+
self.bmiLabel.config(text=f"BMI is {bmi}")
71+
# Category of BMI result
72+
if bmi<15:
73+
self.result.config(text="Very severely underweight",bg="purple",fg="white",font=("Georgia"))
74+
elif bmi>=15 and bmi<16:
75+
self.result.config(text="Severely underweight", bg="blue", fg="white",font=("Georgia"))
76+
elif bmi>=16 and bmi<18.5:
77+
self.result.config(text="Underweight", bg="#3377ff", fg="black",font=("Georgia",18))
78+
elif bmi>=18.5 and bmi<=24.9:
79+
self.result.config(text="Healthy", bg="green", fg="white",font=("Georgia",20))
80+
elif bmi>=25 and bmi<=29.9:
81+
self.result.config(text="Overweight", bg="yellow", fg="black",font=("Georgia",20))
82+
elif bmi>=30 and bmi<40:
83+
self.result.config(text="Obese", bg="orange", fg="black",font=("Georgia",20))
84+
elif bmi>=40:
85+
self.result.config(text="Extremely Obese", bg="red", fg="white",font=("Cambria",23))
86+
elif heightMetre==0 or weight==0:
87+
self.bmiLabel.config(text="")
88+
self.result.config(text="Height and Weight cannot be 0", bg="red", font=("Arial", 15))
89+
else:
90+
# When entered height is less than 100
91+
self.bmiLabel.config(text="")
92+
self.result.config(text="", bg="#ccffff")
93+
messagebox.showinfo(title="Message",message="Invalid height and weight")
8494
else:
85-
# When the entered input in height and weight fiels is not numbers
95+
# When the entered input in height and weight fields is not number
8696
self.bmiLabel.config(text="")
8797
self.result.config(text="Enter numbers only please",bg="red",font=("Arial",18))
8898
# object created for the class 'BmiCalculator'

0 commit comments

Comments
 (0)