DEV Community

Mohammad Alsuwaidi
Mohammad Alsuwaidi

Posted on

3 3

Python bmi calcultor

wrote a quick bmi calculator for imperial and metric it might not be perfect but i wanna know how can i make it better

m_or_i = int(input("Enter 1 for metric and 2 for imperial: "))

if m_or_i == 1:
    h1 = float(input("Enter your height in cm: "))
    h = h1 / 100
    w = float(input("Enter your weight in kgs: "))
    an = w / h ** 2
    if an < 18.4:
        print"Your bmi is:", (round(an, 1)), "which means you are under weight"
    elif 18.5 <= an <= 24.9:
        print"Your bmi is:", (round(an, 1)), "which means you are normal weight"
    elif 25 <= an <= 29.9:
        print"Your bmi is:", (round(an, 1)), "which means you are over weight"
    elif 30 <= an <= 34.9:
        print"Your bmi is:", (round(an, 1)), "which means you are obese class 1"
    elif 35 <= an <= 39.9:
        print"Your bmi is:", (round(an, 1)), "which means you are obese class 2"
    elif an >= 40:
        print"Your bmi is:", (round(an, 1)), "which means you are obese class 3"

elif m_or_i == 2:
    h1 = float(input("Enter your height in feet: "))
    h2 = float(input("Enter the inches: "))
    h = h1 * 12 + h2
    w = float(input("Enter your weight in pounds: "))
    an = w * 703 / h ** 2
    if an < 18.4:
        print"Your bmi is:", (round(an, 1)), "which means you are under weight"
    elif 18.5 <= an <= 24.9:
        print"Your bmi is:", (round(an, 1)), "which means you are normal weight"
    elif 25 <= an <= 29.9:
        print"Your bmi is:", (round(an, 1)), "which means you are over weight"
    elif 30 <= an <= 34.9:
        print"Your bmi is:", (round(an, 1)), "which means you are obese class 1"
    elif 35 <= an <= 39.9:
        print"Your bmi is:", (round(an, 1)), "which means you are obese class 2"
    elif an >= 40:
        print"Your bmi is:", (round(an, 1)), "which means you are obese class 3"

Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series