# Calculating Letter Grades- rounding issue

Hi there, having some difficulty with this letter grades exercise on the Python track. I’ve built a piece of code which by and large does what is asked, but I’m facing some sort of rounding issue which is causing the test to fail. Not being an American, I’m not entirely clear how grade boundaries are rounded in the US, and the question doesn’t offer any hints on this.

``````def letter_grades(highest):
def thresh(ratio):
return round(((highest-40)*ratio)+40)
return [thresh(0),thresh(0.25),thresh(0.5),thresh(0.75)]
``````

The rounded result is often one too low, but not always. I’ve attempted to replace that with math.ceil before as well but with simply a different rounding error from that. Any idea what I’m doing wrong here?

On a funny note, I used to be a university lecturer here in the UK and had to do a similar problem in excel at the time. We don’t shift grade boundaries but I did have to convert numerical scores to letters en masse.

You may have an off-by-one. The lowest grade should be 41, not 40. The test output should make that much more clear. Can you share test outputs?

Additionally, the “steps” should be a fixed size. You should be able to compute an integer step size and not need to round on a per-grade level.

Ah, so you are right, it’s 41 not 40. I’ve also realised that the first value is fixed at 41, so that gets us to here:

``````def letter_grades(highest):
def thresh(ratio):
return round(((highest-41)*ratio)+41)
return [41,thresh(0.25),thresh(0.5),thresh(0.75)]
``````

That still is off-by-one on a few tests:

``````- [41, 56, 70, 85]
?           ^   ^

+ [41, 56, 71, 86]
?           ^   ^
``````

and

``````- [41, 54, 66, 79]
?           ^  ^^

+ [41, 54, 67, 80]
?           ^  ^^
``````

I’ve not yet implemented a procedural integer step size but that’s a good idea too.

EDIT- and math.ceil in place of rounding solves it. Thank you!