skip to Main Content

enter image description here

class CircularlyLinkedList:
    def __init__(self):
        self.tail = None
        self.size = 0

.
.

When I ran the above code and entered:

ls1 = CirculralyLinkedList()

An error occurred: An expression must come after ‘(‘.

This error did not occur when running with IDLE.

If I need to type something after ‘(‘, please tell me what to type.

2

Answers


  1. This code seems to be working fine on my device. Please check if there are other issues showing up in your IDE.

    class CircularlyLinkedList:
        def __init__(self):
            self.tail = None
            self.size = 0
    
    
    ls1 = CircularlyLinkedList()
    print(type(ls1))
    

    If this doesn’t do it, try adding a pass statement at the end of the constructor. Like so,

    class CircularlyLinkedList:
        def __init__(self):
            self.tail = None
            self.size = 0
            pass
    

    I mentioned adding a pass statement because I saw a parser error in the image attached. In Python, the pass statement is basically a null operation, so nothing happens when it executes. It’s used as a placeholder when the syntax requires a statement, but no action is really needed in that case.

    Login or Signup to reply.
  2. You enter python code directly in the cmd terminal, which is not recognized. You need to enter pythonREPL.

    You could try the following ways:

    1. You could use jupyter-notebook extension, and the class codes to cell1 and ls1 = CirculralyLinkedList() to cell2. This way you can achieve the same goal when you execute cells sequentially
    2. Try to use python interactive window, this way is similar to the first solution.
    3. Use pythonREPL and re-import class
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search