how do i add this to my python program ask the user for a date (you MAY assume the user enters…
how do i add this to my python program
ask the user for a date (you MAY assume the user enters a
valid date in the valid mm/dd/yyyy format).
Then you should go through the file and display the location name
and state for the location having the HIGHEST PERCENTAGE of fully
vaccinated people on that date AND the location name and state for
the location having the LOWEST PERCENTAGE of fully vaccinated
people on that date.
once that works, make it into a function called YourPercentage
which accepts one value (a string representing the date in
Submit the function plus a main function.
The main function asks the user for the date and then calls the
The file should be opened and closed inside the
def UserStates(): # open file to read file = open("CovidResults.txt", "r") # list to store state abbreviation state_abbreviations =  # for loop in opened file for row in file: # striped each row stripped_row = row.strip() # split row separated by comma, into list List = stripped_row.split(',') # at 4th indeex of List is state abbreviation, #so check if abbreviation has 2 char and not already in state_abbreviation_list, for avoid duplicates if len(List) == 2 and List not in state_abbreviations: state_abbreviations.append(List) #close file file.close() # sort list state_abbreviations.sort() #print, line by line, one in each line print("state abbreviations in sorted order from the file 'CovidResults.txt'") for st in state_abbreviations: print(st) # this function find the locations from state abbreviation def WhereStates(): # open file file = open("CovidResults.txt", "r") # take input from user and convert into upper case state_abbr=input("Enter state abbreviation: ").upper() # to store locations locations= # iterate rows for row in file: # convert rows into list data=row.strip().split(",") # check the state abbrevation is equal to input if(data==state_abbr): # if yes append into locations locations.append(data) # close the file file.close() # print the result if (locations==): print("does not exist") else: print("The locations are: ") print(*locations, sep = "n") # main function def main(): # call UserStates function UserStates() WhereStates() #test #call main main()
this is the file-called – CovidResults