CSSE1001 / MyPyTutor

Interactive tutorial application for Python3.
Other
7 stars 12 forks source link

problem with the raising an exception problem #151

Closed pjritee closed 9 years ago

pjritee commented 9 years ago

this comes from a posting on piazza (slightly modified).

The code is:

class InvalidCommand(Exception):
    pass

def validate_input(string):
    """
    validate_input(str) -> (str, [float])

    If string is a valid command, return its name and arguments.
    If string is not a valid command, raise InvalidCommand

    Valid commands:
      add x y
      sub x y
      mul x y
      div x y

    Arguments x and y must be convertable to float.

    """
    # your code here
    cmd=string.split()
    print(cmd)
    if len(cmd)!=3 or cmd[0] not in ["add","sub","mul","div"]:
        raise InvalidCommand()
    try:
        float(cmd[1])
        float(cmd[2])
        error = False
    except ValueError:
        error=True
    if error:
        raise InvalidCommand()
    out=(cmd[0],[float(cmd[1]),float(cmd[2])])
    return out

and when I choose this problem after saving this code (and restarting) it I get (in the terminal):

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1490, in __call__
    return self.func(*args)
  File "/home/pjr/MyPyTutor/tutorlib/gui/app/menu.py", line 262, in <lambda>
    cb = (lambda t=tutorial: lambda: self.problem_callback(t))()
  File "/home/pjr/MyPyTutor/tutorlib/gui/app/menu.py", line 215, in problem_callback
    self.delegate.change_problem(problem=tutorial)
  File "/home/pjr/MyPyTutor/tutorlib/utils/decorators.py", line 10, in method
    return f(self, *args, **kwargs)
  File "/home/pjr/MyPyTutor/tutorlib/gui/app/app.py", line 523, in change_problem
    self.run_tests()
  File "/home/pjr/MyPyTutor/tutorlib/utils/decorators.py", line 10, in method
    return f(self, *args, **kwargs)
  File "/home/pjr/MyPyTutor/tutorlib/gui/app/app.py", line 396, in run_tests
    self.current_tutorial, code_text
  File "/home/pjr/MyPyTutor/tutorlib/interface/tests.py", line 64, in run_tests
    analyser.analyse(text)
  File "/home/pjr/MyPyTutor/tutorlib/analysis/analyser.py", line 118, in analyse
    handle_event[event](node)
  File "/usr/lib/python3.4/ast.py", line 245, in visit
    return visitor(node)
  File "/home/pjr/MyPyTutor/tutorlib/analysis/visitor.py", line 278, in visit_Assign
    fn.assigned_value_of[assignment_value].append(target_id)
  File "/home/pjr/MyPyTutor/tutorlib/analysis/support.py", line 121, in __getitem__
    return self._store[self._convert_key(key)]
TypeError: unhashable type: 'list'
sapi commented 9 years ago

Fixed. Tell him thanks!

pjritee commented 9 years ago

BTW - the student says (in reporting the error with the code I put in post, without the error = False line): When I submit my code for the "Raising an Exception" question in the "Classes, Error Handling and I/O" set, I get the following error:

Error in code: test not run (possibly infinite loop)
--------------------------------------------
---------------------------------------------
SyntaxError: invalid character in identifier (<student-code>, line 26)

The position of the syntax error does not change even if I add new lines above line 26 (I added them at like line 20, below the docstring). I've checked the tabs and white space (i converted to spaces in Sublime Text) and there doesn't appear to be spacing issues.

Running my code in IDLE appears to bring about the correct result.

sapi commented 9 years ago

I tested my fix with his code locally, so I dunno what's up with that. If he's updated MPT it should work fine :/

On Monday, March 9, 2015, Peter Robinson notifications@github.com wrote:

BTW - the student says (in reporting the error with the code I put in post, without the error = False line): When I submit my code for the "Raising an Exception" question in the "Classes, Error Handling and I/O" set, I get the following error:

Error in code: test not run (possibly infinite loop)

SyntaxError: invalid character in identifier (, line 26)

The position of the syntax error does not change even if I add new lines above line 26 (I added them at like line 20, below the docstring). I've checked the tabs and white space (i converted to spaces in Sublime Text) and there doesn't appear to be spacing issues.

Running my code in IDLE appears to bring about the correct result.

— Reply to this email directly or view it on GitHub https://github.com/CSSE1001/MyPyTutor/issues/151#issuecomment-77799939.

sapi commented 9 years ago

If it still happens after updating can you ask him to sync his code with the server so we can see exactly what he's got entered?

On Monday, March 9, 2015, Sean Purdon sean.purdon@gmail.com wrote:

I tested my fix with his code locally, so I dunno what's up with that. If he's updated MPT it should work fine :/

On Monday, March 9, 2015, Peter Robinson <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

BTW - the student says (in reporting the error with the code I put in post, without the error = False line): When I submit my code for the "Raising an Exception" question in the "Classes, Error Handling and I/O" set, I get the following error:

Error in code: test not run (possibly infinite loop)

SyntaxError: invalid character in identifier (, line 26)

The position of the syntax error does not change even if I add new lines above line 26 (I added them at like line 20, below the docstring). I've checked the tabs and white space (i converted to spaces in Sublime Text) and there doesn't appear to be spacing issues.

Running my code in IDLE appears to bring about the correct result.

— Reply to this email directly or view it on GitHub https://github.com/CSSE1001/MyPyTutor/issues/151#issuecomment-77799939.