#Stuck on Guido's Lasagna for Python

21 messages · Page 1 of 1 (latest)

fierce stag
#

Hey all! I'm stuck on Guido's Gorgeous Lasagna for Python.

So I have smashed around in my head some things about basic python. And I have come up with solutions to complete Task 1-3. But I'm stuck or maybe getting slightly confused on Task 4.

I have included I hope correctly the code block I have for Task 4. I'm thinking we just take in 2 parameters (preparation_time_in_minutes because of the number_of_layers and bake_time_remaining / elapsed_bake_time)

But when I go to run it the numbers are not coming out right. Assuming I'm missing something or possibly have something confused?

#TODO: define the 'elapsed_time_in_minutes()' function below.
def elapsed_time_in_minutes(bake_time_remaining, preparation_time_in_minutes):
    time_difference = bake_time_remaining + preparation_time_in_minutes
    return time_difference
dense kindle
#

Just for context, here are the instructions of task #4.

  1. Calculate total elapsed cooking time (prep + bake) in minutes

Define the elapsed_time_in_minutes() function that takes two parameters as arguments: number_of_layers (the number of layers added to the lasagna) and elapsed_bake_time (the number of minutes the lasagna has been baking in the oven). This function should return the total number of minutes you have been cooking, or the sum of your preparation time and the time the lasagna has already spent baking in the oven.

#

There's also an example:

>>> def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
        ...
        ...
        
>>> elapsed_time_in_minutes(3, 20)
26
#

In other words:
As input you get
(1) the number of layers of the lasagna, and
(2) the time the lasagna has already been in the oven.

You have to calculate the time since you started preparing the lasagna.
That is the time it took you to prepare the layers, and the time in the oven.

#

Do you understand the example, why elapsed_time_in_minutes(3, 20) should return 26?

fierce stag
#

Well, that's what I'm trying to understand currently, I'm trying to run back through what I have currently to figure it out. This is kinda the entire code I have so far..

#TODO: define the 'EXPECTED_BAKE_TIME' constant below.
EXPECTED_BAKE_TIME = 40
PREPARATION_TIME = 2
#TODO: Remove 'pass' and complete the 'bake_time_remaining()' function below.
def bake_time_remaining(elapsed_bake_time):
    """Calculate the bake time remaining.

    :param elapsed_bake_time: int - baking time already elapsed.
    :return: int - remaining bake time (in minutes) derived from 'EXPECTED_BAKE_TIME'.
    
    Function that takes the actual minutes the lasagna has been in the oven as
    an argument and returns how many minutes the lasagna still needs to bake
    based on the `EXPECTED_BAKE_TIME`.
    """
    return EXPECTED_BAKE_TIME - elapsed_bake_time


#TODO: Define the 'preparation_time_in_minutes()' function below.
# You might also consider defining a 'PREPARATION_TIME' constant.
# You can do that on the line below the 'EXPECTED_BAKE_TIME' constant.
# This will make it easier to do calculations.
def preparation_time_in_minutes(number_of_layers):
    return number_of_layers * PREPARATION_TIME

#TODO: define the 'elapsed_time_in_minutes()' function below.
def elapsed_time_in_minutes(preparation_time_in_minutes, bake_time_remaining):
    time_difference = preparation_time_in_minutes + bake_time_remaining
    return time_difference
dense kindle
#

Let's try this: Forget the code for a moment.
Imagine I'm a chef. I started my workday with making a lasagna.
One layer takes me 2 minutes to prepare.
After the preparation I put the lasagna into the oven.
When I tell you that my lasagna has 3 layers and has already been in the oven for 20 minutes, can you figure out how many minutes ago I started making the lasagna?

#

That's similar to a math problem. Can you as a human solve this concrete problem?

fierce stag
#

So that should be 2 * 3 = 6. Plus the 20. So it would return the 26 from the example.

dense kindle
#

correct.

#

can you generalize that?
When I tell you that my lasagna has X layers and has been in the oven for Y minutes, can you come up with a formula for how many minutes ago I started making the lasagna?

fierce stag
#

Snap, okay.

So this def would be the following:

def elapsed_time_in_minutes(number_of_layers, bake_time_remaining):
    time_difference = (number_of_layers * PREPARATION_TIME) + bake_time_remaining
    return time_difference
dense kindle
#

try it

fierce stag
#

Yup that worked, sick!

dense kindle
#

Congratulation!

fierce stag
#

Thank you for that! Guess I just needed to talk it out some haha

dense kindle
#

You might like the idea of "rubber duck debugging". Look it up, it's a real thing.

fierce stag
#

I will check it out!

#

Is that a book or just a online thing to read?

#

Just found it, I will give this a read, thank you again for the help!

dense kindle
#

Happy coding!