neeed help!!!

Thread Solved

Join Date: Nov 2009
Posts: 7
Reputation: Ri0o is an unknown quantity at this point 
Solved Threads: 0
Ri0o Ri0o is offline Offline
Newbie Poster

neeed help!!!

 
-1
  #1
25 Days Ago
hi, i'm new in python programming
i'm trying to write a simple program that processes a text file containing grades for a class, extracts the desired grades, count the number of grades in each grade segment and genrate a pie chart for grades,(A1) .
http://pages.cpsc.ucalgary.ca/~zongp...ents/A3/a3.pdf
any help would be appreciated
txt file grades1.txt
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 188
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 47
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Junior Poster
 
0
  #2
25 Days Ago
Originally Posted by Ri0o View Post
hi, i'm new in python programming
i'm trying to write a simple program that processes a text file containing grades for a class, extracts the desired grades, count the number of grades in each grade segment and genrate a pie chart for grades,(A1) .
http://pages.cpsc.ucalgary.ca/~zongp...ents/A3/a3.pdf
any help would be appreciated
txt file Attachment 12416
http://www.daniweb.com/forums/announcement114-2.html
try to make a plan for what the program needs to do and divide each step into separate functions.

Hint: f = open( filename, "r" ) opens a file named 'filename'
l = f.readlines() reads the contents of the file line by line into a list
string.split() split a string by a given delimiter as an argument
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,003
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 927
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #3
25 Days Ago
Simply posting the same question with another meaningless title again is in rather poor taste. People have given you advice, so apply it and go from there. We will not do homework for you, since you are the one that has to learn something!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: Ri0o is an unknown quantity at this point 
Solved Threads: 0
Ri0o Ri0o is offline Offline
Newbie Poster
 
0
  #4
25 Days Ago
here is what i have so far but it doesn't seem to be working need help in figuring out what's wrong
  1. Code:
  2. dbfile = open(grades.txt,'r')
  3. table = []
  4. lines = dbfile.readline()
  5. newtable = []
  6. for line in lines:
  7. line = line[:-1]
  8. r = string.split(line,':')
  9. table.append(r)
  10. for x in table: t=[]
  11. for all in x:
  12. if all.isalpha() == 0:
  13. num = float(all)
  14. else:
  15. num = all
  16. t.append(num)
  17. newtable.append(tuple(t))
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,008
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 285
woooee woooee is offline Offline
Veteran Poster
 
0
  #5
25 Days Ago
You want to use "readlines()",as readline reads one line at a time, where readlines() reads all data. Also, a print statement is added for clarity.
  1. records = open(grades.txt,'r').readlines()
  2. table = []
  3. newtable = []
  4. for line in records:
  5. line = line[:-1]
  6. r = string.split(line,':')
  7. ## table.append(r)
  8. ## for x in table: ## x = r so just use r
  9. ## for all in x:
  10. for all in r:
  11. print "testing isalpha()", all.isalpha(), all
  12. if all.isalpha() == 0:
  13. num = float(all)
  14. else:
  15. num = all
  16.  
  17. ##--- get the first part of the program working first
  18. ## t.append(num)
  19. ## newtable.append(tuple(t))
Last edited by woooee; 25 Days Ago at 12:14 am.
Linux counter #99383
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 141
Reputation: mn_kthompson is an unknown quantity at this point 
Solved Threads: 32
mn_kthompson mn_kthompson is offline Offline
Junior Poster
 
0
  #6
25 Days Ago
Remember, the first thing you want to do is read in the input, so start by working out that problem. Read in the file and strip off the first and last lines:
  1. infile = open('grades1.txt','r')
  2. all_lines = infile.readlines()
  3.  
  4. all_lines = all_lines[1:]
  5. all_lines = all_lines[:-2]

Then you could take your file and make it into a list of tuples so you can generate reports based on any field in the file.
  1. dataset = []
  2. for eachline in all_lines:
  3. dataset.append(eachline.split('\t'))

So that is just one way that you can read in the data. If you decide to go this route, then you can iterate through the list called dataset and pull out the field of the tuples that you're interested in.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: Ri0o is an unknown quantity at this point 
Solved Threads: 0
Ri0o Ri0o is offline Offline
Newbie Poster
 
0
  #7
25 Days Ago
i'm really confused , i tried many ways to read and extract the 6th column from the txt file (A1) but it doesn't work ,
if someone can help me i would really appreciated plz without mocking me i'm a real newbie in this language
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 141
Reputation: mn_kthompson is an unknown quantity at this point 
Solved Threads: 32
mn_kthompson mn_kthompson is offline Offline
Junior Poster
 
0
  #8
25 Days Ago
Use the first code snippet that I put in my last post so that you can strip off the first and last lines of the file.

Now if you want a list that only contains the stuff in the 6th column, you can use this code.
  1. 6th_column = []
  2. for eachline in all_lines:
  3. 6th_column.append(eachline.split('\t')[5])

So what's going on in my code snippet? Well first I'm creating an empty list that I can fill with stuff called 6th_column. Then in the for loop I start adding stuff to my list with the append. I'm splitting each line into a tuple with the split function, and I'm specifying that tabs are what separate each column.

How did I know that it was tabs rather than spaces? Well I read in a line of the file earlier and used the repr() function to see what they were.
print repr(all_lines[0])
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 7
Reputation: Ri0o is an unknown quantity at this point 
Solved Threads: 0
Ri0o Ri0o is offline Offline
Newbie Poster
 
0
  #9
25 Days Ago
thx man for your help, i'm now trying to assign grades for each result in column #6 and count how many repeated grades scored
i was using that code, but it didn't work
  1. A+ =[10]
  2. A = [9,10)
  3. A- =[8,9)
  4. B+ =[7,8)
  5. B =[6,7)
  6. B- =[5,6)
  7. C+ =[4,5)
  8. C =[3,4)
  9. D+ =[2,3)
  10. F =[0,1)
  11.  
  12.  
  13. grades=["ABCDA"]
  14. i=0
  15. total=0
  16. while i<len(grades):
  17. if grades[i] =='A':
  18. total=total+1
  19. i=i+1
  20. print total
if you have any suggestion on how to solve this that would be great
thx again for your help i really apperciated
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC