this is what I’v done so far. I’m new to python. what I want to know is how to get an invalid date when a character is present in the date string. such as 01/x1/2012
also if a negative number is input for the date, to print out invalid date.
not using imports or calendars
dateStr = input("Date: ")
monthStr, dayStr, yearStr = dateStr.split("/")
months = ["January", "February","March", "April", "May", "June", "July", "August","September","October", "November","December"]
monthStr = months[int(monthStr)- 1]
print ("The date is:", monthStr, dayStr+",", yearStr)
if chr in dateStr:
print("Invalid date")
These things are usually much easier done with
datetime:without datetime: