I am very new to Python and programming. I am trying to solve the second Python exercise on the website https://exercism.org/.
I am really struggling to understand why this first task fails. The code properly executes in VScode and I pass the 4/5 tests of this exercise using their online code editor. Why does the first test fail, while the other 4 succeed?
Here is my code:
def EXPECTED_BAKE_TIME():
EXPECTED_BAKE_TIME = 40
bake_time_remaining = 30
elapsed_bake_time = (EXPECTED_BAKE_TIME - bake_time_remaining)
print(elapsed_bake_time, "minutes to go") EXPECTED_BAKE_TIME()
def preparation_time_in_minutes():
preparation_time_in_minutes = 2
numbers_of_layers = (preparation_time_in_minutes * 4) # Multiply 4 layers
print(numbers_of_layers, "layers of lasanga") preparation_time_in_minutes()
def elapsed_time_in_minutes():
EXPECTED_BAKE_TIME = 40
bake_time_remaining = 30
elapsed_bake_time = (EXPECTED_BAKE_TIME - bake_time_remaining)
preparation_time_in_minutes = 2
numbers_of_layers = (preparation_time_in_minutes * 4) # Multiply 4 layers
elapsed_time_in_minuites = (elapsed_bake_time numbers_of_layers)
def bake_time_remaining():
EXPECTED_BAKE_TIME = 40
bake_time_remaining = 30
elapsed_bake_time = (EXPECTED_BAKE_TIME - bake_time_remaining)
preparation_time_in_minutes = 2
numbers_of_layers = (preparation_time_in_minutes * 4) # Multiply 4 layers
elapsed_time_in_minuites = (elapsed_bake_time numbers_of_layers)
print(elapsed_time_in_minuites, "Total cooking and preparation time") bake_time_remaining()
https://i.stack.imgur.com/Ryhsl.jpg
CodePudding user response:
Does the website provide any error output?
CodePudding user response:
Welcome to python and programming in general.
The site is looking for a variable called EXPECTED_BAKE_TIME
which means you need define it. The trick here is you don't need to create a function.
You can simply do this on the root of the file like so...
EXPECTED_BAKE_TIME = 40
def bake_time_remaining():
"""Calculate the bake time remaining."""
...