Lasagna code works in VS Code, but not in Exercism editor... need an assist... thx

Define CONSTANT for expected bake time in snake case

EXPECTED_BAKE_TIME = 40 #EBT constant

print(EXPECTED_BAKE_TIME)

Define FUNCTION for remaining bake time: EXPECTED_BAKE_TIME - time_baked

def bake_time_remaining(time_baked):
return EXPECTED_BAKE_TIME - time_baked

Print remaining bake time with function call to pass time already baked ARGUMENT into function & substract from EBT constant

print(bake_time_remaining(10))

Define FUNCTION for prep time: # of layers * 2

def preparation_time_in_minutes(number_of_layers):
return number_of_layers * 2

Print prep time with function call to pass # of layers ARGUMENT into function & multiply by 2

print(preparation_time_in_miniutes(2))

def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
“”"Calculate the elapsed cooking time.

:param number_of_layers: int - the number of layers in the lasagna.
:param elapsed_bake_time: int - elapsed cooking time.
:return: int - total time elapsed (in minutes) preparing and cooking.

This function takes two integers representing the number of lasagna layers and the time already spent baking and calculates the total elapsed minutes spent cooking the lasagna.
"""

return bake_time_remaining(elapsed_bake_time) + preparation_time_in_minutes(number_of_layers)

print(elapsed_time_in_minutes.doc)
print("TOTAL TIME SPENT COOKING… ", elapsed_time_in_minutes(3, 20))

If you wrap your code in a codeblock, it’s a whole lot easier for people to read/debug/use:

# Define CONSTANT for expected bake time in snake case
EXPECTED_BAKE_TIME = 40 #EBT constant
# print(EXPECTED_BAKE_TIME)

# Define FUNCTION for remaining bake time: EXPECTED_BAKE_TIME - time_baked 
def bake_time_remaining(time_baked):
    return EXPECTED_BAKE_TIME - time_baked
# Print remaining bake time with function call to pass time already baked ARGUMENT into function & substract from EBT constant
### print(bake_time_remaining(10))

# Define FUNCTION for prep time: # of layers * 2 
def preparation_time_in_minutes(number_of_layers):
    return number_of_layers * 2

# Print prep time with function call to pass # of layers ARGUMENT into function & multiply by 2
### print(preparation_time_in_miniutes(2))

def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
    """Calculate the elapsed cooking time.

    :param number_of_layers: int - the number of layers in the lasagna.
    :param elapsed_bake_time: int - elapsed cooking time.
    :return: int - total time elapsed (in minutes) preparing and cooking.

    This function takes two integers representing the number of lasagna layers and the time already spent baking and calculates the total elapsed minutes spent cooking the lasagna.
    """

    return bake_time_remaining(elapsed_bake_time) + preparation_time_in_minutes(number_of_layers)

print(elapsed_time_in_minutes.__doc__)
print("TOTAL TIME SPENT COOKING... ", elapsed_time_in_minutes(3, 20))

What about the code doesn’t work? Do the tests pass? If not, can you read the tests and figure out what isn’t working? Learning to read the tests is an important skill when using Test Driven Development!

The final function doesn’t work in the Exercism editor

def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
“”"Calculate the elapsed cooking time.

:param number_of_layers: int - the number of layers in the lasagna.
:param elapsed_bake_time: int - elapsed cooking time.
:return: int - total time elapsed (in minutes) preparing and cooking.

This function takes two integers representing the number of lasagna layers and the time already spent baking and calculates the total elapsed minutes spent cooking the lasagna.
"""

return bake_time_remaining(elapsed_bake_time) + preparation_time_in_minutes(number_of_layers)

print(elapsed_time_in_minutes.doc)
print("TOTAL TIME SPENT COOKING… ", elapsed_time_in_minutes(3, 20))

Throws the following error:

It works fine :slight_smile: It just does the wrong thing.

  1. Please use codeblocks to share text. Not unformatted text. Not images.
  2. Look at the TEST FAILURE message. Do you understand what function was called? Do you understand the values it was called with? Do you understand what the tests expected vs what it received? Do you understand why it expects what it expects and why it got something different?

If you haven’t used codeblocks before, see Block code formatting