Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. date = input("Enter the date in DD/MM/YYYY format: ")
  2. date = date.split("/")
  3.  
  4. # Check if the date was correct
  5. if len(date) != 3:
  6.     print("The entered date is incorrect")
  7. else:
  8.     # Create variables for day, month and year
  9.     day = int(date[0])
  10.     month = int(date[1])
  11.     year = int(date[2])
  12.  
  13.     if len(str(year)) != 4:
  14.         print("The year is invalid")
  15.     else:
  16.  
  17.         # Check if the day is between 1 and 31, and month between 1 and 12
  18.         if 1 < day < 31 and 1 < month < 12:
  19.             # Change month to a string with month's name
  20.             if month == 1:
  21.                 month = "Jan"
  22.             elif month == 2:
  23.                 month = "Feb"
  24.             elif month == 3:
  25.                 month = "Mar"
  26.             elif month == 4:
  27.                 month = "Apr"
  28.             elif month == 5:
  29.                 month = "May"
  30.             elif month == 6:
  31.                 month = "Jun"
  32.             elif month == 7:
  33.                 month = "Jul"
  34.             elif month == 8:
  35.                 month = "Aug"
  36.             elif month == 9:
  37.                 month = "Sep"
  38.             elif month == 10:
  39.                 month = "Oct"
  40.             elif month == 11:
  41.                 month = "Nov"
  42.             elif month == 12:
  43.                 month = "Dec"
  44.             # Display date in "MMM DD, YYYY" format
  45.             fullDate = month + " " + str(day) + ", " + str(year)
  46.             print("The date is " + fullDate)
  47.         else:
  48.             # If the day or month values are incorrect
  49.             print("The date is invalid")
  50.             print("The day is " + str(day) + " and the month is " + str(month))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement