Aan de slagGa gratis aan de slag

Calculating file sizes

Lambda functions are handy for quickly creating short, one-line functions that can be used immediately without the need for formal def definitions.

In this exercise, you'll work with a lambda function that calculates the total file size including extra space needed for file information. extra_space is calculated as a percent of file_size.

Deze oefening maakt deel uit van de cursus

Intermediate Python for Developers

Cursus bekijken

Oefeninstructies

  • Define the calculate_total lambda that adds the extra_space to the base file size.
  • Call calculate_total() on the file_size variable.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

file_size = 2500
extra_space = 0.15

# Define a lambda function
calculate_total = ____ x: x * (1 + ____)

# Call the lambda function
print(____(____))
Code bewerken en uitvoeren