3.4.3.2. Exercise: Function return values 2#

Based on the function print_info that you created previously, write a function named format_info that returns a string so that:

print(format_info(1, "Catherina", "Smith", 20, 1.5, 50.2))

prints this:

=============
Participant 1: Catherina Smith
20 years old
Height: 1.5 m
Weight: 50.2 kg
BMI: 22.31
=============

Tip

You may want to return section Strings for a refresher on how to include line breaks in strings, how to create long strings, and how to add variables in strings.

Hide code cell content
def calculate_bmi(height, weight):
    return weight / (height ** 2)


def format_info(i_participant, first_name, last_name, age, height, weight):

    output = (
        "=============\n"
        f"Participant {i_participant}: {first_name} {last_name}\n"
        f"{age} years old\n"
        f"Height: {height} m\n"
        f"Weight: {weight} kg\n"
        f"BMI: {calculate_bmi(height, weight):.2f}\n"
        "============="
    )
    return output


print(format_info(1, "Catherina", "Smith", 20, 1.5, 50.2))
=============
Participant 1: Catherina Smith
20 years old
Height: 1.5 m
Weight: 50.2 kg
BMI: 22.31
=============