List in Function in Python Read as Multiple Objects
<p>I have a function that looks like this:</p>

<pre><code>class Question:
    Ans = "";
    checkAns = 0;
    isPos=False;
    def Ask(Q, PosAns):
        checkAns=0;
        Ans = raw_input("{} ({})".format(Q,PosAns));
        while(checkAns&lt;len(PosAns) and isPos!=True):
            if(Ans==PosAns[x]):
                isPos=True; #if it IS a possible answer, the loop ends
            checkAns+=1;
            if(checkAns==len(PosAns)):
#If the loop goes through all the possible answers and still doesn't find a
#match, it asks again and resets checkAns to zero.
                Ans = raw_input("{} ({})".format(Q,PosAns));
                checkAns=0;
        return ("Good Answer");

ques = Question();
print(ques.Ask("Do you like to code?",["Yes","No"]));
</code></pre>

<p>First off, the point of this function is to take in a question (Q) and all the possible answers (PosAns), and if the user puts in something that is not one of the possible answers, then the function will simply ask again.</p>

<p>Every time I run it, however, it says that the Ask() function can only handle two parameters and that I've given it three (note that YesNo has two strings inside). Why does it read the list's objects instead of taking the list as a parameter? How can I make it take the list as the parameter?</p>

<p>I do recognize that the way I code is roundabout and strange to most people, but it's just the way things make sense to me. I'm more interested in the answer to my question than a new way to write the whole function (I'm still working on it).</p>

<p>You missed the 'self' in method declaration. Every class method (except static methods) require first argument to be <code>self</code>. self is implicily passed so doesnt show up in our method calls.
self can be used to refer the the other attributes of call like <code>isPos</code>, <code>checkAns</code> and <code>ans</code> variables in this example </p>

<p>Though one thins I wann't able to figure out what is <code>x</code> here
<code>if (Ans == PosAns[x])</code></p>

<pre><code>class Question:
Ans = "";
checkAns = 0;
isPos = False;

def Ask(self, Q, PosAns):
    Ans = raw_input("{} ({})".format(Q, PosAns));
    while (self.checkAns &lt; len(PosAns) and self.isPos != True):
        if (Ans == PosAns[x]):
            isPos = True;  # if it IS a possible answer, the loop ends
        self.checkAns += 1;
        if (self.checkAns == len(PosAns)):
            # If the loop goes through all the possible answers and still doesn't find a
            # match, it asks again and resets checkAns to zero.
            self.Ans = raw_input("{} ({})".format(Q, PosAns));
            self.checkAns = 0;
    return ("Good Answer");
</code></pre>

python