+ 6

Code Coach : Convert US date to Europe

I couldn't find what went wrong in my (python) code. The last test case failed, but all the other 4 have passed. I can't see the test case, so i can't figure out the input and see what the problem is. Wondering if anybody had this problem. 👇👇👇👇 Here is the code =================================== in_day = input() month={"January":"1","February":"2","March":"3","April":"4","May":"5","June":"6","July":"7","August":"8","September":"9","October":"10","November":"11","December":"12"} #separate month, date and year in_day = in_day.replace("/", " ") in_day = in_day.replace(",", "") word_list = in_day.split() if word_list[0].isalpha(): mm = month[word_list[0]] else: mm = word_list[0] dd = word_list[1] yyyy = word_list[2] out = "{d}/{m}/{y}".format(d=dd ,m =mm ,y=yyyy) print(out) ===================================

11th Jan 2020, 1:57 PM
Besufkad Tsegaye
Besufkad Tsegaye - avatar
23 Answers
+ 11
Comma needs to vanish not become a space as it is followed by a space.
12th Jan 2020, 1:56 AM
John Wells
John Wells - avatar
+ 6
Solved! Thanks to John Wells and TheWh¡teCat.
12th Jan 2020, 2:36 PM
Besufkad Tsegaye
Besufkad Tsegaye - avatar
+ 5
Besufkad Tsegaye , I think you wrote wrong the key for August => you wrote "Augest". Change it and try again 🐱
11th Jan 2020, 2:28 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 4
import calendar as c s=str(input()) l=[] for i in range(1,13): l.append(c.month_name[i]) if '/' in s: v=s.split("/") else: v=s.replace(',',"").split(" ") day=v[1] year=v[2] if v[0].isalpha(): mon=l.index(v[0])+1 else: mon=v[0] print(f"{day}/{mon}/{year}") Here is my code , all test case passed.
22nd Sep 2021, 5:29 AM
AYUSH
AYUSH - avatar
+ 2
May 1, 2345 does not get processed as it fails len(usdate) <= 10 and len(usdate) > 13.
18th May 2020, 8:33 AM
John Wells
John Wells - avatar
+ 1
January 10, 2020 becomes 10/01/2020 becomes 1/01/2020 as you remove the first 0 trying to get the second.
16th May 2020, 12:32 PM
John Wells
John Wells - avatar
+ 1
n = input() if '/' in n: n = n.split("/") month = n[0] date = n[1] year = n[2] print(f"{date}/{month}/{year}") else: m = ["NULL", "January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] n = n.split(" ") month = n[0] date = n[1].split(",")[0] year = n[2] print(f"{date}/{m.index(month)}/{year}")
8th Feb 2022, 1:15 AM
GURURAJ KL
GURURAJ KL - avatar
0
John Wells woooohooo finally solved, thanks a lot for helping. It's been such a nice learning experience. Looking forward to learn more 🍻
18th May 2020, 10:18 AM
Tshering Tamang
Tshering Tamang - avatar
0
# ------ Date converter ------ import re x = input() check = re.compile(r'(\d\d|\d)?/(\d|\d\d)?/(\d{4})') mo1 = check.findall(x) if mo1 != []: date_regex = re.compile(r'(\d\d|\d)?/(\d|\d\d)?/(\d{4})') mo = date_regex.search(x) print(f'{mo.group(2)}/{mo.group(1)}/{mo.group(3)}') else: name_d = re.compile(r'(\w*) (\d|\d\d),(\d{4})') mo = name_d.search(x) if mo.group(1) == 'January': print(f'{mo.group(2)}/1/{mo.group(3)}') elif mo.group(1) == 'February': print(f'{mo.group(2)}/2/{mo.group(3)}') elif mo.group(1) == 'March': print(f'{mo.group(2)}/3/{mo.group(3)}') elif mo.group(1) == 'April': print(f'{mo.group(2)}/4/{mo.group(3)}') elif mo.group(1) == 'May': print(f'{mo.group(2)}/5/{mo.group(3)}') elif mo.group(1) == 'June': print(f'{mo.group(2)}/6/{mo.group(3)}') elif mo.group(1) == 'July': print(f'{mo.group(2)}/7/{mo.group(3)}') elif mo.group(1) == 'August': print(f'{mo.group(2)}/8/{mo.group(3)}') elif mo.group(1) == 'September': print(f'{mo.group(2)}/9/{mo.group(3)}') elif mo.group(1) == 'October': print(f'{mo.group(2)}/10/{mo.group(3)}') elif mo.group(1) == 'November': print(f'{mo.group(2)}/11/{mo.group(3)}') elif mo.group(1) == 'December': print(f'{mo.group(2)}/12/{mo.group(3)}')
9th Oct 2020, 3:58 AM
Dawit Mekonnen
Dawit Mekonnen - avatar
0
African Nani Puji Versandi, Bro U just copy paste my code.
2nd Feb 2022, 7:40 AM
AYUSH
AYUSH - avatar
0
import re date = input() if re.match(r"[A-Za-z]",date): if re.match(r"January",date): date = re.sub("January", "1", date) elif re.match(r"February",date): date = re.sub("February", "2",date) elif re.match(r"March",date): date = re.sub("March", "3",date) elif re.match(r"April",date): date = re.sub("April", "4",date) elif re.match(r"May",date): date = re.sub("May", "5",date) elif re.match(r"June",date): date = re.sub("June", "6",date) elif re.match(r"Jule",date): date = re.sub("Jule", "7",date) elif re.match(r"August",date): date = re.sub("August", "8",date) elif re.match(r"September",date): date = re.sub("September", "9",date) elif re.match(r"October",date): date = re.sub("October", "10",date) elif re.match(r"November",date): date = re.sub("November", "11",date) elif re.match(r"December",date): date
26th Feb 2022, 3:58 PM
Przemysław Komański
Przemysław Komański - avatar
0
My solution od this: import re date = input() if re.match(r"[A-Za-z]",date): if re.match(r"January",date): date = re.sub("January", "1", date) elif re.match(r"February",date): date = re.sub("February", "2",date) elif re.match(r"March",date): date = re.sub("March", "3",date) elif re.match(r"April",date): date = re.sub("April", "4",date) elif re.match(r"May",date): date = re.sub("May", "5",date) elif re.match(r"June",date): date = re.sub("June", "6",date) elif re.match(r"Jule",date): date = re.sub("Jule", "7",date) elif re.match(r"August",date): date = re.sub("August", "8",date) elif re.match(r"September",date): date = re.sub("September", "9",date) elif re.match(r"October",date): date = re.sub("October", "10",date) elif re.match(r"November",date): date = re.sub("November", "11",date) elif re.match(r"Decembe
26th Feb 2022, 3:58 PM
Przemysław Komański
Przemysław Komański - avatar
0
import re date=input() month={"January":"1","February":"2","March":"3","April":"4","May":"5","June":"6", "July":"7","August":"8","September":"9","October":"10","November":"11","December":"12"} date=date.replace("/"," ") date=date.replace(","," ") lst=date.split() if lst[0] in month: month_nb=month[lst[0]] eu_date="{1}/{0}/{2}".format(month_nb,lst[1],lst[2]) print(eu_date) else: eu_date="{1}/{0}/{2}".format(lst[0],lst[1],lst[2]) print(eu_date)
17th May 2022, 8:37 AM
Dmitriy Panin
Dmitriy Panin - avatar
0
Guys all the test cases were passed except the 3rd... Can someone please help me out? date=input() if date[2]=="/": date=date.replace("/"," ") date=date.split() date[0],date[1]=date[1],date[0] print(date[0]+"/"+date[1]+"/"+date[2]) else: date=date.split() date[0],date[1]=date[1],date[0] if date[1]=="January": date[1]="01" elif date[1]=="February": date[1]="02" elif date[1]=="March": date[1]="03" elif date[1]=="April": date[1]="04" elif date[1]=="May": date[1]="05" elif date[1]=="June": date[1]="06" elif date[1]=="July": date[1]="07" elif date[1]=="August": date[1]="08" elif date[1]=="September": date[1]="09" elif date[1]=="October": date[1]="10" elif date[1]=="November": date[1]="11" elif date[1]=="December": date[1]="12" if len(date[0])>2: print(date[0][0:2]+"/"+date[1]+"/"+date[2]) else: print(date[0][0:1]+"/"+date[1
22nd Sep 2022, 9:20 AM
Mohammad Mahdi
Mohammad Mahdi - avatar
0
This is my code it's working well on computer terminal but in sololearn terminal it only pass two test case 🤐 date = input() #date = "07/26/2019" dict = {"January": "01", "February": "02", "March": "03", "April": "04", "May": "05", "June": "06", "July": "07", "August": "08", "September": "09", "October": "10", "November": "11", "December": "12"} div = date.split(" ") if len(div) == 1: spl = date.split("/") print(spl[1] + "/" + spl[0] + "/" + spl[2]) else: div = date.split(" ") div1 = div[1].split(",") for i in dict: if div[0] == i: print(div1[0]+"/"+dict[i]+"/"+div1[1])
22nd Sep 2022, 2:21 PM
Joel Justin
Joel Justin - avatar
0
d= input() x= d[0].isalpha() if x==True: dic={"January":1, "February":2, "March":3, "April":4, "May":5, "June":6, "July":7, "August":8, "September":9, "October":10, "November":11, "December":12 } d=d.split(", ") d1= d[0].split(" ") print(d1[1]+"/"+str(dic.get(d1[0]))+"/"+d[1]) else: date=d.split("/") print(date[1]+"/"+date[0]+"/"+date[2])
23rd Nov 2022, 8:01 PM
Mehanaz Salim
Mehanaz Salim - avatar
0
months = { "January" : 1, "February" : 2, "March" : 3, "April" : 4, "May" : 5, "June" : 6, "July" : 7, "August" : 8, "September" : 9, "October" : 10, "November" : 11, "December" : 12 } date_EU = input() #MM/DD/YYYY if date_EU[0].isalpha(): EU_list = date_EU.split(" ") month = months[EU_list[0]] date = EU_list[1].strip(",") date_US = f"{date}/{month}/{EU_list[-1]}" #DD/MM/YYYY print(date_US) else: EU_list = date_EU.split("/") EU_list[0], EU_list[1] = EU_list[1], EU_list[0] date_US = "/".join(EU_list) #DD/MM/YYYY print(date_US) #Here "/" is used to check if the user input has Alphabetical month name or number. # and convered the input into list and then swap the value if month and day if it in numeric format AND so if the month is alphabet using dictionary and "f-string".
16th Jan 2023, 5:55 AM
Alim Ansari
Alim Ansari - avatar
- 1
I have done it differently and the code passes all cases except for case 4 which is hidden and doesn't show what's wrong with the code. Please take a look and help me correct my mistake. The link to code is below. https://code.sololearn.com/cWPzkk3iMusT/?ref=app
16th May 2020, 8:55 AM
Tshering Tamang
Tshering Tamang - avatar
- 1
John Wells Oh, I didn't see that. Thanks a lot. I'll go and fix it.
17th May 2020, 6:55 PM
Tshering Tamang
Tshering Tamang - avatar
- 1
John Wells I have fixed the mistakes and updated the code but it still can't pass the case 4. I've tried various date combinations and all seem to get converted properly. I can't see what I'm missing here. Show me the way please. https://code.sololearn.com/cWPzkk3iMusT/?ref=app
18th May 2020, 5:18 AM
Tshering Tamang
Tshering Tamang - avatar