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/~zongpeng/CPSC231/assignments/A3/a3.pdf
any help would be appreciated
txt file
grades1.txt

Attachments
ID	Last	First	Lecture	Tutor	A1	A2	A3	A4	A5
6882621	Lee	Lisa	LO1	TO7	2.0	7.0	1.0	10.0	8.5
5727139	Lee	John	LO1	TO8	3.5	3.5	8.5	0.0	2.0
4592442	Jones	Linda	LO0	TO7	8.0	7.5	3.5	1.5	2.0
4194804	Bing	Robert	LO1	TO0	1.5	8.0	3.5	9.5	8.0
3841058	Johnson	Paul	LO1	TO6	9.0	2.0	8.0	9.5	2.0
3378161	Freeman	John	LO1	TO3	2.0	6.0	8.5	8.5	9.5
5140629	Thomas	Helen	LO0	TO4	0.0	2.0	9.0	10.0	2.0
9347090	Miller	Maria	LO1	TO1	9.5	9.5	6.5	8.0	9.0
1916293	Jones	Robert	LO1	TO4	8.5	0.5	10.0	2.0	3.5
6353341	Miller	Lisa	LO0	TO2	2.0	2.5	3.0	9.0	7.5
7594201	Johnson	Linda	LO0	TO6	7.0	6.0	6.0	2.0	9.5
9529592	Freeman	John	LO0	TO3	3.0	9.5	8.5	10.0	9.0
7123952	Moore	Maria	LO0	TO4	6.5	6.0	5.5	9.0	3.5
5784699	Thomas	Maria	LO1	TO3	1.5	8.0	9.0	1.0	8.0
7009346	Davis	Helen	LO1	TO9	1.5	2.0	9.0	1.0	2.0
2235041	Bing	James	LO1	TO4	6.5	9.0	8.5	9.5	2.5
9295242	Freeman	Paul	LO1	TO5	6.5	9.5	1.0	4.0	10.0
7501126	Miller	Maria	LO0	TO0	8.5	3.0	10.0	8.5	8.0
3971527	Davis	Maria	LO0	TO9	9.0	1.5	2.5	3.5	1.5
0084475	Miller	John	LO1	TO7	8.5	1.5	9.0	2.5	1.0
2167228	Freeman	James	LO1	TO5	4.5	8.5	9.5	8.5	10.0
3031060	Freeman	Robert	LO0	TO9	6.5	9.0	10.0	9.0	3.0
5598222	Bing	Lisa	LO0	TO9	6.5	2.5	8.0	6.0	0.5
7543280	Lee	Mary	LO1	TO8	9.5	9.0	8.5	9.5	1.0
6483388	Thomas	Linda	LO1	TO3	5.5	6.0	1.5	3.0	1.0
3751752	Miller	Maria	LO1	TO8	9.5	1.5	2.5	9.5	9.0
4395813	Freeman	James	LO1	TO9	3.5	10.0	5.0	6.5	2.5
0410097	Davis	John	LO0	TO2	3.5	8.0	0.5	9.0	2.0
3719104	Davis	Mary	LO0	TO0	1.0	1.5	4.5	3.5	10.0
9959266	Freeman	Helen	LO0	TO0	8.0	9.0	1.5	7.5	1.5
6861532	Jones	Maria	LO0	TO2	1.0	3.5	4.5	4.0	2.5
8304781	Johnson	Helen	LO0	TO6	10.0	9.0	8.0	10.0	7.5
5337432	Taylor	James	LO1	TO7	1.5	9.0	9.5	2.5	3.5
2602852	Davis	Lisa	LO0	TO3	1.0	7.5	5.5	1.5	2.0
4293362	Miller	Robert	LO1	TO7	9.5	4.5	8.5	8.0	8.5
0158170	Lee	John	LO1	TO1	1.5	3.5	2.5	1.0	9.0
6576801	Jones	David	LO1	TO6	9.5	4.0	9.5	9.0	10.0
5761759	Lee	Robert	LO0	TO6	2.5	2.0	9.0	8.0	2.0
9009383	Johnson	Paul	LO0	TO9	2.0	8.0	2.5	9.5	10.0
9519864	Taylor	John	LO0	TO4	7.5	2.5	8.5	2.5	10.0
1824451	Taylor	James	LO0	TO6	9.5	4.5	9.0	8.5	9.0
0423903	Taylor	Lisa	LO0	TO3	3.0	3.0	3.5	1.5	0.0
9300493	Jones	Mary	LO1	TO6	10.0	9.0	9.5	9.0	9.5
6429383	Jones	Mary	LO1	TO3	10.0	8.5	9.0	2.5	9.0
6389950	Lee	Robert	LO1	TO2	8.5	5.0	1.0	7.0	2.0
8625509	Thomas	Mary	LO0	TO3	2.0	7.0	8.0	3.0	9.0
3953468	Freeman	David	LO0	TO9	8.0	8.5	1.0	2.5	2.5
7743437	Bing	Linda	LO0	TO3	0.0	7.0	8.5	9.5	8.5
4306782	Jones	Linda	LO0	TO5	2.0	9.5	3.5	7.5	9.5
6299607	Miller	James	LO0	TO8	8.5	5.0	7.5	9.5	2.0
8295182	Davis	Linda	LO0	TO9	9.5	9.5	2.5	8.0	8.0
4849291	Freeman	Helen	LO0	TO5	8.5	2.0	9.5	3.0	8.5
7658018	Thomas	Paul	LO1	TO2	9.0	8.0	8.5	2.5	9.0
3028404	Jones	Paul	LO0	TO4	8.5	10.0	6.0	2.0	9.0
1063070	Miller	John	LO0	TO0	10.0	3.0	4.0	8.0	3.0
0899667	Jones	Mary	LO1	TO6	2.0	2.0	9.0	10.0	8.0
8459165	Moore	John	LO1	TO4	2.5	2.5	8.5	1.0	9.5
7503479	Jones	Mary	LO1	TO3	5.5	8.0	8.5	8.5	10.0
2806139	Miller	Paul	LO1	TO6	9.5	3.5	9.5	9.5	9.0
5357396	Miller	David	LO1	TO2	9.5	0.5	8.5	3.0	8.0
2400621	Miller	James	LO0	TO4	2.0	10.0	3.0	9.5	1.5
7199745	Taylor	Maria	LO1	TO4	2.0	10.0	6.5	8.0	3.5
7375539	Freeman	Mary	LO0	TO8	10.0	8.0	7.0	3.0	8.0
7300880	Jones	Robert	LO0	TO8	2.0	2.0	1.0	9.5	6.0
1332697	Freeman	David	LO1	TO4	8.0	7.0	1.0	8.5	2.0
3284906	Thomas	Maria	LO1	TO4	2.5	1.5	3.5	9.0	9.5
5411217	Jones	Lisa	LO0	TO4	10.0	2.5	10.0	9.0	3.5
0896946	Moore	Lisa	LO1	TO2	2.5	8.0	7.5	1.5	10.0
7207189	Lee	Mary	LO1	TO1	8.5	1.0	10.0	10.0	0.0
1243134	Davis	John	LO1	TO6	1.5	10.0	2.0	2.0	10.0
4463744	Taylor	Paul	LO0	TO8	0.0	1.5	9.5	0.0	8.0
4662506	Miller	Helen	LO1	TO6	7.0	10.0	1.5	9.5	8.0
3983380	Davis	James	LO1	TO9	3.5	8.0	8.0	5.0	8.5
3123601	Freeman	Robert	LO1	TO2	8.5	8.5	9.0	8.5	1.5
2965912	Bing	Linda	LO0	TO7	2.0	9.0	8.0	9.0	8.0
7195536	Lee	Paul	LO1	TO2	1.0	1.0	8.5	2.5	8.0
1886035	Davis	Paul	LO1	TO1	8.0	8.0	1.5	6.5	10.0
3932253	Thomas	Mary	LO1	TO5	9.0	9.0	4.5	3.5	6.0
5847220	Bing	Paul	LO1	TO9	8.5	3.0	8.0	2.5	10.0
4532923	Jones	Robert	LO0	TO5	2.5	1.5	10.0	9.0	9.5
1881752	Johnson	Helen	LO1	TO3	2.5	3.5	8.5	2.5	2.0
0834763	Davis	John	LO0	TO5	9.0	3.5	9.0	8.0	8.5
4786795	Miller	Maria	LO0	TO3	8.0	8.0	8.0	8.0	4.5
7685892	Thomas	Lisa	LO1	TO6	3.5	1.5	2.5	7.5	9.0
2798090	Jones	John	LO0	TO3	8.5	2.0	6.5	2.0	10.0
9609974	Jones	Linda	LO1	TO9	6.5	7.0	9.0	3.5	8.5
2357750	Thomas	Linda	LO0	TO8	2.5	8.5	1.0	1.0	3.0
1813468	Lee	John	LO1	TO3	10.0	1.5	5.5	8.5	10.0
3863617	Moore	Mary	LO0	TO4	2.0	9.5	2.0	10.0	6.5
7366878	Bing	David	LO0	TO1	1.5	2.5	10.0	3.5	2.0
8991569	Bing	Linda	LO1	TO9	1.0	3.0	7.5	8.0	8.5
9882308	Thomas	Helen	LO1	TO9	9.5	2.0	8.5	10.0	3.5
5973710	Bing	Robert	LO0	TO8	2.0	9.0	9.0	0.0	2.0
0097002	Thomas	David	LO0	TO7	8.0	9.0	8.0	2.0	9.5
3275773	Johnson	Mary	LO0	TO3	10.0	8.5	3.0	9.5	8.5
3183649	Freeman	Mary	LO0	TO5	1.0	10.0	3.5	9.5	3.0
5055095	Freeman	Maria	LO1	TO8	2.5	1.0	8.5	8.5	9.0
0785510	Bing	Robert	LO1	TO8	9.5	1.5	1.5	2.5	3.5
9497502	Taylor	Mary	LO1	TO6	9.0	9.5	8.5	1.5	8.0
7167053	Johnson	James	LO0	TO3	9.0	10.0	9.5	1.0	3.5
0724716	Taylor	Helen	LO1	TO6	9.5	9.0	2.5	2.0	10.0
5745865	Freeman	Helen	LO0	TO2	6.0	9.0	2.5	10.0	6.5
5865892	Johnson	Robert	LO0	TO0	9.0	9.0	8.0	0.0	2.0
8097087	Taylor	Helen	LO1	TO3	2.0	1.5	9.0	9.0	3.5
8707595	Miller	Helen	LO0	TO8	1.5	8.5	9.5	3.0	2.5
3099178	Jones	Maria	LO1	TO2	3.0	10.0	2.0	2.5	2.5
6944872	Taylor	David	LO1	TO0	1.0	7.5	9.0	8.5	9.5
1359192	Davis	Linda	LO0	TO0	3.5	10.0	6.0	9.5	6.0
0303445	Taylor	Robert	LO0	TO4	8.5	8.5	3.5	3.0	8.0
9484561	Davis	Lisa	LO1	TO4	8.0	4.0	1.0	9.5	9.0
7084062	Davis	Mary	LO0	TO1	9.5	9.5	3.5	6.5	7.5
1571681	Miller	Maria	LO0	TO1	1.5	8.0	10.0	8.0	10.0
5036203	Davis	Helen	LO1	TO8	10.0	9.5	3.0	1.0	6.0
3882721	Thomas	Paul	LO0	TO4	9.0	1.5	1.0	3.0	8.0
0891727	Johnson	Helen	LO0	TO9	2.5	10.0	9.5	2.5	4.5
4769088	Miller	John	LO1	TO5	3.5	2.0	3.0	8.0	3.0
4628171	Davis	Mary	LO1	TO6	3.5	10.0	2.5	6.5	1.0
6522044	Lee	Lisa	LO0	TO5	10.0	9.0	1.5	9.5	3.0
8513443	Johnson	James	LO1	TO9	1.0	7.0	1.5	9.0	1.0
2191126	Freeman	Robert	LO0	TO5	2.5	8.0	3.0	7.5	0.5
0122422	Thomas	Paul	LO1	TO9	8.5	10.0	2.0	9.0	2.5
4535365	Moore	Robert	LO0	TO4	8.0	9.0	1.0	8.5	1.0
9478146	Moore	Robert	LO0	TO5	9.0	10.0	2.5	3.5	2.5
7430187	Taylor	Mary	LO0	TO9	3.5	2.5	8.5	2.0	8.5
0420782	Jones	Paul	LO1	TO5	5.0	2.5	9.5	1.0	1.5
9216671	Bing	Robert	LO0	TO3	9.0	9.5	2.5	3.0	10.0
5680965	Freeman	Lisa	LO1	TO2	1.0	2.0	1.0	4.0	1.5
1561226	Jones	Helen	LO0	TO3	10.0	8.5	10.0	10.0	7.0
5800880	Taylor	John	LO0	TO2	2.0	9.5	8.0	8.5	2.0
4745064	Lee	Robert	LO0	TO8	1.0	9.0	7.5	9.5	9.5
0124905	Thomas	Robert	LO0	TO5	0.0	6.0	7.5	3.0	8.5
9412148	Moore	Helen	LO1	TO3	2.5	10.0	10.0	4.5	8.0
1651802	Lee	James	LO1	TO9	3.0	9.0	7.0	8.0	0.0
2966435	Taylor	John	LO1	TO4	3.5	2.0	8.0	2.0	1.0
6418425	Jones	Paul	LO0	TO3	10.0	3.0	9.0	8.0	3.0
3938727	Johnson	John	LO1	TO9	9.0	6.0	4.0	8.5	9.5
4174757	Thomas	John	LO1	TO9	2.0	8.0	2.5	10.0	10.0
7311720	Davis	John	LO1	TO4	8.5	9.0	1.0	2.5	9.0
8208044	Miller	James	LO1	TO3	2.0	3.0	9.0	3.5	2.0
5523808	Miller	Maria	LO0	TO1	3.5	9.0	8.0	9.5	5.0
9568715	Davis	David	LO0	TO5	8.0	1.5	2.0	9.0	1.0
7210843	Bing	David	LO1	TO1	9.0	3.0	8.5	9.0	1.5
0982498	Freeman	Robert	LO0	TO9	3.5	2.5	2.5	1.5	8.0
7993288	Moore	David	LO0	TO0	9.5	10.0	1.5	1.0	1.5
8400573	Johnson	Lisa	LO0	TO1	2.0	1.5	9.5	9.5	6.0
2750734	Jones	James	LO0	TO7	2.5	1.0	10.0	6.5	8.0
2226816	Lee	Lisa	LO1	TO5	6.0	5.5	3.0	2.0	9.5
5908017	Bing	Paul	LO1	TO1	9.5	1.5	9.5	3.0	1.0
5701656	Davis	David	LO1	TO8	9.0	2.5	1.5	8.5	9.5
2899468	Davis	James	LO1	TO4	4.0	2.5	7.5	2.5	9.5
2445411	Davis	Linda	LO1	TO5	8.5	10.0	3.5	2.5	7.5
7156143	Thomas	David	LO0	TO1	5.0	3.5	9.5	10.0	8.5
0278356	Thomas	Mary	LO1	TO1	0.0	3.5	10.0	8.0	10.0
3305129	Taylor	Paul	LO1	TO6	9.0	6.0	9.0	6.0	8.0
2241172	Johnson	John	LO1	TO7	2.0	3.0	8.0	8.0	9.0
7518221	Thomas	Mary	LO1	TO4	9.5	8.0	8.0	7.5	3.0
6937962	Freeman	John	LO0	TO9	8.0	3.5	1.0	1.5	3.5
3138608	Lee	John	LO0	TO1	3.0	10.0	9.0	1.0	9.5
0622474	Jones	Maria	LO1	TO7	2.0	8.0	5.5	8.0	9.5
3162261	Taylor	Linda	LO0	TO1	9.0	1.0	8.5	9.0	1.0
6317075	Miller	David	LO1	TO3	8.5	7.5	2.5	9.5	9.0
4594585	Miller	Lisa	LO1	TO3	9.5	9.0	3.0	9.0	2.5
8677663	Miller	Paul	LO1	TO0	9.5	4.0	3.5	9.0	10.0
2118002	Thomas	Lisa	LO1	TO9	0.5	9.5	9.0	2.0	9.5
6255739	Johnson	David	LO1	TO2	9.5	3.0	2.5	2.5	3.5
2894340	Thomas	Paul	LO0	TO0	8.5	9.0	7.0	9.0	2.5
9491631	Miller	Paul	LO1	TO9	8.5	2.5	7.5	9.0	9.5
0070081	Lee	Paul	LO1	TO1	2.5	10.0	1.0	9.5	3.5
3982776	Taylor	Helen	LO1	TO8	1.5	1.0	1.5	1.0	9.0
6210665	Freeman	John	LO0	TO8	10.0	1.0	2.5	7.0	8.0
8157366	Moore	Paul	LO0	TO1	9.5	10.0	8.5	10.0	9.5
3723339	Taylor	Linda	LO1	TO1	2.0	9.5	3.5	8.5	8.5
6526727	Thomas	Lisa	LO1	TO4	10.0	10.0	8.0	8.5	8.0
6478890	Lee	Linda	LO0	TO2	2.5	7.0	2.0	2.0	2.5
9642989	Johnson	Helen	LO0	TO7	9.0	0.0	1.0	9.5	10.0
9369429	Jones	James	LO0	TO8	1.5	10.0	1.0	9.0	9.5
4280640	Moore	Helen	LO0	TO4	3.0	9.0	9.5	9.0	9.0
0057063	Jones	Mary	LO1	TO9	8.0	7.5	3.0	1.5	9.0
0279761	Lee	Helen	LO1	TO7	1.0	7.0	1.0	9.5	3.0
1940836	Davis	Lisa	LO0	TO9	1.5	3.5	4.5	8.0	2.5
6359035	Miller	James	LO0	TO2	10.0	3.0	9.5	3.0	8.5
6178303	Freeman	Mary	LO0	TO4	9.5	9.5	3.0	8.0	1.5
4531622	Lee	Helen	LO0	TO0	8.5	2.0	10.0	9.5	6.0
3152656	Jones	Robert	LO1	TO4	1.5	8.0	7.0	2.5	1.5
1942257	Davis	Mary	LO0	TO9	9.5	8.5	3.5	9.5	3.5
4910827	Lee	John	LO0	TO6	8.0	7.0	3.5	2.0	2.0
7998296	Jones	Linda	LO1	TO1	2.0	9.0	9.0	10.0	9.0
1876861	Bing	Lisa	LO1	TO8	2.0	9.0	7.0	3.0	1.5
2968691	Thomas	David	LO0	TO7	8.0	8.5	4.5	3.5	8.5
2281437	Jones	Mary	LO0	TO0	9.0	2.5	4.5	4.5	9.5
5367989	Lee	James	LO0	TO1	3.5	3.5	8.0	9.0	6.5
2702361	Miller	John	LO0	TO4	10.0	1.5	5.5	1.0	1.0
9204661	Freeman	Paul	LO0	TO6	2.0	3.5	2.5	9.5	9.0
9175403	Jones	David	LO0	TO8	8.0	3.0	4.5	2.0	1.0
0380188	Davis	John	LO0	TO5	10.0	9.5	9.5	1.0	8.5
4646732	Thomas	Maria	LO1	TO3	9.0	4.0	7.0	2.5	2.0
3102045	Thomas	Linda	LO0	TO7	3.0	8.5	2.5	9.0	9.5
7037617	Thomas	Paul	LO1	TO1	2.5	2.0	2.0	7.0	5.0
2209727	Jones	David	LO0	TO3	2.0	3.5	10.0	8.0	5.5
4193846	Freeman	Linda	LO0	TO8	9.5	3.5	9.0	9.0	8.5
EOF

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/~zongpeng/CPSC231/assignments/A3/a3.pdf
any help would be appreciated
txt file [ATTACH]12416[/ATTACH]

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

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!

