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:
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