Code could be faulty under different cirumstances?

Hello everyone
I’ve been going over high order functions and in one of the pages there was a coding exercise to basically take a list of grades, some in the four point scale and some in the 100 point scale and turn them all to the 100 point scale.

I thought of this:

grade_list = [3.5, 3.7, 2.6, 95, 87]

# Your code below:
# assign the result of your map function to the variable grades_100scale
grades_100scale = map(lambda grades: grades * 25 if grades != int(grades) else grades, grade_list)
# convert grades_100scale to a list and save it as updated_grade_list
updated_grade_list = (list(grades_100scale))
# print updated_grade_list
print(updated_grade_list)

However, the code solution was this:

grade_list = [3.5, 3.7, 2.6, 95, 87]

# Your code below:
# assign the result of your map function to the variable grades_100scale
grades_100scale = map(lambda grade: grade*25 if grade <= 4.0 else grade, grade_list)
# convert grades_100scale to a list and save it as updated_grade_list 
updated_grade_list = list(grades_100scale)
# print updated_grade_list
print(updated_grade_list)

Maybe I just don’t know enough about the four point scale but what if someone for example got a 4?
Is the four point scale always a float or can it be an int? and if can be an int is my fault can be considered faulty?

One of the schools I know had its 4 point scale set up something like this:
60% <=> 0.0
70% <=> 1.0
80% <=> 2.0
90% <=> 3.0
100% <=> 4.0

So the formula to convert % grades to the 4 point scale would be something like:
grade_4scale = (grade_100scale / 10 ) - 6 if (grade_100scale > 60) else 0.0

And the formula to convert grades on the 4 point scale to % grades would be something like:
grade_100scale = (grade_4scale * 10) + 60

spoiler:

If those were mixed, the lambda function I’d use would be

lambda grade: (grade * 10) + 60 if grade > 4.0 else grade

The answer could be a float, I guess;
but you can convert it to an int if you want.

1 Like

No, I believe that particular grading method (which you’ll find predominantly in North America, though I’m sure there’s other places which use it) would still refer to the “top mark” as “four point oh” (4.0) and not just “four” so the grade ought to always be a float.

That being said, I’m not sure that I entirely agree with the “solution” implementation… because, whilst you would hope it would be unlikely, it is possible to score below 4 on a percentage grading system… Doesn’t look like that particular edge case would be correctly handled. :slight_smile:

GPA equates with z-score, does it not? The Standard Normal Curve is skewed out of the negative such that z=2 is the Normal. Mind this could be bollocks. Just reaching for some math that has a scale of 4.

1 Like

That > should be ≤

lambda grade: (grade * 10) + 60 if grade <= 4.0 else grade

but it does not deal with edge cases.

# Your code below: grade_list = [3.5, 3.7, 2.6, 95, 87] print(grade_list) # Your code below: # assign the result of your map function to the variable grades_100scale conversion = lambda grade: (grade * 10) + 60 if grade <= 4.0 else grade grades_100scale = map(conversion, grade_list) # convert grades_100scale to a list and save it as updated_grade_list updated_grade_list = (list(grades_100scale)) # print updated_grade_list print(updated_grade_list) def conversion4(grade): if grade < 5: return grade elif (grade > 60): grade4 = (grade / 10) - 6 return round(grade4, 2) else: return 0.0 print() print(grade_list) # assign the result of your map function to the variable grades_4scale = map(conversion4, grade_list) # convert grades_4scale to a list grades_4scale = list(grades_4scale) # print it print(grades_4scale)