Easy function excercise

Hello people, I’ve been trying to solve this problem for a while trying different options and reasoning them but none worked =( could you pls share the solution?

Given a string called date that is in the form MM/DD/YYYY , write a function called date_extractor that takes date as an input and returns three values, month , day , and year .

For example, if date = '6/16/2006' , the function should return month = 6 , day = 16 , and year = 2006 .

Leave all returned values as strings.

I tried to split the date inside the function using split("/") to get a list. Then I assigned indexes 0 1 and 2 to variables month, day, year. Then I tried to print the results using .format:
a

It works in pycharm but not in codeacademy. In codeacademy it tells me the following:

Enter a date: Traceback (most recent call last):

  • File “script.py”, line 7, in *
  • date=input("Enter a date: ")*
    EOFError: EOF when reading a line

Also I dont know why I cannot use “return” instead of “print” in this function. WHen I use return, it prints nothing to the console.
Here is the link to the excercise: https://www.codecademy.com/practice/tracks/learn-python-3/modules/learn-python3-strings?redirect_url=%2Flearn%2Flearn-python-3

Thanks a lot !!!

Hey @board9232566683!! Welcome to the Codecademy forums!! :grinning:

I can not give you the solution, but I can certainly point you in the right direction.


The EOFError is caused when input() fails to recieve the users input.
You can read the full documentation for it here:
docs.python.org/3/library/exceptions.html?highlight=eoferror#EOFError

In this case your code appears to work correctly, and I would guess the error apears because the console for this lesson is not capable of sending input to the program.
Not all of Codecademy’s lessons are capable of using the input function.

I would suggest hard coding a value into date:

date = "6/16/2006"
3 Likes

This is because return simply hands the data back to whatever is calling the function, but it does not do anything with the data after that.

An analogy

It’s like if you ordered a cake from a shop-that would be calling the function. When the cake is handed to you, that is like a return-the cake is given to you, but no-one else would know. If the person who gives you the cake instead says, “I’m giving you a cake”, other people know what is happening, but you don’t actually get the cake-that is printing.

So, unless you do anything with the returned data, i.e print it, store it,etc. the data returned from the function is not used.
I hope this helps!

3 Likes

Thank you very much guys!!! =)

2 Likes