Tell us what’s happening:
I have tested my codes with the test question and they all seem to be correct but I still got all 12 failed. Could anyone please help to take a look and provide feedback?
Sorry for the lengthy code, still a beginner here ><
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Challenge: Scientific Computing with Python Projects - Time Calculator
Link to the challenge:
Looking at one of the error output:
AssertionError: None != ‘3:07 PM’ : Expected calling “add_time()” with “11:55 AM”, “3:12” to return “3:07 PM”
This means function returned None, while it was expected to return 3:07 PM. None
is default value returned by function, if it doesn’t return anything explicitly with return
keyword. This function is expected to return the string, it shouldn’t print anything on it own.
As @sanity said, the first step would be to focus on the output of your code.
These projects are created within a function, and a will typically need to return
something from the function. A print
statement just prints to the screen, but does not return anything. The function will have to return
a value so that the tests can be ran on the returned value. If a value is simply printed, whether it is correct or not, the tests cannot be run, because the tests cannot take input from a print statement. A print statement simply just shows a user the value of something.
Example of a function:
def this_is_my_function():
If you need more clarification, let me know!
Also as @sanity was saying, you can look into the error statements to see what your code is actually outputting. This is useful for debugging the code and finding out where you went wrong.
======================================================================
FAIL: test_different_period (test_module.UnitTests)
Traceback (most recent call last):
File “/home/runner/boilerplate-time-calculator/test_module.py”, line 15, in test_different_period
self.assertEqual(actual, expected, ‘Expected calling “add_time()” with “11:55 AM”, “3:12” to return “3:07 PM”’)
AssertionError: None != ‘3:07 PM’ : Expected calling “add_time()” with “11:55 AM”, “3:12” to return “3:07 PM”
Where is says…
AssertionError: None != ‘3:07 PM’ : Expected calling “add_time()” with “11:55 AM”, “3:12” to return “3:07 PM”
None
is your code’s output value, and ‘3:07 PM’
is the output value you need to pass the test.