Convert Us date to Eu date
Hi, only one failed hidden case, any Help ? https://code.sololearn.com/ckH8cZNb3liN/?ref=app
7/23/2020 6:28:38 PM
A. Essabbere
8 Answers
New AnswerOkay, it's easy, the third test case tests a date of format M/d/yyyy. It's not specified, that numbers up to ten have a leading zero... Fix this in your pattern and it works.
Hello, I tried to solve it in a simple way and make the code more readable. I still haven't completed the Python course. Let me know if you have suggestions :) https://code.sololearn.com/cRic2JyR2YP5/?ref=app
text=input() text2=text.replace(',', '') if '/' in text: g=text.split('/') e=g[0:2] e.reverse() e=e+g[2:3] print('/'.join(map(str,e))) elif len(text)>10: w=text2.split(' ') l=w[0:2] l.reverse() w=l+w[2:3] if 'January' in w: w[1]='1' elif 'February' in w: w[1]='2' elif 'Mart' in w: w[1]='3' elif 'April' in w: w[1]='4' elif 'May' in w: w[1]='5' elif 'June' in w: w[1]='6' elif 'July' in w: w[1]='7' elif 'August' in w: w[1]='8' elif 'September' in w: w[1]='9' print('/'.join(w)) elif 'October' in w: w[1]='10' elif 'November' in w: w[1]='11' elif 'Desember' in w: w[1]='12' print('/'.join(w)) Maybe, this is a bad way, but I dont pro
Using datetime module: from datetime import datetime def dateconvert(x): try: new_format = datetime.strptime(x,'%m/%d/%Y').strftime('%-d/%-m/%Y') print(new_format) except ValueError: new_format = datetime.strptime(x,'%B %d, %Y').strftime('%-d/%-m/%Y') print(new_format) dateconvert(input())