Question

Do it in python please Boston Americans 1903 No Winner 1904 New York Giants 1905 Chicago...

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:

  1. Exercise 10 on page 290

You are to:

  1. Work through this Lab on your own (no peer help on this one!)
  2. Submit your own completed Lab file(s) here (click the link above)
  3. Do NOT alter the text file or change the name of the file.

This activity is worth 10 total points

This week's Lab is:

  • The attached WorldSeriesWinners.txt 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:
    • You should use at least one try/catch error validation
    • You can use the string function lower() to convert a string into lowercase letters which might make it easier as a user interface.
    • You should use a while loop that allows the user to enter another team name after results are displayed

You are to:

  1. Work through this Lab on your own (no peer help on this one!)
  2. Submit your own completed Lab file(s) here (click the link above)

Homework Answers

Answer #1

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!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python A text file (WorldSeriesWinners.txt ) contains a chronological list of the World Series winning teams...
Python A text file (WorldSeriesWinners.txt ) contains a chronological list of the World Series winning teams from 1903 through 2009. The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note the World Series was not played in 1904 and 1994. Write a program to open the file WorldSeriesWinners.txt, read it line by line and store the team names in...
Here is the data Stat7_prob2.txt : "Team","WINS","HR","BA","ERA" "Anaheim Angels",99,152,.282,3.69 "Baltimore Orioles",67,165,.246,4.46 "Boston Red Sox",93,177,.277,3.75 "Chicago White...
Here is the data Stat7_prob2.txt : "Team","WINS","HR","BA","ERA" "Anaheim Angels",99,152,.282,3.69 "Baltimore Orioles",67,165,.246,4.46 "Boston Red Sox",93,177,.277,3.75 "Chicago White Sox",81,217,.268,4.53 "Cleveland Indians",74,192,.249,4.91 "Detroit Tigers",55,124,.248,4.93 "Kansas City Royals",62,140,.256,5.21 "Minnesota Twins",94,167,.272,4.12 "New York Yankees",103,223,.275,3.87 "Oakland Athletics",103,205,.261,3.68 "Seattle Mariners",93,152,.275,4.07 "Tampa Bay Devil Rays",55,133,.253,5.29 "Texas Rangers",72,230,.269,5.15 "Toronto Blue Jays",78,187,.261,4.8 "Arizona Diamondbacks",98,165,.267,3.92 "Atlanta Braves",101,164,.26,3.13 "Chicago Cubs",67,200,.246,4.29 "Cincinnati Reds",78,169,.253,4.27 "Colorado Rockies",73,152,.274,5.2 "Florida Marlins",79,146,.261,4.36 "Houston Astros",84,167,.262,4 "Los Angeles Dodgers",92,155,.264,3.69 "Milwaukee Brewers",56,139,.253,4.73 "Montreal Expos",83,162,.261,3.97 "New York Mets",75,160,.256,3.89 "Philadelphia Phillies",80,165,.259,4.17 "Pittsburgh Pirates",72,142,.244,4.23 "St. Louis Cardinales",97,175,.268,3.7 "San Diego Padres",66,136,.253,4.62 "San Francisco Giants",95,198,.267,3.54 Here...
team   league    price    wins    cost/win Arizona Diamondbacks   NL   19.68   90   35.40 Atlanta Braves  ...
team   league    price    wins    cost/win Arizona Diamondbacks   NL   19.68   90   35.40 Atlanta Braves   NL   17.07   84   32.89 Chicago Cubs   NL   34.30   85   65.33 Cincinnati Reds   NL   17.90   72   40.32 Colorado Rockies   NL   14.72   90   26.67 Florida Marlins   NL   16.70   71   38.13 Houston Astros   NL   26.66   73   59.11 Los Angeles Dodgers   NL   20.09   82   34.64 Milwaukee Brewers   NL   18.11   83   35.37 N.Y. Mets   NL   25.28   88   46.56 Philadelphia Phillies     NL   26.73   89   48.69 Pittsburgh Pirates   NL   17.08  ...
Do highly performing athletic teams have a larger fan base and generate greater attendance at games...
Do highly performing athletic teams have a larger fan base and generate greater attendance at games or matches? Use the data (in the data document) for the number of wins and attendance in 2006 for the 14 American League baseball teams to answer the follow questions: a) Examine a scatterplot for the 2 variables and test the conditions for regression. b) Do you think there is a linear association between Home Attendance and Wins? Team Wins Runs Home Attendance Minnesota...
. If a sports team is maximizing their wins, is that the same as maximizing their...
. If a sports team is maximizing their wins, is that the same as maximizing their profits? Explain at least three ways that teams seek to maximize their profits. b. Using at least 2 teams from the following list, explain how teams can become wealthy even if they do not win all the time Rank, Team, Value, 1-Year change (Sport) 1. Dallas Cowboys, $4.8 billion, 14% (NFL) 2. Manchester United, $4.123 billion, 12% (Soccer) 3. Real Madrid, $4.09 billion, 14%...
11v On December 17, 2007 baseball writer John Hickey wrote an article for the Seattle P-I...
11v On December 17, 2007 baseball writer John Hickey wrote an article for the Seattle P-I about increases to ticket prices for Seattle Mariners games during the 2008 season. The article included a data set that listed the average ticket price for each MLB team, the league in which the team plays (AL or NL), the number of wins during the 2007 season and the cost per win (in dollars). The data for the 16 National League teams are shown...
Notes: Please type your work, or 10% credits will be deducted Show your work for full...
Notes: Please type your work, or 10% credits will be deducted Show your work for full credits Follow the six steps for hypothesis testing If Excel is used, please copy and paste Excel Output as part of your answer How does cellphone service compare between different cities? The data stored in CellServicee represent the rating of Verizon and AT&T in 22 different cities. (Data extracted from “Best Phones and Service,” Consumer Reports, January 2012, p. 28, 37.) At the 0.05...
For each of the following two-samples t-tests (problems 1-6): (a) Determine if a F test for...
For each of the following two-samples t-tests (problems 1-6): (a) Determine if a F test for the ratio of two variances is appropriate to calculate for the context. If it is appropriate, conduct the analysis and report the result. Include what statistical conclusion you should draw from the analysis (i.e., whether you should conduct a pooled-variance t-test or an unequal-variances t-test). (b) Identify the most appropriate t-test to conduct for the situation/data given. Don’t forget to consider if the context...
Suppose you are a rabid football fan and you get into a discussion about the importance...
Suppose you are a rabid football fan and you get into a discussion about the importance of offense (yards made) versus defense (yards allowed) in terms of winning a game. You decide to look at football statistics to provide evidence of which variable is a stronger predictor of wins. Can use the minitab. Part a) Develop a simple linear regression that compares wins to yards made (please show me the scatter plot) . Perform the following diagnostics on this regression:...
StatCrunch Project #1 Open “Cities”. Provide the following using Statcrunch: (in a pdf document) mean PM10...
StatCrunch Project #1 Open “Cities”. Provide the following using Statcrunch: (in a pdf document) mean PM10 median PM10 min PM10 max PM10 Q1 of PM10 Q3 of PM10 Standard deviation of PM10 Variance of PM10 PM10 stem & leaf plot PM10 histogram PM10 box plot PM10 normal quantile plot (QQ plot) Comparison box plots for REGION vs PM10 Scatterplot for Y vs MAX DEG F JAN What is the coefficient of linear correlation? Q3 Q1 city X Y State Region...