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
mm/dd/yyyy format).
Submit the function plus a main function.
The main function asks the user for the date and then calls the
function.
The file should be opened and closed inside the
function.
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[4]) == 2 and List[4] not in state_abbreviations: state_abbreviations.append(List[4]) #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[4]==state_abbr): # if yes append into locations locations.append(data[3]) # 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
Date,FIPS,MMWR_week,Recip_County,Recip_State,Series_Complete_Pop_Pct,Series_Complete_Yes,Series_Complete_12Plus,Series_Complete_18Plus,Series_Complete_65Plus,Administered_Dose1_Recip,Administered_Dose1_Recip_12Plus,Administered_Dose1_Recip_18Plus,Administered_Dose1_Recip_65Plus,SVI_CTGY,Metro_status
11/14/2021,13265,46,Taliaferro
County,GA,22.1,340,340,317,94,364,364,335,97,D,Non-metro
11/14/2021,21219,46,Todd
County,KY,38.3,4705,4705,4504,1476,5282,5280,5050,1609,D,Non-metro
11/14/2021,26047,46,Emmet
County,MI,68.5,22875,22873,21581,7257,24135,24124,22842,7686,A,Non-metro
11/14/2021,40079,46,Le Flore
County,OK,35.5,17684,17684,16861,6257,20247,20210,19226,6819,D,Metro
11/14/2021,16057,46,Latah
County,ID,50.1,20098,,19898,5177,22467,,22050,5658,A,Non-metro
11/14/2021,42049,46,Erie
County,PA,55.3,149088,149017,140484,42337,181955,180551,170312,53136,C,Metro
11/14/2021,16047,46,Gooding
County,ID,36.5,5545,,5544,1957,6256,,6254,2107,C,Non-metro
11/14/2021,13175,46,Laurens
County,GA,25.4,12064,12062,11150,2805,13866,13858,12713,3037,D,Non-metro
11/12/2021,21125,45,Laurel
County,KY,36.9,22457,22457,21374,6798,25068,25018,23782,7245,D,Non-metro
11/12/2021,20119,45,Meade
County,KS,36.4,1467,1467,1390,431,1867,1867,1777,704,B,Non-metro
11/12/2021,26015,45,Barry
County,MI,44.9,27640,27640,26184,9055,28867,28866,27404,9482,A,Metro
11/12/2021,38027,45,Eddy
County,ND,48.4,1108,1108,1070,437,1180,1179,1137,463,B,Non-metro
11/12/2021,13321,45,Worth
County,GA,17.9,3625,3625,3355,805,3977,3976,3640,825,C,Metro
11/12/2021,17155,45,Putnam
County,IL,52.1,2990,2987,2836,1057,3218,3213,3049,1114,A,Non-metro
11/12/2021,31067,45,Gage
County,NE,39.3,8456,8455,7938,3155,,,,,A,Non-metro
11/12/2021,13309,45,Wheeler
County,GA,11.1,869,869,791,169,1017,1015,909,178,D,Non-metro
11/12/2021,21011,45,Bath
County,KY,48.5,6068,6068,5695,1851,6642,6624,6211,1962,C,Non-metro
10/20/2021,39051,42,Fulton
County,OH,47.2,19894,19894,18950,6580,21218,21218,20192,6806,A,Metro
10/20/2021,40105,42,Nowata
County,OK,36.3,3662,3662,3509,1283,4653,4653,4464,1590,C,Non-metro
10/20/2021,48207,42,Haskell
County,TX,0,0,0,0,0,0,0,0,0,D,Non-metro
10/20/2021,48351,42,Newton
County,TX,0,0,0,0,0,0,0,0,0,C,Metro
10/20/2021,72107,42,Orocovis
Municipio,PR,71.7,14492,14492,13295,2865,16464,16460,15060,3455,D,Metro
10/19/2021,72143,42,Vega Alta
Municipio,PR,58.7,21157,21156,19376,4792,23395,23392,21393,5194,C,Metro
10/19/2021,13189,42,McDuffie
County,GA,18.3,3902,3901,3588,940,4407,4404,3980,978,D,Metro
10/19/2021,13229,42,Pierce
County,GA,24.4,4748,4748,4587,1742,5518,5518,5312,1916,C,Non-metro
10/19/2021,21209,42,Scott
County,KY,58.2,33153,33152,30501,6821,38675,38671,35363,7880,B,Metro
9/20/2021,37135,38,Orange
County,NC,63.9,94884,94553,87089,20365,110061,109606,100772,22583,B,Metro
9/20/2021,22073,38,Ouachita
Parish,LA,37.7,57804,57803,54960,17884,66423,66421,62530,18871,D,Metro
9/20/2021,53047,38,Okanogan
County,WA,59.5,25114,25114,24085,7884,27874,27872,26534,8271,D,Non-metro
9/20/2021,36015,38,Chemung
County,NY,50.5,42131,42129,39518,12737,45509,45503,42555,13575,B,Metro
8/26/2021,18137,34,Ripley
County,IN,38.8,10982,10981,10610,4258,11833,11832,11361,4392,B,Non-metro
8/26/2021,22117,34,Washington
Parish,LA,30.9,14270,14270,13838,5702,17908,17905,17123,6327,D,Non-metro
8/26/2021,38097,34,Traill
County,ND,42,3372,3367,3211,1145,3761,3751,3538,1231,A,Non-metro
8/26/2021,31163,34,Sherman
County,NE,33.6,1007,1007,975,495,,,,,A,Non-metro
7/21/2021,30029,29,Flathead
County,MT,31.8,33060,33057,31955,12692,36001,35996,34575,13605,A,Non-metro
7/21/2021,56015,29,Goshen
County,WY,29.4,3880,3880,3805,1851,4123,4123,4026,1915,B,Non-metro
7/21/2021,54083,29,Randolph
County,WV,27.6,7912,7908,7593,3191,9423,9417,9000,3604,C,Non-metro
7/21/2021,UNK,29,Unknown
County,AS,0,22849,22847,21366,2460,27809,27803,25081,2706,,
7/21/2021,27003,29,Anoka
County,MN,44.4,158419,158027,148744,39045,171048,170479,160209,40895,A,Metro
7/21/2021,13133,29,Greene
County,GA,33.6,6163,6163,6093,3290,6786,6786,6671,3596,C,Non-metro
7/21/2021,55125,29,Vilas
County,WI,53,11773,11773,11562,5947,12393,12393,12115,6143,A,Non-metro
7/21/2021,38093,29,Stutsman
County,ND,41.1,8511,8500,8231,2926,9782,9759,9434,3473,A,Non-metro
6/23/2021,48231,25,Hunt County,TX,0,0,0,0,0,0,0,0,0,D,Metro
6/23/2021,46015,25,Brule
County,SD,31.1,1650,1650,1608,495,,,,,C,Non-metro
6/23/2021,36029,25,Erie
County,NY,52.5,482621,482613,462025,135177,526536,526498,500940,143752,B,Metro
5/14/2021,40069,19,Johnston
County,OK,25.5,2831,2831,2812,1222,3490,3490,3462,1431,D,Non-metro
5/14/2021,42119,19,Union
County,PA,34.8,15615,15613,15537,5773,20034,20033,19760,6846,B,Non-metro
5/14/2021,5023,19,Cleburne
County,AR,25.4,6340,6340,6323,3841,7705,7705,7673,4324,A,Non-metro
4/14/2021,17163,15,St. Clair
County,IL,26.2,68140,68140,67905,26390,105219,105207,103778,35560,C,Metro
4/14/2021,37051,15,Cumberland
County,NC,26,87235,87211,87023,29328,121382,121326,120332,33125,D,Metro
4/14/2021,38083,15,Sheridan
County,ND,24.9,327,327,327,207,369,369,369,219,A,Non-metro
3/17/2021,51169,11,Scott
County,VA,10.2,2200,2200,2199,1221,3605,3603,3598,2005,C,Metro
3/17/2021,18177,11,Wayne
County,IN,15.4,10127,10127,10121,7232,15167,15167,15156,8591,C,Non-metro
3/17/2021,48135,11,Ector County,TX,0,0,0,0,0,0,0,0,0,D,Metro
3/17/2021,26123,11,Newaygo
County,MI,9.5,4645,4645,4645,2970,8182,8180,8177,4732,C,Non-metro
2/24/2021,1049,8,DeKalb
County,AL,3.3,2337,2337,2336,1311,5129,5128,5126,3251,D,Non-metro
2/24/2021,13059,8,Clarke
County,GA,4,5178,5178,5178,3694,8133,8133,8132,5926,D,Metro
2/24/2021,12071,8,Lee
County,FL,6,46390,46390,46381,34511,109591,109580,109557,91231,C,Metro
2/24/2021,2195,8,Petersburg Census
Area,AK,26.7,871,871,870,459,1402,1402,1399,519,C,Non-metro
1/11/2021,26165,2,Wexford
County,MI,0,0,0,0,0,0,0,0,0,C,Non-metro
1/11/2021,13091,2,Dodge
County,GA,0,0,0,0,0,0,0,0,0,D,Non-metro
1/11/2021,48181,2,Grayson County,TX,0,0,0,0,0,0,0,0,0,C,Metro
1/10/2021,13191,2,McIntosh
County,GA,0,0,0,0,0,0,0,0,0,C,Metro
1/10/2021,4001,2,Apache
County,AZ,1.1,791,788,788,54,3647,3644,3644,944,D,Non-metro
1/10/2021,47163,2,Sullivan
County,TN,0.7,1118,1118,1118,132,9322,9322,9320,3895,C,Metro
1/10/2021,8099,2,Prowers
County,CO,0,0,0,0,0,0,0,0,0,D,Non-metro
1/5/2021,13307,1,Webster
County,GA,0,0,0,0,0,0,0,0,0,D,Non-metro
1/5/2021,54073,1,Pleasants
County,WV,0,0,0,0,0,0,0,0,0,B,Non-metro
1/5/2021,22117,1,Washington
Parish,LA,0,0,0,0,0,0,0,0,0,D,Non-metro
1/5/2021,46029,1,Codington
County,SD,0,0,0,0,0,0,0,0,0,A,Non-metro
1/5/2021,29073,1,Gasconade
County,MO,0,0,0,0,0,0,0,0,0,A,Non-metro