Getting wrong Results with my grading system

43 views
Skip to first unread message

mostwanted

unread,
Nov 18, 2017, 3:07:38 AM11/18/17
to web...@googlegroups.com

 I am getting wrong results with my grading system, i think this is more of a syntax problem, i just don't know where I'm mixing up things. My system is supposed to give students grades depending on what percentages they got but the grades do not correspond well with the percentages. I'm getting wrong grades for percentages, e.g 90% is supposed to give me grade 'A' but it is giving me grade 'B', they are all mixed up!!! Can someone assist please?! Thanks.

Here is my code:
{{extend 'layout.html'}}
..............
..............
..............
{{
         total
=0
       
for report in form:
        perc
=(float(report.marks)/float(report.total))*float(100)
       
if perc>=100:
            grade
='A'
       
elif perc>=79:
            grade
='B'
       
elif perc>=69:
            grade
='C'
       
elif perc>=59:
            grade
='D'
       
elif perc>=39:
            grade
='E'
       
elif perc>=19:
            grade
='U'
       
}}

{{pass}}
         
{{
        total
+=perc
        average
=int(total/totalNum)
       
if average>=100:
            avGrade
='A'
       
elif average>=79:
            avGrade
='B'
       
elif average>=69:
            avGrade
='C'
       
elif average>=59:
            avGrade
='D'
       
elif average>=39:
            avGrade
='E'
       
elif average>=19:
            avGrade
='E'
       
}}
       
{{pass}}
       
<tr>
           
<td>{{=report.term.term}}</td>
           
<td>{{=report.subject.subject_name}}</td>
       
<td>{{=report.marks}}</td>
   
<td>{{=report.total}}</td>
             
<td>
{{=perc}}(%)
           
</td>
            <td>{{=grade}}</
td>
           
</td>
        <td>{{=report.comments}}</
td>
       
</tr>


       {{pass}}
{{pass}}
    </
table>
</div>
<div class="grades" style="margin-left: 5px;">
    <table>
        <tr>
            <th>AVERAGE</
th>
           
<th>TOTAL/GRADE</th>
            <th>CLASS/
PS</th>
            <th>SCHOOL/
PS</th>
        </
tr>
       
<tr>
           
<td>{{=average}}(%)</td>
           
<td>{{=avGrade}}</td>
           
<td>3</td>
            <td>21</
td>
       
</tr>
    </
table>

And I'd also be grateful if someone just simple explained what {{pass}} does in web2py and where do we place it because i find myself placing it in wrong places and at times it just disrupts the balance of the entire code if i don't place it correctly, that'd mean a lot, thanks.

Kiran Subbaraman

