Write a program to take input of random date in the format mm/dd/yyyy

  input, python, split

QUESTION:
Write a program to take input of date in the format mm/dd/yyyy
Verify that date is entered in the given format by

  1. checking the length of string
  2. checking the 3rd and 6th character of string
  3. checking that user enters only numbers in the date string

If user enters 02/15/1999, then your program should print 02 15 1999

Following is a sample run:

Enter date in the format mm/dd/yyyy: 02121999

Enough characters are not entered

Third and 6th character of the strings should have been /
Invalid Date Format

Following is another sample run:

Enter date in the format mm/dd/yyyy: ab/cd/yyyy

Only digits are allowed for mm, dd and yyyy
Invalid Date Format

Following is a sample run

Enter date in the format mm/dd/yyyy: Feb221999

Enough characters are not entered

Third and 6th character of the strings should have been /

Only digits are allowed for mm, dd and yyyy
Invalid Date Format

Following is a sample run:

Enter date in the format mm/dd/yyyy: 02/01/2019
02 01 2019

WHAT I’VE TRIED:

dateInput=(input("Enter date in the format MM/DD/YYYY: "))
while date= dateInput.split('/'):
if len(date)== 10: 
    print(date)
else:
    print ("Not enough characters entered.")
if (dateInput[2])== "/" and (dateInput[5]) == "/":
    print(date)
else:
    print("Invalid Date Format. Not enough characters are entered, the third and sixth character of the string should have been '/'")
if (dateInput.isalpha() == False):
    print(date)
else:
    print("Invalid Date Format. Only digits are allowed for MM/DD/YYY") 

WHAT I CAN USE:
I haven’t learned any advanced computer programming, this is for an entry level class. please include a basic answer so that I can understand. So far I’ve learned strings, loops, while, if and else, lists,break, split,ends with, isalpha,find,count,center,join, and strip. Nothing more complicated than that please

Source: Python Questions

LEAVE A COMMENT