dict object is not callable - Python 3

Viewed 6705

i'm writing a Blackjack code and this what I currently have:


values = {'Two': 2, 'Three': 3, 'Four': 4, 'Five': 5, 'Six': 6, 'Seven': 7, 'Eight': 8, 'Nine': 9, 'Ten': 10,
          'Jack': 10, 'Queen': 10, 'King': 10, 'Ace': 11}

class Hand:

    # This Class will keep tracking of the Player's and Dealer's Hands

    def add_card(self,cards):
        self.cards.append(cards)
        self.value += values(cards.rank)
        if cards.rank == "Ace":
            self.aces += 1 #adds to self.aces
        pass

This is the error i'm getting below.

Traceback (most recent call last):
  File "D:/Python/Projects/BlackJack OOP1.py", line 175, in <module>
Round 1 Begins! 
    main()
  File "D:/Python/Projects/BlackJack OOP1.py", line 141, in main
    Human.add_card(Random_Deck.deal())
  File "D:/Python/Projects/BlackJack OOP1.py", line 73, in add_card
    self.value += values(cards.rank)

TypeError: 'dict' object is not callable

Can someone point to me in the right direction regarding this?

Edit: I have a global rank variable:

rank = ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace')
1 Answers

You should index into a dictionary with brackets not parentheses.

values[key]
Related