+ 2
Tasks in SoloLearn "Convers US date to EU date"
In test 4 and 5 it gives an error, but I don't know which error since there is a lock. Here is my solution: date = input() 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} if len(date) <= 10: a = date.split('/') else: a = date.split() a[0], a[1] = a[1], a[0] if len(a[1]) > 2: a[1] = months[a[1]] if len(date) < 11: print('{}/{}/{}'.format(a[0], a[1], a[2])) else: print('{}/{}/{}'.format(a[0][0], a[1], a[2]))
3 Réponses
+ 8
Aibek Zhaisanbay , the issue is the last line that prints the new date if input date was given starting with the month name.
...print(a[0][0])... #<<< this takes only one character (the first one) from the day
...print(a[0][:len(a[0])-1])... # <<< to get the correct slice use this notation
+ 4
date = input()
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}
if len(date) < 11:
a = date.split('/')
else:
a = date.split()
a[0], a[1] = a[1], a[0]
if len(a[1]) > 2:
a[1] = months[a[1]]
if len(date) < 11:
print('{}/{}/{}'.format(a[0], a[1], a[2]))
else:
print('{}/{}/{}'.format(a[0][:-1], a[1], a[2]))
Thank you to my friend for your help, if it wasn't for him, I would have been looking for a problem for a long time or would simply have abandoned this case indefinitely.😄
+ 2
Thank you so much!