Question: Define the is_legitimate_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the string denotes a legitimate date.

Define the is_legitimate_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the string denotes a legitimate date. The first three lines of your function should be defined as follows:

def is_legitmate_date(date_str): month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] 

where month_names is a list of month names and days_in_month is a list which contains the correct number of days in each month (note that February is set to 28 days), e.g., the third element of the month_names list is the month of March and the corresponding third element of the days_in_month list indicates that there are 31 days in March. If the parameter string does not contain exactly two parts then it is not legitimate and should return False. For example, the following code:

Test

print("1.", is_legitimate_date("January 31")) print("2.", is_legitimate_date("Auust 3")) print("3.", is_legitimate_date("January 32")) print("4.", is_legitimate_date("February 0")) print("5.", is_legitimate_date("December 31")) print("6.", is_legitimate_date("January 28 6")) 

Expected

1. True 2. False 3. False 4. False 5. True 6. False 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!