Do it in python please 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
This week's Lab is:
You are to:
This activity is worth 10 total points
This week's Lab is:
You are to:
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Note:- WorldSeriesWinners.txt is placed where the python file is exists.
Images of the Code:
Note: If the below code is missing indentation please refer code Images
Typed Code:
#try block is used to test block of codes for errors
file = "WorldSeriesWinners.txt"
try:
#opening file and reading the file
f = open(file).read()
#spliting the file with new line and store it in a list
series = f.split('\n')
#while loop will iterate infinite times
while True:
#getting team name from the user
team = input("Enter the name of the team: ")
#count is used to store number of wins
count = 0
#years is used to store won years
years = []
#if team name is empty
if len(team) < 1 :
#break the loop
break
#for loop will iterate len(series) times
for i in range(len(series)):
#if team name is equal to series[i]
#lower() is used to change string to lowercase
#strip is used to remove extra spaces at the beginning and end of
string
if team.lower().strip() == series[i].lower().strip():
#count increases
count += 1
#appending the winning year to years[]
years.append(series[i+1])
#team stores the name of the winning team
team = series[i].strip()
#printing team, count, years
print('{} won the series {} times in the
years'.format(team,count),years)
print("\n")
print('If you want to stop, use enter button without entering team
name')
#except block handles thae errors
except:
#printing there is no such file or directory
print('No such file or directory found : {}'.format(file))
#code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!
Get Answers For Free
Most questions answered within 1 hours.