+ 1

Why does the test cases 3&4 isn't working properly??

n = input() b = n.count("/") 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' } if b>0: c = n.split("/") print(c[1]+"/"+c[0]+"/"+c[2]) else: x = str(n.split(" ")) for key, value in dic.items(): x = x.replace(key, value) h = x.replace(" ","") v = h.replace(",","") print(str(v[5]+"/"+v[2]+"/"+v[8:12])) You and your friends are going to Europe! You have made plans to travel around Europe with your friends, but one thing you need to take into account so that everything goes according to play, is that the format of their date is different than from what is used in the United States. Your job is to convert all your dates from MM/DD/YYYY to DD/MM/YYYY. Task: Create a function that takes in a string containing a date that is in US format, and return a string of the same date converted to EU. Input Format: A string that contains a date

17th Jul 2021, 2:30 AM
Shahir
Shahir - avatar
2 Answers
0
problem lays in last line,where u print v[2] and v[5],those only print one character.Say month is january,then v[2] will be 1.but what if month is december,december equals to 12,but v[2] will not be 12,because it only prints one character.
18th Jul 2021, 10:03 AM
Coder21
Coder21 - avatar
0
Solution:instead of converting n.split(“/“) to string,let it remain as list,then replace key with value in x[0],which holds month.after that replace “,” with “” in x[1].and finally concatenate and print them like u did it under if b>0:print(x[1]+”/“+x[0]+”/“+x[2]) and you will pass all tests)) I did it for u: https://code.sololearn.com/cZLgua0v0ECU/?ref=app
18th Jul 2021, 10:11 AM
Coder21
Coder21 - avatar