Write Lines Python Code Test Date Format Month Day Year Exists Given Text String Month Day Q37094371

Write a few lines of Python code to test if a date in the formatmonth/day/year exists in a given text string. For the month, dayand year, you can assume each contains minimum of one digit. So1/1/1 qualifies as a valid date


Solution


Code:

date = “1/1/1″mm,dd,yy = map(int,date.split(‘/’))if date.count(‘/’)==2 and mm<=12 and dd<=31: print(“Valid”)else: print(“Not Valid”)

Output:

date1/1/1 mm, dd, yy-map (int,date.split(/)) if date . count(/)--2 and mmc =12 and ddc=31: print(Valid) else: print(

date”1/1/1″ mm, dd, yy-map (int,date.split(‘/’)) if date . count(‘/’)–2 and mmc =12 and ddc=31: print(“Valid”) else: print(“Not Valid”) Valid

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.