Note that there are some explanatory texts on larger screens.

plurals
  1. PORequired positional argument: self
    primarykey
    data
    text
    <p>I'm new to Python, and I need some help. I was writing a blackjack program as homework, and I think I may have it working, but whenever I run it, it complains that I have not provided anything for 'self'. I thought I didn't have to? Here is the full code:</p> <pre><code>class BlackjackPlayer: '''Represents a player playing blackjack This is used to hold the players hand, and to decide if the player has to hit or not.''' def __init__(self,Deck): '''This constructs the class of the player. We need to return the players hand to the deck, get the players hand, add a card from the deck to the playters hand, and to allow the player to play like the dealer. In addition to all of that, we need a deck.''' self.Deck = Deck self.hand = [] def __str__(self): '''This returns the value of the hand.''' answer = 'The cards in the hand are:' + str(self.hand) return(answer) def clean_up(self): '''This returns all of the player's cards back to the deck and shuffles the deck.''' self.Deck.extend(self.hand) self.hand = [] import random random.shuffle(self.Deck) def get_value(self): '''This gets the value of the player's hand, and returns -1 if busted.''' total = 0 for card in self.hand: total += card if total &gt; 21: return(-1) else: return(self.hand) def hit(self): '''add one card from the Deck to the player's hand.''' self.hand.append(self.Deck[0]) self.Deck = self.Deck[1:] print(self.hand) def play_dealer(self): '''This will make the player behave like the dealer.''' total = 0 for card in self.hand: total += card while total &lt; 17: BlackjackPlayer.hit() total += BlackjackPlayer[-1] print(self.hand) if self.hand &gt; 21: return -1 else: return total </code></pre> <p>When I run this, I get:</p> <pre><code>TypeError: get_value() missing 1 required positional arguments: 'self' </code></pre> <p>I would gladly appreciate any help, and this is my first time here, so I apologize if I broke the rules or something.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload