Question
So my program is to read Program file and creates a dictionary in which the keys are the names of the teams and each keys
So my program is to read Program file and creates a dictionary in which the keys are the names of the teams and each keys 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 keys associated value is the name of the team that won that year. The program should prompt the user for a year in the range of 1903 through 2017. 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.
I keep on getting this error "TypeError: 'in
Once i change it though i get another error saying dict not hashable.
BASE_YEAR = 1903
def main(): # Local dictionary variables year_dict = {} count_dict = {} # Open the file for reading file_read = open('Program11.txt', 'r') # Read the first line of Program 11 team = file_read.readline() teamName = team.rstrip(' ')
winners(team, year_dict) year_dict[BASE_YEAR] = teamName count_dict[teamName] = 1
#Add base_year as a key and teamName also showResults(year_dict, count_dict) again(year_dict) file_read.close()
def showResults(year_dict, count_dict): # Receive user input year = int(input('Enter a year in the range 1903-2017: '))
# Print results if year == 1904 or year == 1994: print("The world series wasn't played in the year", year) elif year < 1903 or year > 2017: print('The data for the year', year, \ 'is not included in our database.') else: winner = year_dict[year] wins = count_dict[winner] print('The team that won the world series in ', \ year, ' is the ', winner, '.', sep='') print('They won the world series', wins, 'times.')
def winners(teams,years): while teams !='': if years in teams: years += 1 else: years = 1 Program FIle
Boston Americans
New York Giants
Chicago White Sox
Chicago Cubs
Chicago Cubs
Pittsburg Pirates
Philadelphia Athletics
Philadelphia Athletics
Boston Red Sox
Philadelphia Athletics
Boston Braves
Boston Red Sox
Boston Red Sox
Chicago White Sox
Boston Red Sox
Cincinnati Reds
Cleveland Indians
New York Giants
New York Giants
New York Yankees
Washington Senators
Pittsburgh Pirates
St. Louis Cardinals
New York Yankees
New York Yankees
Philadelphia Athletics
Philadelphia Athletics
St. Louis Cardinals
New York Yankees
New York Giants
St. Louis Cardinals
Detroit Tigers
New York Yankees
New York Yankees
New York Yankees
New York Yankees
Cincinnati Reds
New York Yankees
St. Louis Cardinals
New York Yankees
St. Louis Cardinals
Detroit Tigers
St. Louis Cardinals
New York Yankees
Cleveland Indians
New York Yankees
New York Yankees
New York Yankees
New York Yankees
New York Yankees
New York Giants
Brooklyn Dodgers
New York Yankees
Milwaukee Braves
New York Yankees
Los Angeles Dodgers
Pittsburgh Pirates
New York Yankees
New York Yankees
Los Angeles Dodgers
St. Louis Cardinals
Los Angeles Dodgers
Baltimore Orioles
St. Louis Cardinals
Detroit Tigers
New York Mets
Baltimore Orioles
Pittsburgh Pirates
Oakland Athletics
Oakland Athletics
Oakland Athletics
Cincinnati Reds
Cincinnati Reds
New York Yankees
New York Yankees
Pittsburgh Pirates
Philadelphia Phillies
Los Angeles Dodgers
St. Louis Cardinals
Baltimore Orioles
Detroit Tigers
Kansas City Royals
New York Mets
Minnesota Twins
Los Angeles Dodgers
Oakland Athletics
Cincinnati Reds
Minnesota Twins
Toronto Blue Jays
Toronto Blue Jays
Atlanta Braves
New York Yankees
Florida Marlins
New York Yankees
New York Yankees
New York Yankees
Arizona Diamondbacks
Anaheim Angels
Florida Marlins
Boston Red Sox
Chicago White Sox
St. Louis Cardinals
Boston Red Sox
Philadelphia Phillies
New York Yankees
San Francisco Giants
St. Louis Cardinals
San Francisco Giants
Boston Red Sox
San Francisco Giants
Kansas City Royals
Chicago Cubs
Houston Astros
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started