i am completely stumped at how to create this program. can anyone help out? here are the guidelines.


Perhaps in no other sport does statistics play as major a role as in the game of Baseball. In fact, certain numbers, such as 56 (length of Joe DiMaggio's hitting streak), 73 (Barry Bonds' single season home run record) and 755 (Hank Aaron's career home run record) are part of American sports culture.

You will write a Python program that reads in Baseball statistics for players on various teams from a CSV (comma separated value) file and display statistical information for a specified player. You will allow the user to find a player and display his statistics.
The interface

The interface will be via the terminal (stdin, stdout). The user interface will have 3 stages:

1. List, in alphabetical order, all teams represented within the file.
2. Allow the user to choose (menu style) a team, and then display all players for that team
3. Allow the user to choose (menu style) a player and then display the full set of statistics for that player

You will, after some input (you decide), bring the user back to the main (team list) menu, which will also have a "quit" option.

When you list out the teams or players, enumerate them, so that the user can choose by entering a number; don't make the user type out text (team or player names), etc.

Player statistics input are provided in sample.in

The following fields are included for each record, as follows:

1. player's last name
2. player's first name
3. player's team
4. player's position
5. number of at bats
6. number of base hits
7. number of doubles
8. number of triples
9. number of home runs
10. number of runs batted in (RBI)
11. batting average (3 decimal places, no leading zero

Note that all fields within a record are separated by commas, and that no field actually contains a comma.

Please review some of the Python examples from week 4 which demonstrate how to retrieve files (either entire file or line by line) into Python. Also, these examples demonstrate how to parse the line items into individual fields.
Notes, the data structures

You will want to keep the keys (for both team and player lists) in a sorted list for displaying a menu (easy access). For storing statistical details, associating them with a player, associating players with teams, please think about how you would store this. Nice tables will drive a lot of the rest of your code.

You will probably choose to utilize some combination of Python's list and dictionary types (list of dictionaries, dictionaries of lists, ....)

You may parse the input file only once, so you need to store the information for easy retrieval.


Here is the contents of the .csv file



if anyone could help me out that would be appreciated, thank you.

8 Years
Discussion Span
Last Post by jrcagle

You'd want to start by getting the info from the file.

allplayerinfo = []
info = open("filename.cvs")
data = info.read()

for lines in data:

Then you should sort the info for every player. Use .split(",") on each individual string line. Organize them all into var lists. Or sort them and .join(" - ") or w/e your teacher wants.


Well, I would recommend checking out the csv module

import csv

in the Python docs. It can do what Shadow is recommending pretty much automatically.

I would also recommend getting your menu working first, just as a stub. The options don't have to do anything, but if you have the working menu framework going, then you can add functionality and test it as you go.


This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.