UPDATED
The problem is that you are never checking strictly for the proper input format and rejecting the user if the input is bad. There are holes in your logic to detect a format mismatch. Namely a glaring hole if they mix the two formats
You currently use one regular expression to see that the text ROUGHLY follows the patterns, however it is not strict enough. You know the exact patterns that are allowed, and there are two of them, I'd suggest checking them both. There are other differences between the two formats besides placement of delimiters that you are completely ignoring. More specifically your regex split
is not validating the formats, it's only splitting your components. It's dandy as a splitter and a nice improvement to alternatives I've seen used. But it is not validating other things.
HINT
A hint is that you can do the check for validation in exactly 1 or 2 regex match checks. (1 is a bit more advanced, the 2 case is very straight forward and basically combines what kcw78 outlines in his checking logic) If you search for other answers, I have provided for this exact question you can find answers, but I'd suggest figuring it out yourself and asking questions.
I also suggest you break apart your code. conversion
should just do conversion, nothing more and nothing less. If you are going to use functions use them, otherwise you might as well dump this code all in main.
Hints:
using a while True
loop generally indicates you are wrong and don't know what you are doing in this course
conversion
shouldn't be prompting the user for input; that should happen in main or in another dedicated function which obtains and validates input
conversion
should have validated input passed into it,
- It should probably
return
output instead of printing it itself
What happens if the month they enter is textual garbage, like if they enter "Enzouary"?
new
What happens if they enter "September/08/2024"? or "12 1, 2024" Both should be rejected. But your reg-ex is not rejecting them.
What happens if they enter "September 08 2024" or "09 08 2024" or "september, 8 2024" or "september,8,2024" or "september 8/2024"
what about "08/sep1/oo2024oo"
what about "#$/afd1@/20$d" ?
Try using some bad inputs and ask yourself did the program do what it was supposed to do for these bad inputs?
"They are not what they should be" is not accurate now was your original problem statement. It's not about 'mixed formats' it is about incorrect formats, the input hasn't been properly validated per the instructions.
You can't make them work? What have you tried doing?
check50
fails becauseOctober/9/1701
is not a valid input format. Valid formats areOctober 9, 1701
and10/9/1701
. Slashes can only be used when all input is numeric values. When you enter a month name, you need the 'comma' format.September 8 1636
is invalid because it is missing the comma.