Skip to content

Commit fd3c338

Browse files
Update bmicalculator.py
1 parent 2b06da3 commit fd3c338

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

venv/bmicalculator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ def __init__(self):
4343
self.result = tk.Label(self.root,font=("Tahoma",17),text="",height=2,width=36,bg="#ccffff")
4444
self.result.pack(padx=30,pady=5)
4545
self.root.mainloop()
46-
46+
47+
# Function to check if given string is a valid decimal or float
48+
def isValidDecimal(self,strNum):
49+
if strNum.count(".") <= 1 and strNum.replace(".", "").isnumeric():
50+
return True
51+
return False
52+
4753
# Function to calculate BMI based on inputted height and weight
4854
def findBMI(self):
4955
weight = self.weight_var.get()
@@ -53,7 +59,7 @@ def findBMI(self):
5359
self.bmiLabel.config(text="")
5460
self.result.config(text="Height and Weight cannot be empty",bg="brown",fg="white",font=("Tahoma",15))
5561
# when height and weight are input properly as numbers
56-
elif weight.isdecimal() and height.isdecimal():
62+
elif self.isValidDecimal(weight)==True and self.isValidDecimal(height)==True:
5763
# converted height in centimetre to metre
5864
heightMetre = float(height)/100
5965
# calculating bmi

0 commit comments

Comments
 (0)