How to determine if the string is valid There are certain criteria that the date in the slashes format must fit to be valid: The string must separate the day, month and year with slashes. This criteria makes the strings "03142022" or "10,24,2025" invalid date strings. Day, month, and year must be composed of digits only. This makes the string "Jan/12/2022" invalid. Note: .isdigit() function is perfect for checking if a string is numeric (if it can be converted to an integer) The month must be within 1 and 12. This criteria makes the string "13/28/2025" invalid. The day must be within the max days limit for a given month. For instance, there are only 30 days on November, but 31 days in December. Therefore, "11/31/2022" is invalid while "12/31/2022" is valid. You will have a dictionary for how many days each month has. For simplicity, let's assume that February always has 28 days. Requirements for the program Write a function validate_date(date_string) which takes in a datestring and checks if the datestring is valid. If the string is valid, we want to return a tuple containing True and the date_string itself. If the string is invalid for a specific reason, we want to return a tuple containing False and the error code explaining what was wrong with the date string passed in.

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter3: Performing Calculations With Formulas And Functions
Section: Chapter Questions
Problem 4.9CP
icon
Related questions
Question

How to determine if the string is valid

There are certain criteria that the date in the slashes format must fit to be valid:

  • The string must separate the day, month and year with slashes. This criteria makes the strings "03142022" or "10,24,2025" invalid date strings.

  • Day, month, and year must be composed of digits only. This makes the string "Jan/12/2022" invalid. Note: .isdigit() function is perfect for checking if a string is numeric (if it can be converted to an integer)

  • The month must be within 1 and 12. This criteria makes the string "13/28/2025" invalid.

  • The day must be within the max days limit for a given month. For instance, there are only 30 days on November, but 31 days in December. Therefore, "11/31/2022" is invalid while "12/31/2022" is valid. You will have a dictionary for how many days each month has. For simplicity, let's assume that February always has 28 days.

Requirements for the program

  • Write a function validate_date(date_string) which takes in a datestring and checks if the datestring is valid. If the string is valid, we want to return a tuple containing True and the date_string itself. If the string is invalid for a specific reason, we want to return a tuple containing False and the error code explaining what was wrong with the date string passed in.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage