>
> {{
> average=0for report in form:
> perc=(float(report.marks)/float(report.total))*float(100)if perc>=75:
> grade='A'elif perc>=65:
> grade='B'elif perc>=55:
> grade='C'elif perc>=45:
> grade='D'
>
> This is where I'm attempting to calculate the average
>
> average+=perc
> average2=int(average/7)}}
> {{pass}}
>
>
Looks like the {{pass}} immediately above closes the if/elif block, which
means the two lines of code dealing with average and average2 only get
executed in the "elif perc >= 45" block. That means average2 wouldn't even
be defined otherwise, so I would expect you would be getting errors later
in the code whenever there isn't at least one D in the list of grades.
Also, there is no reason to calculate average2 inside the for loop -- you
only need to calculate it once after looping over all the records.
Finall, why not name the variables something like "total" and "average"
instead of "average" (which is not really an average) and "average2"?
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.