-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.py
More file actions
34 lines (32 loc) · 1.16 KB
/
task2.py
File metadata and controls
34 lines (32 loc) · 1.16 KB
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
import tkinter as tk
from tkinter import messagebox
def calculate_bmi():
try:
weight = float(weight_entry.get())
height = float(height_entry.get())
bmi = weight / (height ** 2)
bmi = round(bmi, 2)
if bmi < 18.5:
category = "Underweight"
elif 18.5 <= bmi < 24.9:
category = "Normal weight"
elif 25 <= bmi < 29.9:
category = "Overweight"
else:
category = "Obesity"
result_label.config(text=f"BMI: {bmi} - {category}")
except ValueError:
messagebox.showerror("Input Error", "Please enter valid numbers for weight and height.")
root = tk.Tk()
root.title("BMI Calculator")
tk.Label(root, text="Enter Weight (kg):").pack(pady=5)
weight_entry = tk.Entry(root)
weight_entry.pack(pady=5)
tk.Label(root, text="Enter Height (m):").pack(pady=5)
height_entry = tk.Entry(root)
height_entry.pack(pady=5)
calculate_button = tk.Button(root, text="Calculate BMI", command=calculate_bmi)
calculate_button.pack(pady=10)
result_label = tk.Label(root, text="Your BMI will appear here.")
result_label.pack(pady=10)
root.mainloop()