Question: Convert us to eu | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Question: Convert us to eu

I used python for that question My code only supports numeric data of date time questions says that you can get a numeric date or a alphabetical date I'm confused with this. Only 1 Test passed out of 5 Tests https://sololearn.com/compiler-playground/cgFWXbjLslr2/?ref=app

23rd Mar 2024, 6:27 AM
Ayush
Ayush - avatar
8 Answers
+ 4
You need to deal with the second input format. I would say checking if there is a / inside the string should be enough. I would split the string and for the month you can use a dictionary. -> ["January", "1," , "2021"] Now it should be not so difficult to convert it to 1/1/2021 Btw: If you look at testcase 2 the expected output is 1/1/2021 Means for me that you are not allowed to add leading zeros to month or day. But your code does.
23rd Mar 2024, 7:44 AM
Denise Roßberg
Denise Roßberg - avatar
23rd Mar 2024, 7:47 AM
Ayush
Ayush - avatar
+ 1
The task description for reference: Sololearn > Community > Code Coach Convert US date to EU date (Medium) https://www.sololearn.com/coach/75?ref=app (I did it without importing any modules, just regular string manipulation.)
23rd Mar 2024, 12:32 PM
Rain
Rain - avatar
0
How your code handle test case #2, where the input is "January 1, 2021"?
23rd Mar 2024, 7:30 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Wong Hei Ming i noticed that and tried to fix with try: but failed.
23rd Mar 2024, 7:33 AM
Ayush
Ayush - avatar
0
AYUSH SHAH The code you posted doesn't have try...except block...
23rd Mar 2024, 7:36 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
Now
23rd Mar 2024, 7:37 AM
Ayush
Ayush - avatar
0
AYUSH SHAH I'm not sure if you can nest a try inside another try...didn't think of it before. Also, if there is an error you are returning a string "Invalid date format", it surely cannot be converted to a date...
23rd Mar 2024, 7:42 AM
Wong Hei Ming
Wong Hei Ming - avatar