Question: I need help formatting my list to look like how it looks below, and I also need help to have my program close if the

I need help formatting my list to look like how it looks below, and I also need help to have my program close if the file put in is a different name. I also have my program below.

I need help formatting my list to look like how it looks

import datetime from calendar import * def main( ): resultList = monthrange(2020,1); print(resultList) print("There are ",resultList[1], " days in January of 2020") resultList = monthrange(2020,2); print(resultList) print("There are ",resultList[1], " days in February of 2020") resultList = monthrange(2021,2); print(resultList) print("There are ",resultList[1], " days in February of 2021")

def isValidMonth(tmpMonth): if not tmpMonth.isdigit(): return False if int(tmpMonth) 12: return False return True

def isValidYear(year): if not year.isdigit(): return False if (int(year) datetime.MAXYEAR): return False return True def isValidDay(stringDay,intergerMonth,intergerYear): if not stringDay.isdigit(): return False try: datetime.datetime(int(intergerYear),int(intergerMonth),int(stringDay)) return True except ValueError: return False

main()

filename = input ("enter name of file") infile = open('date.txt', 'r') for line in infile: line=line.replace(' ','') date=line.split('-') if not len(date)==3: print(line, end=' ') print('Invalid format') continue if not isValidMonth(date[0]): print(line,end=' ') print('Invalid Month') continue elif not isValidYear(date[2]): print(line,end=' ') print('Invalid year') continue elif not isValidDay(date[1],int(date[0]),int(date[2])): print(line,end=' ') print('Invalid day') continue else: print(line)

Reads date information from a text file Be sure to ask the user to enter the file name and end the program if the file doesn't exist. o Text file format will be similar to the information shown below: 12-31-2020 12-32-2020 1a-30-2020 12-?0-2020 12-30-99999 12-30--209 2-29-2020 2-29-2021 Read the data into a list o Process each entry, and determine if the date is valid or not. Print a report that shows the following: Entry Valid/Invalid Reason 12-31-2020 12-32-2020 1a-30-2020 12-20-2020 12-30-99999 Invalid Valid Invalid Invalid Invalid N/A Invalid Day Invalid Month Invalid Day Invalid Year etc

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 Databases Questions!