-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmicalc.py
77 lines (61 loc) · 2.17 KB
/
bmicalc.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from tkinter import *
w = Tk()
w.title("BMI Calculator")
w.minsize(width=200, height=150)
w.config(padx=30, pady=30)
# def calc_bmi():
# if input_entry_kg and input_entry_hi is int:
# if input_entry_kg and input_entry_hi > 0:
# sonuc = input_entry_hi / input_entry_kg * input_entry_kg
# if sonuc <= 18.5:
# print("Zayıfsın")
# elif sonuc > 18.5 and sonuc <= 29.9:
# print("Normal Ağırlıktasın")
# elif sonuc > 29.9 and sonuc <= 34.9:
# print("Kilolu")
# elif sonuc > 34.9 and sonuc <= 39.9:
# print("I. Derece Obezite")
# elif sonuc > 39.9 and sonuc <= 49.9:
# print("II. Derece Obezite")
# elif sonuc > 49.9 and sonuc <= 59.9:
# print("III. Derece Obezite")
def calculate_bmi():
height = input_entry_hi.get()
weight = input_entry_we.get()
if weight == "" or height == "":
result_label.config(text="Enter both weight and height")
else:
try:
bmi = float(weight) / ((float(height) /100) ** 2)
result_string = Write_result(bmi)
result_label.config(text=result_string)
except:
result_label.config(text="Enter a valid number")
label_kg = Label(text="Enter Your Weight (kg)")
label_kg.pack()
input_entry_we = Entry(width=20)
input_entry_we.pack()
label_height = Label(text="Enter Your Height (cm)")
label_height.pack()
input_entry_hi = Entry(width=20)
input_entry_hi.pack()
calc_button = Button(text= "Calculate", command=calculate_bmi)
calc_button.pack()
result_label = Label()
result_label.pack()
def Write_result(bmi):
result_string = f"Your BMI is: {round(bmi, 2)}. You are "
if bmi <= 18.5:
result_string += "Your bmi: Severely Thin!"
elif 18.5 < bmi <= 24.9:
result_string += "Your bmi: Normal!"
elif 24.9 < bmi <= 29.9:
result_string += "Your bmi: Fat!"
elif 29.9 < bmi <= 34.9:
result_string += "Your bmi: I. Level Obese!"
elif 34.9 < bmi <= 39.9:
result_string += "Your bmi: II. Level Obese!"
else:
result_string += "Your bmi: III. Level Obese!!"
return result_string
w.mainloop()