Lesson 7 Incorrect Code Accepted as Correct


#1

https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/3?curriculum_id=4f89dab3d788890003000096

alright, admittedly I was going through this one a little too quickly and made a mistake in my final print statement

def get_letter_grade(score):
    if score >= 90.0:
        return "A"
    elif score >= 80.0:
        return "B"
    elif score >= 70.0:
        return "C"
    elif score >= 60.0:
        return "D"
    else:
        return "F"
        
print get_letter_grade(lloyd)

I know the correct print statement should read

print get_letter_grade(get_average(lloyd))

But what I wrote was accepted as correct for some reason. They even give me two different answers: my incorrect way spits out A, while the correct was spits out B.

Can anybody explain why this is?


#2

It was accepted as correct because the function is correct and returned the result the lesson checker was expecting in its own internal test.

Your first example should have raised an exception with an error message in the console. Something along the lines of dictionary is not an 'float'.


#3

That makes sense. Do you know how could they both be accepted as correct by the internal check if they each spit out different answers? That I don't get.


#4

There's a good chance the mistaken call did not raise an exception, just a null return, None. That is not a syntax error so wouldn't trip up the SCT. The SCT is not looking at our outputs, only those returned in its own tests. We don't see the outcomes since nothing is printed.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.