Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:18:56+00:00 2026-06-13T02:18:56+00:00

Only one argument is passed. Still I’m getting error that 2 arguments have been

  • 0

Only one argument is passed. Still I’m getting error that 2 arguments have been passed. head and tail are not being initialized to -1.

class Queue_demo:
    head=-1
    tail=-1
    a=[]

    def enqueue(data=10):
        if(head==-1 and tail==-1):
            head=head+1
            tail=tail+1
            a.append(data)
        else:
            tail=tail+1
            a.append(data)

    def dequeue():
        y=a[head]
        if(head==tail):
            head,tail=-1,-1
        else:
            head=head+1
        return y

q1=Queue_demo()
q2=Queue_demo()
q1.enqueue(12)

while(q1.tail==-1):
    print(q1.dequeue())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:18:58+00:00Added an answer on June 13, 2026 at 2:18 am

    There are a few issues with your code.

    The one that is directly causing your error is that you have not given your methods a self argument. When you call q1.enqueue(12) Python translates this to Queue_demo.enqueue(q1, 12). The object the method is being called on is passed to the method as the first argument. By convention, it is usually named self.

    This leads me to the second issue you’re going to encounter once you get past the wrong number of arguments error. Your instances are going to all be sharing the same set of data members, since they’re currently accessing class variables head, tail and a, rather than instance variables. This will be very confusing, as adding an item to one queue will make it appear in all other queues too.

    To fix this, what you will want to do is create those variables in a constructor (which is simply a method named __init__), rather than defining them in the class definition. Here’s what your __init__ method will probably look like:

    def __init__(self):
        self.head = -1
        self.tail = -1
        self.a = []
    

    Remember that Python is often different from other programming languages! You don’t need to declare your member variables, just start assigning things as values on self and you’ll be all set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That is, when you call a function with >1 arity with only one argument,
-[NSInvocationOperation initWithTarget:selector:object:] only accepts one object to be passed as an argument for the
I have now seen 2 methods for determining if an argument has been passed
Only one instance of a ScriptManager can be added to the page. this error
Why only one overload throws this exception? Little update: I understand that there was
I have one user (only one, all the others are fine) trying to update
I need to have only one button in showConfirmDialog . I tried this: int
I have only one class with many instances. Every instance is observer of couple
Only one instance of a Script Manager can be added to the page. Such
I want to select only one radio button but I cant do this. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.