Respuesta :
Answer:
Following are the correct code to this question:
import re#import package for regular expression
def check_time(text):#defining a method check_time that accepts string value
p = r'(1[012]|[1-9]):[0-5][0-9][ ]{0,1}?(am|pm|AM|PM)'#defining string variable p that stores values
val = re.search(p, text)#defining val variable that check serachs p and text variable values
return val!= None#use return keyword to return val value
print(check_time("12:45pm"))#defining print method that calls method by input value
print(check_time("9:59 AM")) #defining print method that calls method by input value
print(check_time("6:60 am")) #defining print method that calls method by input value
print(check_time("five o'clock"))#defining print method that calls method by input value
Output:
True
True
False
False
Step-by-step explanation:
In the above-given program, some data is missing that is code file so, the correct code can be defined as follows:
In the above-given method, that is "check time" it uses 12-hour time format validation, that is tested by coding the regex and all the value validates in the "val" variables, that can be defined as follows:
- In the first step, its values should be in 1,2,3, ... 10,11,12
- In the second step, it values in Between hour and minutes, and there will be a colon.
- In the third step, the minutes variable should take the double-digit, that will be like 00,01 .... 59.
- In the last step, one space becomes permitted after an hour: a minute or no space for am or pm value.