Oops try again! Looks like your code didn't print the grade 100


#1

I'm having a similar problem. I've written the code as below and tried numerous variations, but still get error messages like "looks like your code didn't print the grade 100" or "looks like your code didn't print the grade 90"

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades):
    for grade in grades:
        print grades

I've been playing with this for 3 days now and can't get it to print the list of grades.


2/9 Exam Statistics
#2

If I remove the function and just write the 'for' and 'print' lines, then I get a green light to proceed, even though the instructions call for the function definition to be placed on line 3. ??????


#3

@noeman5 in the original code you posted you wrote

def print_grades(grades):
    for grade in grades:
        print grades

you are printing the grades list, as a whole , each time and not the individual grades
rather it should be

def print_grades(grades):
    for grade in grades:
        print grade

#now you can call the method like this
print_grades(grades) #assuming you have a list stored in a variable called grades

#4

Yep, tried that too and still got the error message about not printing 100 or printing 90, etc.

(tried posting a screenshot, we'll see if it comes out when I post.)


#5

call the method like this

print_grades(grades)

#6

Still no luck. Different error message. See below.


#7

You want something like

def print_grades(grades):
    for grade in grades:
        print grade

print_grades(grades)

The function in your first screenshot worked fine, but you never called it. In your second attempt you ended up writing a function that calls itself over and over until a safety measure kicks in.


#8

Thanks! It finally sank in, what you were talking about. I'd replaced "print grade" with "print_grades(grades)". When I re-did it just as you showed above, it came out right. I still don't understand why I need to have the print statement in two different places, but I guess it has to do with printing two different sets of subject matter (printing inside and outside of the function.) But at least I've passed this lesson now and can move on. Thanks again!.


#9

exactly what was wrong with my code! thanks rydan