Exam statistics list compreshension print


#1



Exam Statistics 2. Print those grades

I get this error message
Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: invalid syntax (python, line 4) The print statement


This is a simple list comprehension to print out everything. In general, this is a more pythonic way if I'm correct. Why does this not get through, as it will function the same way. I've been using python for awhile and maybe it just isn't what the problem expects.

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

def print_grades(grades):
    [print(x) for x in grades]

print_grades(grades).


#2

List comprehensions do not come up until the Advanced Topics unit so will not be expected by the SCT. Stay as close to the instructions as possible, without attempting to improve on the suggested code. When you have passed the lesson, then have it. But pass the lesson, first, by following the directions.

Aside

Your code three this error...

 >
  File "<stdin>", line 4
    [print(y) for y in x]
         ^
SyntaxError: invalid syntax
Unknown error.
 >

This tells us that we cannot print inside a list.


#3

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