In: Computer Science
The attached WorldSeriesWinners.txt ( since I cannot share it directly I will send the information for the text file ) file contains the name of the winner of the World Series (duh) and the year in which they won. 1904 and 1994 did not have World Series played, so "No Winner" is displayed for those years. Your job is to write a program that lets the user enter the name of a team (or "No Winner") and then display the number of times the team won and a list of the years in which they won. Some hints/tips:
Boston Americans 1903 No Winner 1904 New York Giants 1905 Chicago White Sox 1906 Chicago Cubs 1907 Chicago Cubs 1908 Pittsburgh Pirates 1909 Philadelphia Athletics 1910 Philadelphia Athletics 1911 Boston Red Sox 1912 Philadelphia Athletics 1913 Boston Braves 1914 Boston Red Sox 1915 Boston Red Sox 1916 Chicago White Sox 1917 Boston Red Sox 1918 Cincinnati Reds 1919 Cleveland Indians 1920 New York Giants 1921 New York Giants 1922 New York Yankees 1923 Washington Senators 1924 Pittsburgh Pirates 1925 St. Louis Cardinals 1926 New York Yankees 1927 New York Yankees 1928 Philadelphia Athletics 1929 Philadelphia Athletics 1930 St. Louis Cardinals 1931 New York Yankees 1932 New York Giants 1933 St. Louis Cardinals 1934 Detroit Tigers 1935 New York Yankees 1936 New York Yankees 1937 New York Yankees 1938 New York Yankees 1939 Cincinnati Reds 1940 New York Yankees 1941 St. Louis Cardinals 1942 New York Yankees 1943 St. Louis Cardinals 1944 Detroit Tigers 1945 St. Louis Cardinals 1946 New York Yankees 1947 Cleveland Indians 1948 New York Yankees 1949 New York Yankees 1950 New York Yankees 1951 New York Yankees 1952 New York Yankees 1953 New York Giants 1954 Brooklyn Dodgers 1955 New York Yankees 1956 Milwaukee Braves 1957 New York Yankees 1958 Los Angeles Dodgers 1959 Pittsburgh Pirates 1960 New York Yankees 1961 New York Yankees 1962 Los Angeles Dodgers 1963 St. Louis Cardinals 1964 Los Angeles Dodgers 1965 Baltimore Orioles 1966 St. Louis Cardinals 1967 Detroit Tigers 1968 New York Mets 1969 Baltimore Orioles 1970 Pittsburgh Pirates 1971 Oakland Athletics 1972 Oakland Athletics 1973 Oakland Athletics 1974 Cincinnati Reds 1975 Cincinnati Reds 1976 New York Yankees 1977 New York Yankees 1978 Pittsburgh Pirates 1979 Philadelphia Phillies 1980 Los Angeles Dodgers 1981 St. Louis Cardinals 1982 Baltimore Orioles 1983 Detroit Tigers 1984 Kansas City Royals 1985 New York Mets 1986 Minnesota Twins 1987 Los Angeles Dodgers 1988 Oakland Athletics 1989 Cincinnati Reds 1990 Minnesota Twins 1991 Toronto Blue Jays 1992 Toronto Blue Jays 1993 No Winner 1994 Atlanta Braves 1995 New York Yankees 1996 Florida Marlins 1997 New York Yankees 1998 New York Yankees 1999 New York Yankees 2000 Arizona Diamondbacks 2001 Anaheim Angels 2002 Florida Marlins 2003 Boston Red Sox 2004 Chicago White Sox 2005 St. Louis Cardinals 2006 Boston Red Sox 2007 Philadelphia Phillies 2008 New York Yankees 2009 San Francisco Giants 2010 St. Louis Cardinals 2011 San Francisco Giants 2012 Boston Red Sox 2013 San Francisco Giants 2014 Kansas City Royals 2015 Chicago Cubs 2016
def main():
data={}
teamLine=True
filename='WorldSeriesWinners.txt'
try:
with open(filename) as f:
for line in f:
token = line.strip()
if teamLine:
teamLine=False
if token.lower() not in data:
data[token.lower()]=[]
team=token.lower()
else:
teamLine=True
data[team].append(int(token))
again="y"
while again.lower()!="n":
team = input("Enter a team name: ")
if team.lower() in data:
print("{} won the World Series {}
times.".format(team,len(data[team.lower()])))
print('Years won:',data[team.lower()])
again=input("Do you want to enter again (y/n)?: ")
except FileNotFoundError:
print('File {} not found!!'.format(filename))