here is what i have so far but it doesn't seem to be working need help in figuring out what's wrong

Code:
dbfile = open(grades.txt,'r')
  table = []
  lines = dbfile.readline()
  newtable = []
  for line in lines:  
   line = line[:-1]
   r = string.split(line,':')
   table.append(r)
  for x in table:       t=[]
   for all in x:
    if all.isalpha() == 0:
     num = float(all)
    else:
     num = all
   t.append(num)
   newtable.append(tuple(t))

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.

records = open(grades.txt,'r').readlines()
table = []
newtable = []
for line in records:  
   line = line[:-1]
   r = string.split(line,':')
##   table.append(r)
##  for x in table:           ## x = r so just use r
##   for all in x:
   for all in r:
    print "testing isalpha()", all.isalpha(), all
    if all.isalpha() == 0:
     num = float(all)
    else:
     num = all

##---  get the first part of the program working first
##   t.append(num)
##   newtable.append(tuple(t))

Edited 7 Years Ago by woooee: n/a

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:

infile = open('grades1.txt','r')
all_lines = infile.readlines()

all_lines = all_lines[1:]
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.

dataset = []
for eachline in all_lines:
   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.

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

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.

6th_column = []
for eachline in all_lines:
    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])

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

A+ =[10]
A = [9,10)
A- =[8,9)
B+ =[7,8)
B =[6,7)
B- =[5,6)
C+ =[4,5)
C =[3,4)
D+ =[2,3)
F =[0,1)


grades=["ABCDA"]
i=0
total=0
while i<len(grades):
    if grades[i]  =='A':
        total=total+1
        i=i+1
print total

if you have any suggestion on how to solve this that would be great
thx again for your help i really apperciated

This question has already been answered. Start a new discussion instead.