+ 2

I fail to pass sololearn tests

My regards to everyone. I am trying to solve every riddle in sololearn environment but I got stuck with the one called "convert date from US to EU'", particularly with passing sololearn tests. When I test it by myself in full python environment, every input gives me a desired outcome, however the code fails to pass some sololearn tests. Can you please give me a hint where to look at. Here is my code, I hope I did the right way reffing to it https://code.sololearn.com/c9UWg5Yebd2u/?ref=app

8th Apr 2020, 9:06 AM
Shamil Erkenov
Shamil Erkenov - avatar
40 Antworten
+ 1
You can also try this approach!!!! import re months = ["January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] s= input() if bool(re.search('[a-zA-Z]', s)): n=months.index(re.findall('[a-zA-Z]+', s)[0])+1 date=s.split(',') print(re.findall('[\d]+',date[0])[0]+'/'+str(n)+'/'+date[1].strip()) else: n=s.split('/') print(n[1]+'/'+str(n[0])+'/'+n[2])
10th Apr 2020, 12:33 AM
Rohit Anand
Rohit Anand - avatar
+ 12
you should put a space after the comma, the input must fit the codecoach instructions 'November 01, 2010'
8th Apr 2020, 9:54 AM
John Robotane
John Robotane - avatar
+ 7
Rik Wittkopp string isn't a keyword ;) The rest I fully agree with.
8th Apr 2020, 9:36 AM
Russ
Russ - avatar
+ 5
Wow, thank you very much guys for brain storming ♥️ this feeling when strangers help you to solve a problem is just amazing, if only in every domain of life it's implied
8th Apr 2020, 9:57 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 5
I think that with every test just another skill of coding that we got is tested. For example, for this task they want to test us how to create a function🙆
9th Apr 2020, 6:40 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 4
I think that in output2 you should print splt_string[2] instead of date[1] output2 = '{}/{}/{}'.format(int(date[0]), month_dict[month], splt_string [2])
8th Apr 2020, 9:32 AM
John Robotane
John Robotane - avatar
+ 4
Russ Thanks for the correction. I will review........again 😁
8th Apr 2020, 9:37 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
Not a keyword, ok 😅
8th Apr 2020, 9:39 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 4
Code Crasher I thought that might be the case too🤔
8th Apr 2020, 9:40 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 4
Oh, I got it, I thought there is no space in 19,2019
8th Apr 2020, 9:54 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 4
Code Crasher my code is just for the challenge so I don't validate the input, but you are right in your point.
9th Apr 2020, 5:08 AM
Jonathan Alvarado
Jonathan Alvarado - avatar
+ 3
Rik Wittkopp I converted it into a int() in case if input is '01/01/2010' and output must be '1/1/2010'. I didn't know about 'string' being a keyword, thank you for your answer
8th Apr 2020, 9:37 AM
Shamil Erkenov
Shamil Erkenov - avatar
+ 3
Just go back and read the chapter again is the good idea
10th Apr 2020, 2:38 AM
👑Mahesh Khatri👑
👑Mahesh Khatri👑 - avatar
+ 2
no, splt_string contains ['month_name', 'date_no,', 'year'] as Russ said it.
8th Apr 2020, 9:47 AM
John Robotane
John Robotane - avatar
+ 2
us=input() def temp(month): month=month.lower() d={"january":1,'february':2,'march': 3,'april':4,'may':5,'june':6,'july':7,'august':8,'september':9,'october':10,'november':11,'december':12} m=str(d[month]) return m if "/" in us: us=us.split('/') eu=[] eu.append(us[1]) eu.append (us[0]) eu.append(us[2]) eu="/".join(eu) else: us=us.split (' ') eu=[] euu=us[1].split (',') eu.append(euu[0]) eu.append (temp(us[0])) euuu=euu[1] eu.append(us[2]) eu='/'.join(eu) print(eu)
9th Apr 2020, 10:45 PM
Prashant Priyadarshi
Prashant Priyadarshi - avatar
+ 1
Looking at it now
8th Apr 2020, 9:20 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Your code doesn't pass the second test and I think won't pass any test in that format. In your second section, string.split() will give you ['month_name', 'day_no,', 'year'] but you seem to treat it like the day and the year will appear in the same element as each other.
8th Apr 2020, 9:32 AM
Russ
Russ - avatar
+ 1
Shamil Erkenov Ok buddy. The main problem seems to be that when an input is something like November 17, 2009 your output does not generate the year. Might I also suggest that you replace the word string with date. string is a python keyword which may cause confusion with the program. Also, I don't think you need to convert aspects of your string into integers as you are not doing any math. See how you go. Please excuse me for not providing a direct answer, but code coach is all about being able to resolve the problem yourself.
8th Apr 2020, 9:34 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Shamil Erkenov did you try what I suggested? replace date[1] with splt_string[2] in output2 output2 = '{}/{}/{}'.format(int(date[0]), month_dict[month], splt_string [2]) I don't think it's a date validation problem.
8th Apr 2020, 9:43 AM
John Robotane
John Robotane - avatar
+ 1
I just tested it, SIGH! I thought it operated like int or float, but now I know better. Thanks guys. 😁👍
8th Apr 2020, 9:44 AM
Rik Wittkopp
Rik Wittkopp - avatar