Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Placeholders
Numbers
6. Float placeholders
Date and time
Padding and Alignment
Summary

Instruction

You did well! Now let's take a look at how we can format float variables.

exact_temperature = 24.3487935543
print('The exact temperature is {:f} degrees Celsius.'.format(exact_temperature))

Result: The exact temperature is 24.348794 degrees Celsius.

The {:f} placeholder is used to print float variables. By default, it shows the float value rounded to 6 digits after the decimal point.

Exercise

Ask the user for their height and weight:

What is your height in m? 
What is your weight in kg? 

Remember to cast the user input to a float. Then, print the following:

Your BMI is {bmi}.

Calculate the BMI as:

\text{BMI} = \frac{\text{weight\ in\ kilograms}}{(\text{height\ in\ meters})^2}

Use a float placeholder to format the result to six digits after the decimal point.

Stuck? Here's a hint!

Example inputs:

height = 1.6
weight = 50

Output:

Your BMI is 19.531250.