简体   繁体   English

字典 object 不可调用 - Python 3

[英]dict object is not callable - Python 3

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')

You should index into a dictionary with brackets not parentheses.你应该用方括号而不是圆括号索引字典。

values[key]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM