BMI ক্যালকুলেটর (পাইথন) - SMH Amiri

সর্বশেষ লিখাসমূহ

BMI ক্যালকুলেটর (পাইথন)


BMI ক্যালকুলেটর ( ওজন, উচ্চতা, জেন্ডার ইনপুট এর মাধ্যমে BMI নির্ণয় হবে এবং BMI এর ঝুঁকির মাত্রা প্রদর্শিত হবে)


import tkinter as tk

from tkinter import ttk


def calculate_bmi():

    weight = float(weight_entry.get())

    height = float(feet_entry.get()) * 0.3048  # convert feet to meters

    age = int(age_entry.get())

    gender = gender_var.get()


    # Calculate BMI

    bmi = weight / (height ** 2)


    # Adjust BMI for age and gender

    if gender == 'male':

        bmi -= (0.03 * age)

    else:

        bmi += (0.03 * age)


    result_label.config(text="Your BMI: {:.2f}".format(bmi))


# Create the main window

root = tk.Tk()

root.title("BMI Calculator")


# Create a frame to hold the input fields

input_frame = ttk.Frame(root, padding="10")

input_frame.grid(row=0, column=0, sticky=(tk.W, tk.E))


# Gender

gender_label = ttk.Label(input_frame, text="Gender:")

gender_label.grid(row=0, column=0, sticky=tk.W)

gender_var = tk.StringVar()

gender_combobox = ttk.Combobox(input_frame, textvariable=gender_var, values=['male', 'female'])

gender_combobox.grid(row=0, column=1)

gender_combobox.current(0)


# Weight

weight_label = ttk.Label(input_frame, text="Weight (kg):")

weight_label.grid(row=1, column=0, sticky=tk.W)

weight_entry = ttk.Entry(input_frame)

weight_entry.grid(row=1, column=1)

weight_entry.focus()


# Height

feet_label = ttk.Label(input_frame, text="Height (feet):")

feet_label.grid(row=2, column=0, sticky=tk.W)

feet_entry = ttk.Entry(input_frame)

feet_entry.grid(row=2, column=1)


# Age

age_label = ttk.Label(input_frame, text="Age:")

age_label.grid(row=3, column=0, sticky=tk.W)

age_entry = ttk.Entry(input_frame)

age_entry.grid(row=3, column=1)


# Calculate button

calculate_button = ttk.Button(input_frame, text="Calculate BMI", command=calculate_bmi)

calculate_button.grid(row=4, columnspan=2)


# Result label

result_label = ttk.Label(root, text="")

result_label.grid(row=1, column=0, sticky=tk.W)


root.mainloop()