Problem Description
Files, Lists: World Series Winners, version 2Skills needed: read files, manipulate lists, manipulate stringsProgram name: world_series2.pyProblem DescriptionWrite a Python program to read a file of World Series winners and then respond to queries about the data.Getting the dataThe file is an ordinary text file, worldseries.txt, and has one team name per line. Line 1 corresponds to the 1903 World Series and subsequent lines refer to subsequent years. Note that there is still a line for those years in which there was no World Series (1904 and 1994). Read the entire file into a list. The input may be any combination of upper and lower case letters. Put the file in the same folder as your ".py" file and you won't have to provide any path information to locate the file. Remember to remove the newline character from the end of the string (rstrip() method).Keep track of startYear (1903—store it in a variable so that the number doesn't appear more than once in your program) and endYear (the year corresponding to the last line of the input file). If you know how many lines are in the file, then you can easily compute the endYear. Then your program will work regardless of how many lines are in the data file. If you build the number 2019 into your program, it won't work next year. But if you count the lines, it will always work without modification.Responding to queriesAsk the user for the name of a team (e.g. New York Yankees). Note that the name typed by the user must be exactly the same as the name in the file, but the case of the letters does NOT have to match. For example, if the user enters "new york yankees", "NEW YORK yankees", etc., you should still find the answer. You do not have to worry about the case where there may be extra spaces between words. But you should trim any characters from the beginning and end of the input string. After reading the name from the user, respond with a list of the years that the team won the World Series.Sample sessionBelow is a brief interactive session from my program. User input is in bold. On the last line, I just hit the Enter key to enter an empty string and end the program. Enter a team: new YORK yankeesNew York Yankees won the World Series in the following years [1923, 1927, 1928, 1932, 1936, 1937, 1938, 1939, 1941, 1943, 1947, 1949, 1950, 1951, 1952, 1953, 1956, 1958, 1961, 1962, 1977, 1978, 1996, 1998, 1999, 2000, 2009].Enter a team: minnesota TWINS Minnesota Twins won the World Series in the following years [1987, 1991].Enter a team: bcu chargersBCU CHARGERS never won a World Series.Enter a team: End of program. ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
Related searches
- different approaches to problem solving
- 3rd grade word problem worksheets
- research problem examples
- math word problem worksheets pdf
- word problem practice worksheets
- online shopping problem and solution
- identifying a research problem examples
- research problem example pdf
- identifying problem statements in research
- significance of the problem example
- examples of good problem statements
- research problem statement examples pdf