Question: Help me write a diagnostic program that will be able to tell a user whether a date is valid. The program should begin by asking

Help me write a "diagnostic" program that will be able to tell a user whether a date is valid. The program should begin by asking the user to supply a date in the following format:YYYYMMDDFor example,20200218would be interpreted as "February 18th, 2020". You can always assume that the user will supply an 8 digit integer. Next, the program should "diagnose" the date as one of the following: Whether the year provided is a Leap Year or not. During a Leap Year February has 29 days, and in non-Leap Years February only has 28 days. You can compute whether a year is a leap year by using the following algorithm: A Leap Year is any year that can be exactly divided by 4 (such as 2016, 2020, 2024, etc) ... EXCEPT if it can be exactly divided by 100, then it isn't (such as 2100, 2200, etc) ... EXCEPT if it can be exactly divided by 400, then it is (such as 2000, 2400) Note that the year will ALWAYS be valid. For example, 0000 is valid year, as is 9999 Next, determine if the month / day combination is valid. For example, September 30th is valid, but September 37th is not. The following chart may help you to identify whether these combinations are valid or not: Months with 30 days: September, April, June, November Months with 31 days: January, March, May, July, August, October, December Months with 28 days (29 during a leap year): Feburary If the combination is invalid you should report this to the user. If the combination is valid you should report it to the user using the full name of the month. For example, if the date entered was 20210213 you would classify the month as "February" You should also report the date using the correct English label for the day. For example, "February 1st" - note the "st" after the number 1. In English the following are valid labels for the numbers 1-31: 1, 21 and 31:st 2 and 22:nd 3 and 23:rd All other numbers:th Here are a few sample runnings of the program (underlined text indicates user input): Enter a date (YYYYMMDD): 20210213 2021 is NOT a leap year February 13th 2021 is a valid date How would you do this program below without using def def isLeapYear(year): isLeap = False if(year % 4 == 0): isLeap = True if (year % 100 ==0 and year % 400 == 0): isLeap = True elif(year%100!=0): isLeap = True else: isLeap = False return isLeap def getMonthName(monthNumber): month="" if(monthNumber ==1): month="January" elif(monthNumber == 2): month = "February" elif(monthNumber == 3): month = "March" elif(monthNumber == 4): month = "April" elif(monthNumber == 5): month = "May" elif(monthNumber == 6): month = "June" elif(monthNumber == 7): month = "July" elif(monthNumber == 8): month = "August" elif(monthNumber == 9): month = "September" elif(monthNumber == 10): month = "October" elif(monthNumber == 11): month = "November" elif(monthNumber == 12): month = "December" else: month = "Invalid" return month def getSuffix(dayNumber): if(dayNumber == 1 or dayNumber ==21 or dayNumber ==31): return "st" elif(dayNumber==2 and dayNumber==22): return "nd" elif(dayNumber==3 and dayNumber ==23): return "rd" else: return "th" date = input("Enter a date (YYYYMMDD):") year = int(date[0:4]) month = int(date[4:6]) day = int(date[6:8]) if(isLeapYear(year)): print(str(year)+" is a leap year") else: print(str(year)+" is NOT a leap year") print(month) monthStr = getMonthName(month) if(monthStr =="Invalid"): print("Month is invalid") else: dayStr = str(day)+getSuffix(day) if(month == 4 and month == 6 and month == 9 and month == 11 ): if(day<=30): print(monthStr, dayStr+" is a valid date") else: print(monthStr, dayStr+" is a NOT valid date") elif(month == 2): if(isLeapYear(year) and day<=29): print(monthStr, dayStr+" is a valid date") elif(isLeapYear(year) == False and day<=28): print(monthStr, dayStr+" is a valid date") else: print(monthStr, dayStr+" is a not a valid date") else: if(day<=31): print(monthStr, dayStr+" is a valid date") else: print(monthStr, dayStr+" is a NOT valid date") 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!