STAY INFORMED
following content serves as a personal note and may lack complete accuracy or certainty.

Minimal-Mistakes instruction
Useful vscode Shortcut Keys
Unix Commands
npm Commands
Vim Commands
Git Note
Useful Figma Shortcut Keys

2 minute read

DBMR(Daily Basal Metabolic Requirement) is the total amount of energy your body needs at rest over a 24-hour period. This depends on what activity you do and the gender. Here is brief information about DBMR.

  • Estimated Range in Daily Energy Used = DBMR + Physical Activity Level

  • DBMR For Women = Mass in kg × 22 kcal/kg
  • DBMR For Men = Mass in kg × 24 kcal/kg
  Activity Level For Women Activity Level For Men
Inactive DBMR × (0.25 to 0.35) DBMR × (0.25 to 0.40)
Lightly Active DBMR × (0.40 to 0.60) DBMR × (0.50 to 0.70)
Moderately Active DBMR × (0.50 to 0.70) DBMR × (0.65 to 0.80)
Heavily Active DBMR × (0.80 to 1.00) DBMR × (0.90 to 1.20)
Exceptionaly Active DBMR × (1.10 to 1.30) DBMR × (1.30 to 1.45)

inputs

Now I will code for inputs(skipped code for creating window). You need one entry for mass, two radio buttons for selecting gender, one combo box for selecting activity level and one list for combo box(and one convert button obviously).

self.entry = Entry(self.frame, width=5)
self.entry.place(x=10, y=20)
self.label = Label(self.frame, text="kg")
self.label.place(x=70, y=20)

activity_level = [("Inactive"), ("Lightly Acitve"), ("Moderately Active"),
                    ("Heavily Active"), ("Exceptionaly Active")]
self.convert_from = ttk.Combobox(self.frame, values=activity_level, width=11)
self.convert_from.place(x=110, y=20)

self.choice=StringVar()
self.choice.set("MALE")
self.rb1 = Radiobutton(self.frame, text="Male", font=14, variable=self.choice, value="MALE")
self.rb1.place(x=250, y=10)
self.rb1 = Radiobutton(self.frame, text="Female", font=14, variable=self.choice, value="FEMALE")
self.rb1.place(x=250, y=30)

self.button = Button(self.frame, text="Convert", font=14)
self.button.place(x=350, y=20)

function

And here is the function. First, get values of mass, gender, activity and dbmr depending on the selected choice.

mass = float(self.entry.get())
gender = self.choice.get()
activity = self.select_activity.get()
output_val1 = 0
output_val2 = 0
dbmr = mass * (24 if gender == "MALE" else 22)

Since there are two different outputs, it is hard to optimize using dictionary, so I used elif method. This is my whole code.

def do_this(self):
try:
    mass = float(self.entry.get())
    gender = self.choice.get()
    activity = self.select_activity.get()
    output_val1 = 0
    output_val2 = 0
    dbmr = mass * (24 if gender == "MALE" else 22)

except:
    showerror("Error", "Please type valid value in entry box")

else:
    if gender == "MALE":
        if activity == "Inactive":
            output_val1 = dbmr + mass * 0.25
            output_val2 = dbmr + mass * 0.40
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Lightly Active":
            output_val1 = dbmr + mass * 0.50
            output_val2 = dbmr + mass * 0.70
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Moderately Active":
            output_val1 = dbmr + mass * 0.65
            output_val2 = dbmr + mass * 0.80
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Heavily Active":
            output_val1 = dbmr + mass * 0.90
            output_val2 = dbmr + mass * 1.20
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Exceptionaly Active":
            output_val1 = dbmr + mass * 1.30
            output_val2 = dbmr + mass * 1.45
            showinfo("Result", f"{output_val1} to {output_val2}")

    elif gender =="FEMALE":
        if activity == "Inactive":
            output_val1 = dbmr + mass * 0.25
            output_val2 = dbmr + mass * 0.35
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Lightly Active":
            output_val1 = dbmr + mass * 0.40
            output_val2 = dbmr + mass * 0.60
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Moderately Active":
            output_val1 = dbmr + mass * 0.50
            output_val2 = dbmr + mass * 0.70
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Heavily Active":
            output_val1 = dbmr + mass * 0.80
            output_val2 = dbmr + mass * 1.00
            showinfo("Result", f"{output_val1} to {output_val2}")

        elif activity == "Exceptionaly Active":
            output_val1 = dbmr + mass * 1.10
            output_val2 = dbmr + mass * 1.30
            showinfo("Result", f"{output_val1} to {output_val2}")

    else:
        showerror("Error", "Please select your gender")

I think I am done with this project, but if I get some more ideas, I will add.