[Python] Problem with arguments given

21 views
Skip to first unread message

Dariusz Mysior

unread,
Mar 14, 2015, 4:30:16 AM3/14/15
to django...@googlegroups.com
Mam jeden problem nie wiem dlaczego mam bład
I have problem with this bug :/


Traceback (most recent call last):
  File "C:\Python31\makao.py", line 23, in <module>
    nr_players=Hand.ask_number("Ilu graczy ma wziąść udział w grze (2-5):",low=2,high=5)
TypeError: ask_number() takes exactly 4 non-keyword positional arguments (1 given)

my code


class Hand(object):              
   
def ask_number(self,question,low,high):    
        response
=None
       
while response not in range(low,high):
            response
=int(input(question))
       
return response
   
def ask_human_players(self,question,nr_player):
        response
=None
       
while response not in range(low,nr_player):
            response
=int(input(question))
       
return response
 
nr_players
=Hand.ask_number("Ilu graczy ma wziąść udział w grze (2-5):",low=2,high=5)
print(nr_players)
 
human_players
=Hand.ask_human_players("Ile graczy to ludzie",nr_players)
print(human_players)

John

unread,
Mar 14, 2015, 7:23:01 AM3/14/15
to django...@googlegroups.com

Dariusz,

You've declared ask_number() as an instance method in class Hand. You are calling it as if it was a class method. See https://docs.python.org/3.1/tutorial/classes.html.

John
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b825f565-98fb-4bf3-a136-58dfcb424dc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anderson Resende

unread,
Mar 14, 2015, 11:09:31 AM3/14/15
to django...@googlegroups.com, john-...@martinhome.org.uk
Change your method:


def ask_number(self,question,low,high):    
        response
=None
       
while response not in range(low,high):
            response
=int(input(question))


change  self to class:
This way you can call the method directly from Hand.

@classmethod
def ask_number(class,question,low,high):    
        response
=None

Babatunde Akinyanmi

unread,
Mar 14, 2015, 11:43:48 AM3/14/15
to Django users


On 14 Mar 2015 12:22, "John" <john-...@martinhome.org.uk> wrote:
>
>
> Dariusz,
>
> You've declared ask_number() as an instance method in class Hand. You are calling it as if it was a class method. See https://docs.python.org/3.1/tutorial/classes.html.
>

In other words, you have to first create an instance of Hand before calling the ask_number method.

Your code might then be something like:
nr_players=Hand()
nr_players.ask_number("Ilu graczy ma wziąść udział w grze (2-5):",low=2,high=5)

> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/550419D5.1060503%40martinhome.org.uk.

Reply all
Reply to author
Forward
0 new messages