python - Required positional argument: self -


i'm new python, , need help. writing blackjack program homework, , think may have working, whenever run it, complains have not provided 'self'. thought didn't have to? here full code:

class blackjackplayer:     '''represents player playing blackjack     used hold players hand, , decide if player has hit or not.'''     def __init__(self,deck):         '''this constructs class of player.         need return players hand deck, players hand, add card deck playters hand, , allow player play dealer.         in addition of that, need deck.'''         self.deck = deck         self.hand = []      def __str__(self):         '''this returns value of hand.'''         answer = 'the cards in hand are:' + str(self.hand)         return(answer)      def clean_up(self):         '''this returns of player's cards deck , shuffles deck.'''         self.deck.extend(self.hand)         self.hand = []         import random         random.shuffle(self.deck)      def get_value(self):         '''this gets value of player's hand, , returns -1 if busted.'''         total = 0         card in self.hand:             total += card         if total > 21:             return(-1)         else:             return(self.hand)      def hit(self):         '''add 1 card deck player's hand.'''         self.hand.append(self.deck[0])         self.deck = self.deck[1:]         print(self.hand)      def play_dealer(self):         '''this make player behave dealer.'''         total = 0         card in self.hand:             total += card         while total < 17:             blackjackplayer.hit()             total += blackjackplayer[-1]             print(self.hand)         if self.hand > 21:             return -1         else:             return total 

when run this, get:

typeerror: get_value() missing 1 required positional arguments: 'self' 

i gladly appreciate help, , first time here, apologize if broke rules or something.

i'm not sure problem have in code you've shown since you're not calling get_value() anywhere in there.

it have way you're using class. need ensure instantiate object class , use call function. way, self prefixed automagically argument list.

for example:

oneeyedjim = blackjackplayer() score = oneeyedjim.get_value() 

on top of that, scoring doesn't seem take account fact aces can soft (1) or hard (11).


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -