Question: Need help fixing my phyton programming. Write a program that reads the WorldSeries.txt file and creates a dictionary in which the keys are the names
Need help fixing my phyton programming.
"Write a program that reads the WorldSeries.txt file and creates a dictionary in which the keys are the names of the teams and each key's associated value is the number of times the team has won the World Series. The program should also create a dictionary in which the keys are the years and each key's associated value is the name of the team that won that year.The program should prompt the user for a year in the range 1903-2009. It should then display the name of the team that won the World Series that year and the number of times that team has won the World Series"
The following is what I have so far:
file_read =open('WorldSeries.txt', 'r')
team = file_read.readline() teamname = team.rstrip(' ') year =1903
dctnum ={} dctyear ={}
dctyear[year] =teamname dctnum[teamname] =1
while team !='':
if teamname in dctnum: dctnnum[teamname] +=1 else: dctnum[teamname] =1 team=file_read.readline() teamname=team.rstrip()
year+= 1 dctyear[year]=teamame
file_read.close()
year = input('Enter a year to know about winning team (1903-2009): ')
if year>='1903' and year <='2009': rec= dctyear[int(year)] print('The team' + rec + 'have won' + str(dctnum[rec] +'times')
else: print ('Invalid Year')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
