← Back to Blog

PARAMETERS Mini Project — BMI Calculator

The problem...

You've built the BMI Calculator before. It asked for input, calculated, and printed. One long block.

Now you have parameters. Same logic — but cleaner.

The idea!

One function. Weight and height as parameters. The function calculates and prints. No input() inside — you pass the values from outside.

Your mission

Rewrite the BMI Calculator as a function. Pass weight and height as parameters.

The solution

def calculate_bmi(weight, height):
    bmi = weight / height ** 2
    print(f"Weight: {weight}kg | Height: {height}m | BMI: {bmi:.1f}")

calculate_bmi(70, 1.75)
calculate_bmi(90, 1.80)
calculate_bmi(55, 1.60)

Test it

# Weight: 70kg | Height: 1.75m | BMI: 22.9
# Weight: 90kg | Height: 1.80m | BMI: 27.8
# Weight: 55kg | Height: 1.60m | BMI: 21.5

What's really happening

Weight and height come in as parameters. The function calculates the BMI and prints the result. Three calls — three different people — three different BMIs. No rewriting. No copy-paste.

When you learn return — you'll add the category too. For now — the calculation is clean and reusable.

Go further

  • Call the function with your own weight and height
  • Add a name parameter — print "Bull | BMI: 22.9"
  • Add a default weight or height — what would a sensible default be?

What you should understand now

  • Parameters replace hardcoded values — pass what changes
  • No input() inside — the function receives values, it doesn't ask for them
  • Same function, different arguments — different BMI every time
  • The category logic comes later — when you learn return
[ login to bookmark ] // copied! 19 views · 1 min
// resources
Exercise bmi_calculator_2.py
← prev PARAMETERS Mini Project — Username Generator next → Your function finally talks back
// 0 comments
// No comments yet. Be the first.
// leave a comment

// Your comment will appear after approval.