thank you for the all advice I really appreciate it. I probably wasn't wasn't too clear when i first sent my email asking for help, my apologies so let me better explain what i'm doing. I'm trying to write a program that reads 3 class data files such as period1.txt, period2.txt. Inside those files are the first name, last name, and 3 test scores from 3 different students.
The format of the data files looks like this Meagan. Hesse. 99. 99. 99 My program is then suppose to take the average assign a grade and write the results and also the students names in another txt folder I've tried fixing some of the problems but it looks like it's still a work in progress I'm not to sure whether i'm opening the data files right, can you take a look at that part def calcaverage(test1,test2,test3): for count in range(test1,test2,test3): curraverage=0 curraverage=((test1[count]+ test2[count]+ test3[count])/3) currentaverage.append(curraverage) if curraverage>= 90: grade= "A" lettergrades.append(grade) elif curraverage >= 80 and curraverage < 90: grade= "B" lettergrades.append(grade) elif curraverage >= 70 and curraverage < 80: grade= "C" lettergrades.append(grade) elif curraverage < 70: grade= "F" lettergrades.append(grade) name=[] test1=[] test2=[] test3=[] averagescore=[] lettergrades=[] with open ("period1.txt", 'r') as infile: for line in infile: values = line.split() name.append(values[0] + ','+ values[1]) for line in infile: values = line.split() score1=float(values[2]) test1.append(score1) for line in infile: values = line.split() score2=float(values[3]) test2.append(score2) for line in inline: values = line.split() score3=float(values[4]) test3.append(score3) averagescore=calcaverage(test1,test2,test3) print(line) On Wed, May 14, 2014 at 9:15 PM, Danny Yoo <d...@hashcollision.org> wrote: > > if curraverage>= 90: > > grade= "A" > > lettergrades.append(grade) > > else: > > if curraverage >= 80 and curraverage < 90: > > grade= "B" > > lettergrades.append(grade) > > else: > > if curraverage >= 70 and curraverage < 80: > > grade= "C" > > lettergrades.append(grade) > > else: > > if curraverage < 70: > > grade= "F" > > lettergrades.append(grade) > > > Just wanted to note that this style of cascading if statements is a > little unusual here. Since you know that only one of the tests is > going to be true, you can use a more parallel structure. > > That is, if you're doing something like: > > ################## > if test1: > ... > else: > if test2: > ... > else: > if test3: > ... > else: > ... > ################## > > and if you know that test1, test2, and test3 don't overlap, you can > express this as: > > > ################## > if test1: > ... > elif test2: > ... > elif test3: > ... > else: > ... > ################## > > and avoid the Tower of Pisa-style code. >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor