Search code examples
python-3.xsyntax-errorpython-idle

'SyntaxError: invalid syntax' in python 3 IDLE


Why is this a syntax error? And how do I fix it?

class Queue:

    #Queue is basicliy a List:
    def __init__(self):
        self.queue = []

    #add to the top of the list (the left side)
    def Enqueue(self, num):
        if isinstance(num, int):
            self.queue.append(num)

    #remove from the top of the list and return it to user
    def Dequeue(self):
        return self.queue.pop(0)

#this function gets inputs from user, and adds them to queue,
#until it gets 0.
def addToQueue(queue, num):
    num = input()
    while num != 0:
        queue.Enqueue(num)
        num = input()

Solution

  • The interactive mode (with the >>> prompt) only accepts one statement at a time. You've entered two to be processed at once.

    After you've entered the class definition, be sure to add an extra blank line so that the interactive prompt knows you're done. Once you're prompted with a >>>, you'll know it is ready for the function definition.

    The rest of your code looks fine. Happy computing :-)