unread,
Nov 18, 2017, 4:00:45 AM11/18/17
to web...@googlegroups.com
so if `perc >=90%, it is grade `A`? The code should reflect the same then. Right now, it is `A`, if `perc >= 100`, which is not a valid value for `perc`.
Am guessing the same is applicable for the `average` check too.
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
On 18-Nov-17 1:37 PM, mostwanted wrote:

 I am getting wrong results with my grading system, i think this is more of a syntax problem, i just don't know where I'm mixing up things. My system is supposed to give students grades depending on what percentages they got but the grades do not correspond well with the percentages. I'm getting wrong grades for percentages, e.g 90% is supposed to give me grade 'A' but it is giving me grade 'B', they are all mixed up!!! Can someone assist please?! Thanks.

Here is my code:
{{extend 'layout.html'}}
..............
..............
..............
{{
         total
=0
       
for report in form:
        perc
=(float(report.marks)/float(report.total))*float(100)
       
if perc>=100:
            grade
='A'
       
elif perc>=79:
            grade
='B'
       
elif perc>=69:
            grade
='C'
       
elif perc>=59:
            grade
='D'
       
elif perc>=39:
            grade
='E'
       
elif perc>=19:
            grade
='U'
       
}}

{{pass}}
         
{{
        total
+=
perc
        average
=int(average/totalNum)


--
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jose C

unread,
Nov 18, 2017, 4:05:02 AM11/18/17
to web2py-users
Simple logic error...

Your first if clause should most likely be:
if perc >= 90:

in order to trap that value. 



Anthony

unread,
Nov 18, 2017, 7:38:28 AM11/18/17
to web...@googlegroups.com

And I'd also be grateful if someone just simple explained what {{pass}} does in web2py and where do we place it because i find myself placing it in wrong places and at times it just disrupts the balance of the entire code if i don't place it correctly, that'd mean a lot, thanks.

The use of {{pass}} is explained here: http://web2py.com/books/default/chapter/29/05/the-views#The-views. Python usually defines code blocks based on indentation, but since the views do not require proper Python indentation, we need an alternate way to define code blocks when the boundaries are not otherwise obvious -- so you use {{pass}} to indicate the end of a code block. For example:

{{if some_condition:}}
This
{{else:}}
That
{{pass}}
Now we are outside the "else" block, so this line will always be displayed.

Without the {{pass}}, that last line would be part of the "else" block and therefore only display conditionally. Note, we do not need a {{pass}} at the end of the "if" block above, because the {{else:}} implies the end of the "if" block.

Typically, you would need a {{pass}} to indicate the end of an if, else, elif, or for block in a view.

Anthony

mostwanted

unread,
Nov 18, 2017, 9:15:36 AM11/18/17
to web2py-users
I want grade 'A' to fall within a range of percentages, 'A' ranges from 80%(being the lowest) to 100%(being the highest), how do i reflect that here to get the system to grade properly??

mostwanted

unread,
Nov 18, 2017, 9:16:03 AM11/18/17
to web2py-users
I want grade 'A' to fall within a range of percentages, 'A' ranges from 80%(being the lowest) to 100%(being the highest), how do i reflect that here to get the system to grade properly??


mostwanted

unread,
Nov 18, 2017, 9:18:30 AM11/18/17
to web2py-users
Thanks for the {{pass}} clarification, its clear now

Anthony

unread,
Nov 18, 2017, 6:06:20 PM11/18/17
to web2py-users


On Saturday, November 18, 2017 at 9:15:36 AM UTC-5, mostwanted wrote:
I want grade 'A' to fall within a range of percentages, 'A' ranges from 80%(being the lowest) to 100%(being the highest), how do i reflect that here to get the system to grade properly??

if perc >= 80:

The upper range doesn't matter, as presumably 100 is the maximum anyway.

Note, though, that you have defined a B as >= 79. That means that you get a B only if your percentage is between 79 and 80 -- once you hit 80, it's an A. Is that really what you want?

Anthony

mostwanted

unread,
Nov 19, 2017, 12:37:50 AM11/19/17
to web2py-users
What i want is to reflect an a 'A' if a student gets anything between 100% and 80%, hence the line
if perc>=100:
            grade
='A'

and get grade 'B' if a student gets anything between79% and 70% hence the line

elif perc>=79:
            grade
='B'
elif perc>=69:
            grade
='C'
When i coded it i thought it's straight forward it'd reflect correctly but instead 70% gives me 'C' and 80% to 90% give me a 'B'!!!! I Cant figure out what I'm doing wrong where!

黄祥

unread,
Nov 19, 2017, 5:08:57 AM11/19/17
to web2py-users
think the answer is right in front of you (just a matter of conditional logic):
What i want is to reflect an a 'A' if a student gets anything between 100% and 80%, hence the line
if perc>=100:
grade='A'
pls try (not tested):
if perc>=80 and perc<=100:
grade='A'
and get grade 'B' if a student gets anything between79% and 70% hence the line
elif perc>=79:
grade='B'
pls try (not tested):
elif perc>=70 perc<=79:
grade='B'

best regards,
stifan

Jose C

unread,
Nov 19, 2017, 5:09:49 AM11/19/17
to web...@googlegroups.com
This is starting to look like a homework assignment.  You do not seem to understand what the >= (greater than or equal to) means.

The python statement:
if perc >=100:
grade
='A'
elif perc >= 79:
grade
='B'
...

means or reads as (in English):  
if the value in 'perc' is greater than or equal to 100, then set the value of 'grade' to 'A'.  
Else if the value in perc is greater than or equal to 79 , then set the value of grade to 'B'.
Else if the value in perc is greater than or equal to 69, then set the value of grade to 'C'
and so on....

The above statements stop being evaluated after the first condition that is true.

Now can you see the error in the logic? If not, I would suggest you run through some sample values for perc using the above statements and see if that helps.


mostwanted

unread,
Nov 19, 2017, 7:57:58 AM11/19/17
to web...@googlegroups.com
WOOOW!!! Thank you Jose i have been switching the signs, i have been using > as small than and as greater than,i do not know when all this information got mixed up in my head but it took your words to pay close attention & realize my error. Thank you.

And honestly its not a school assignment
Reply all
Reply to author
Forward
0 new messages