Question
PYTHON Build a regular expressions based on informal specications to match specified patterns. Use a compiled regular expression in a Python program where appropriate. Use
PYTHON
- Build a regular expressions based on informal specications to match specified patterns.
- Use a compiled regular expression in a Python program where appropriate.
- Use Python's text processing str methods to generate a string format converter.
create a date format converter. Your program will convert a date in the format mm/dd/yyyy to the format month day, year.
Specify the required input format: mm/dd/yyyy Use a regular expression to validate the user input date format. If the format is incorrect raise a SystemExit (Links to an external site.)built-in Python exception.
Split the input string into respective month, day, and year components. Using a list to hold the month format as a string, convert the month input to the correct string month name. You will need to calculate an appropriate index to retrieve the correct month name from the month list.
Use the Gregorian calendar for valid dd:
The 12 Months
The Gregorian calendar (Links to an external site.) consists of the following 12 months:
- January (Links to an external site.) - 31 days
- February (Links to an external site.) - 28 days in a common year (Links to an external site.) and 29 days in leap years (Links to an external site.)
- March (Links to an external site.) - 31 days
- April (Links to an external site.) - 30 days
- May (Links to an external site.) - 31 days
- June (Links to an external site.) - 30 days
- July (Links to an external site.) - 31 days
- August (Links to an external site.) - 31 days
- September (Links to an external site.) - 30 days
- October (Links to an external site.) - 31 days
- November (Links to an external site.) - 30 days
- December (Links to an external site.) - 31 days
Below is an example conversion:
Enter a date (mm/dd/yyyy): 01/01/2018 The converted date is: January 01, 2018
Testing Specification
Testing Requirements: Use a loop construct to display 5 date conversions. The 1st 3 test cases should consist of valid user input. The 4th test case should be a leap year. The last 5th test case should consist of invalid user input.
Tips and Requirements
1. A list is used to store the month string names.
2. An index is calculated to retrieve the correct month from the list based on the user input.
3. A user prompt instructs the user of the expected input date format: mm/dd/yyyy
4. Obtain and validate user input. Specify a regular expression to validate the date format input by the user. Display an error message and raise a SystemExit sys.exit() if invalid.
5. The converted date output is in the format: month day, year
6. The output display: month is spelled out, the day is 2 digits dd and the year is 4 digits dddd.
7. Use named constants instead of literal values (i.e. NUM_DATES = 5).
8. Require 2 digits be supplied for mm and dd, 4 digits be supplied for year yyyy (require that the leftmost digit of the year not to be a 0). Use valid user input date range: 01/01/1000 - 12/31/2999.
Hand in only one .py file.
yournameLab4.py
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started