Programming Assignment: Deep Learning for Content-Based Filtering

{moderator edit - solution code removed}

And this is the grading error I was given ( I got a 0% and need better to continue the course)
Cell #UNQ_C2. Can’t compile the student’s code. Error: SyntaxError(“‘return’ outside function”, (‘/tmp/student_solution_cells/cell_19.py’, 36, 0, ‘return d \n’))
Traceback (most recent call last):
File “/home/www/app/grading/exceptions.py”, line 112, in handle_solution_errors
yield {}
File “/home/www/app/grading/abstract.py”, line 393, in _grade
context = compiled_code.run(cell_index=cell.index)
File “/home/www/app/grading/submission/compiled_code.py”, line 195, in run
return list(self._code_items.values())[cell_num - 1].run()
File “/home/www/app/grading/submission/compiled_code.py”, line 54, in run
return import_module(self.import_statement, items)
File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 677, in _load_unlocked
File “”, line 724, in exec_module
File “”, line 860, in get_code
File “”, line 791, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/tmp/student_solution_cells/cell_19.py”, line 36
return d
^
SyntaxError: ‘return’ outside function

Just reformatted your post so the code is clear by using the “{}” tool.

Note that indentation is part of the syntax in python. You have indented the return at the same level as the “def” statement, so it is not part of the body of the function.

Please note that these courses are not an “intro to python”: it is assumed you already know python.

Also note that we aren’t allowed to post solution code in public threads. No harm done in this case: I just edited the post again to remove the code now that we have an explanation.

1 Like

Oh well that was obvious thank you. That was outside of the graded portion so I must have just accidentally removed the indent and was so focused on the graded portion I missed that.

Apologies on the solution code this was my first post so I wasn’t exactly sure on protocol but will avoid that in the future

1 Like