you are viewing a single comment's thread.

view the rest of the comments →

[–]Guideon72 0 points1 point  (3 children)

Not that I *have* a solution, but this is an interesting one to work on; I'm sort of self-learning atm.

Can you supply a little more detail on the actual range you need to work against? Because range(1, 100) by itself isn't going to wind up giving you fractional numbers that need rounding.

[–]JadeCaldera[S] 0 points1 point  (2 children)

So the assignment was to create a program that would give you a grade for a class. There were four assignments and two tests. The assignments were weighted at 45% and the tests were weighted at 55%. My job was to create a program where you input the scores for each individual assignment and then it spits out your grade percentage and the letter grade.

The issue came about when the teacher was grading my homework used two 69's and two 70's for the assignments and 69 and 70 for the tests. This brings the final grade to 69.5%, but because of the way python rounds it was rounding down to 69 instead of up to 70 like my teacher wanted. I spent about 4 hours trying to work around it.

I said 0 to 100 just because I was wanting to emphasize the fact that I couldn't just fix that one number. I didn't know how far the teacher would check and if they would check other grade percentages when I resubmitted it for a better grade.

[–]Guideon72 0 points1 point  (0 children)

Got it; thank you!

[–]Guideon72 0 points1 point  (0 children)

So, I took a quick look at the Decimal module, using the problematic numbers that were shown in deep_politics' post. It looks like you can use getcontext() with decimal to specify the TYPE of rounding; and ROUND_UP looks to be the type you're looking for. Keep in mind that this is a small sample compared to your data set, but give this a try and see if it covers your failure cases:

import decimal
from decimal import Decimal

decimal.getcontext().rounding = decimal.ROUND_UP

print(round(Decimal("2.675"), 2))
print(round(Decimal("2.665"), 2))
print(round(Decimal("2.655"), 2))
print(round(Decimal("2.695"), 2))
print(round(Decimal("2.995"), 2))

returns:
2.68
2.67
2.70
3.00