Let's put your new function input and output skills to work. In this exercise, you are going to write a get_day_of_week() function, which will accept an input date in the format "YYYY-MM-DD" and return a string containing the day of the week (like "Monday").

Here are some example function calls and the resulting output.

# main code starts here
print(get_day_of_week("1776-07-04")) # US Declaration of Independence adopted
print(get_day_of_week("1918-11-11")) # World War I Armistice Day
print(get_day_of_week("3-16-2001")) # Test invalid date format

When run, you should see the following output. Notice that the function will handle invalid input (a date in the wrong format) with a nice error message instead of throwing an exception and crashing.

Thursday
Monday
Invalid YYYY-MM-DD Date
Your function will use the Python datetime library to perform the actual conversion of a date like "1776-07-04" to "Thursday". Because you haven't used this library before, the starting code begins with the statements needed to perform the conversion. It's up to you to write the full get_day_of_week() function by completing the following steps.

Near the top of the code, after the import statement and before the main code, add the "def" statement for get_day_of_week(). The function should accept one input parameter named target.
Inside the get_day_of_week() function body, start an exception-handling block with "try". It is possible that the input string is not in the right format, and we want our function to cleanly handle that situation without crashing. The two existing statements using the datetime functions to create the thisDate and dayOfWeek variables should go inside the try block.
Also inside the try block, add a return statement to send the dayOfWeek value to the calling code.
Add an "except" statement to mark the exception-handling block. Statements in this block will run if the target input is not in the right format, causing the datetime code to throw an exception. Inside the "except" block:
"return" the hard-coded value "Invalid YYYY-MM-DD Date"

import datetime

# define the get_day_of_week() function here

thisDate = datetime.datetime.strptime(target,"%Y-%m-%d")
dayOfWeek = thisDate.strftime("%A")

# main code starts here
print(get_day_of_week("1776-07-04")) # US Declaration of Independence adopted
print(get_day_of_week("1918-11-11")) # World War I Armistice Day
print(get_day_of_week("3-16-2001")) # Test invalid date format

Hint: You can parse the input string with datetime.datetime.strptime(target,"%Y-%m-%d")

When done, test your code and make sure it produces the expected results. You should also test today's date as input and verify that you get the right day of the week for today. It's always a good idea to test your code with known inputs and outputs to make sure everything is working correctly.

import datetime

def get_day_of_week(target):
try:
thisDate = datetime.datetime.strptime(target,"%Y-%m-%d")
dayOfWeek = thisDate.strftime("%A")
return dayOfWeek
except:
return "Invalid YYYY-MM-DD Date"

# main code starts here
print(get_day_of_week("1776-07-04")) # US Declaration of Independence adopted
print(get_day_of_week("1918-11-11")) # World War I Armistice Day
print(get_day_of_week("3-16-2001")) # Test invalid date format

# Test current date
print(get_day_of_week(datetime.datetime.now().strftime("%Y-%m-%d"))) # Today's day of the week