1

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()
1
  • 1
    Please paste the actual code, not a screenshot of the code. Commented Apr 28, 2012 at 22:29

1 Answer 1

2

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 :-)

Sign up to request clarification or add additional context in comments.

1 Comment

Tnx! But if I have the entire code in one '*.py' file, it should be fine?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.