The Artima Developer Community
Sponsored Link

Python Answers Forum
help making sublists

1 reply on 1 page. Most recent reply: Apr 20, 2005 5:36 AM by Andrew Todd

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Mike Markman

Posts: 1
Nickname: markman023
Registered: Apr, 2005

help making sublists Posted: Apr 3, 2005 6:15 PM
Reply to this message Reply
Advertisement
Write a Python program to do the following.

You wish to store, maintain, update, and use data for each of several baseball players. For each player you will store last name, player number, number of times at bat, and number of hits. Use a nested list to store this data.

Your program will have the following major parts.
1. Create the data structure and populate it with data. For this part, you should read the data from a text file named “players.txt”. You do not know how many total lines of data are in this file, but you DO know that you have 4 lines for each player. Furthermore, you also know that for each player, the data in the file is given in the order: last name, player number, at bats, hits. Finally, all data is of the expected type. (In other words, there are no “tricks” in the data file.)
2. Update the data in your data structure. This would correspond to the appropriate updates at the end of a game. For this part, you should go through your list of players and do the following for each player: print the name and player number to the screen, ask the user to input the number of at-bat appearances that game, ask the user to input the number of hits for that game, and then update the player’s record accordingly.
3. Count and output the number of players who have a batting average of 300 or higher. Note that batting average is not stored directly. You will have to compute it. Do NOT store it in the player’s record.
4. Count and output the number of players in each of the following classifications. 0-50 hits whiffer
51-100 hits OK
101-150 hits productive
over 150 hits MVP candidate

You must design your code so that you make good use of functions. At a very minimum, you should have a function for each of the parts described above. You may, of course, use more functions than this.


The main part I need help with is #1, I know how to read in the file but I can't quite figure out how to put it into sublists.

Thanks for any help,

Markman023


Andrew Todd

Posts: 2
Nickname: aetodd
Registered: Mar, 2005

Re: help making sublists Posted: Apr 20, 2005 5:36 AM
Reply to this message Reply
http://www.python.org/doc/2.4.1/tut/tut.html

list of lists or list of player classes

Flat View: This topic has 1 reply on 1 page
Topic: problem with activating imported methods Previous Topic   Next Topic Topic: help...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use