# ERROR HANDLING Mini Project — BMI Calculator
# three functions, built in order, each feeding the next

# ─────────────────────────────────────────────
# Step 1 — get valid input
# ─────────────────────────────────────────────

def get_input(prompt):
    while True:
        try:
            value = float(input(prompt))
            if value <= 0:
                raise ValueError("Value must be greater than zero.")
            return value
        except ValueError as e:
            print(f"Invalid input: {e}")

# keeps asking until user provides a valid positive number
# handles both wrong types and wrong values

# ─────────────────────────────────────────────
# Step 2 — calculate BMI
# ─────────────────────────────────────────────

def calculate_bmi(weight, height):
    return weight / height ** 2

# clean and simple — validation already happened in get_input()

# ─────────────────────────────────────────────
# Step 3 — get the category
# ─────────────────────────────────────────────

def get_category(bmi):
    if bmi < 18.5:
        return "Underweight"
    elif bmi < 25:
        return "Normal weight"
    elif bmi < 30:
        return "Overweight"
    else:
        return "Obese"

# ─────────────────────────────────────────────
# Put it together
# ─────────────────────────────────────────────

weight = get_input("Enter your weight (kg): ")
height = get_input("Enter your height (m): ")

bmi = calculate_bmi(weight, height)
category = get_category(bmi)

print(f"Weight: {weight}kg | Height: {height}m | BMI: {bmi:.1f} | {category}")

# ─────────────────────────────────────────────
# Test it
# ─────────────────────────────────────────────

# Enter your weight (kg): abc
# Invalid input: could not convert string to float: 'abc'
# Enter your weight (kg): -5
# Invalid input: Value must be greater than zero.
# Enter your weight (kg): 70
# Enter your height (m): 1.75
# Weight: 70kg | Height: 1.75m | BMI: 22.9 | Normal weight

# ─────────────────────────────────────────────
# Go further
# ─────────────────────────────────────────────

# Add a name parameter to the final print — "Bull | BMI: 22.9 | Normal weight"
# Wrap everything in a while True — let the user calculate multiple times
# Add raise inside calculate_bmi() as an extra safety net
