[Tutor] (no subject)
Emile van Sebille
emile at fenx.com
Thu May 15 19:30:01 CEST 2014
On 5/14/2014 9:57 PM, JEAN MICHEL wrote:
> 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)
Note that once the above if fails such that the below elif is tested,
you already know that curraverage>= 90 from the if above failed, so
on the elif below you really don't need to test if curraverage < 90.
> 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)
You can also move the lettergrades.append(grade) outside the if tests.
Combining both simplifies this to:
if curraverage>= 90: grade="A"
elif curraverage >= 80: grade = "B"
elif curraverage >= 70: grade = "C"
elif curraverage >= 60: grade = "D"
else: grade = "F"
lettergrades.append(grade)
HTH,
Emile
More information about the Tutor
mailing list