Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
@UpandAdam - yes, agreed. This is what I know: I tested the posted code, and it failed. Then I modified to use randint() and it passed. Go figure. It also passes if the stop value for randrange() is increased by 1. Solution modified to reflect this. There are 2 check50 issues. First, the error message about generates 10 problems before exiting is useless AND misleading. I wondered how check50 managed this. I suspect you are correct about seeding the generator. Every check50 output shows the same inputs for this test. :-)
Certainly you can replace while True with while Your_Logical_Test_for_True. However, the same infinite loop challenge exists with if Your_Logical_Test_for_True is poorly constructed and yields False when it should yield True. :-) The test for this PSet is relatively straight-forward - you can test for valid values of the day, month and year. However, you have to initialize the tested values prior to the while loop. As an aside, Dr. Malin uses the while True design in his regex examples. Just sayin... :-)
Question about your while True comment. I used that to re-prompt the user when the input is an invalid date format/data. Can you explain how you did that differently (w/out giving away the solution)?
Thanks, yeah it's a balance to share code without giving away the answer. I tried to thread the needle -- the if/elif/else block outlines the thought process without solving the problem. :-) (And, I just realized I left a line I intended to delete.) A quick note on regex: This is PSet 3, and Regular Expressions aren't covered (in depth) until Lecture 7. So, most students will probably use string manipulation methods.
You need to test for 2 different formats: A) TWO slashes or B) ONE comma, THEN apply proper conversion procedure. Other tests to consider: C) day and month are >0, and D) month name is in the list (personally, I prefer a dictionary). All other input should be re-prompted. I posted an "answer" with some psuedo code that might help your thought process.
check50 fails because October/9/1701 is not a valid input format. Valid formats are October 9, 1701 and 10/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.
If your code matches this post, it won't run due to indentation errors. I added indents to main() and longest_match(). (I also formatted your post so main() is included in the formatted code block.) Once that id corrected, it gets the right answer for several tests I spot checked.