Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 3rd, 2005, 8:24 PM   #1
frdtylr
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 frdtylr is on a distinguished road
help with a program

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 minor
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.

I am having trouble with #1 and making a list into sublists. Any help would be awesome.

Thanks, Mike
frdtylr is offline   Reply With Quote
Old Apr 3rd, 2005, 8:39 PM   #2
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
Let's see some work first.
thechristelegacy is offline   Reply With Quote
Old Apr 3rd, 2005, 8:45 PM   #3
al1986
Newbie
 
Join Date: Feb 2005
Posts: 24
Rep Power: 0 al1986 is on a distinguished road
I'm not doing your homework for you am I? A few hints...

[ [], [], [], [] ]

The above code creates a nested list, call it 'l'. Imagine the list indexed by l[0] is used to store player surnames. To add a name to this sublist, do l[0].append(foo).

To me, though, it'd make more sense to create a dictionary for each player with 4 keys (last name, player no., no. of times at bat, no. of hits).

Btw, this stuff really isn't complicated. You should be able to work it out for yourself from an online tutorial. Or just buy a book.

Last edited by al1986; Apr 3rd, 2005 at 8:50 PM.
al1986 is offline   Reply With Quote
Old Apr 4th, 2005, 11:01 AM   #4
frdtylr
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 frdtylr is on a distinguished road
Ok, well here's some work. As you can see I can get all the things into sublists, but not with four objects in each sublist.

def dataList():
import string
list = []
InFile = open("players.txt" , "r")
for line in InFile:
words = string.split(line)
list.append(words)
print list

results in this...

>>>
[['A'], ['7'], ['100'], ['33'], [], ['B'], ['5'], ['150'], ['50'], [], ['C'], ['2'], ['200'], ['66'], [], ['D'], ['3'], ['500'], ['145']]
>>>
frdtylr is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC