二十一点游戏中的Python属性错误

时间:2017-06-18 18:39:00

标签: python python-3.x

我正在为我的编程课工作,我们必须采取二十一点程序并添加选项进行投注。

这是原始程序: http://courses.ischool.berkeley.edu/i90/f11/resources/chapter09/blackjack.py

这没有问题。

在班级BJ_Game中,我添加了一些代码来收集投注

class BJ_Game(object):

    def __init__(self, names):      
        self.players = []
        for name in names:
            player = BJ_Player(name)
            self.players.append(player)

        self.dealer = BJ_Dealer("Dealer")

        self.deck = BJ_Deck()
        self.deck.populate()
        self.deck.shuffle()

    # betting
    def placing_bets (self, names):
        self.total_bets=10
        for name in names:
            yes_no=input("The dealer bets 10.", name, "would you like to bet on this round? (y/n)")
            if yes_no=="y":
                player_bet=input(int("How much would you like to bet?:"))    
            else:
                break
            self.total_bets=player_bet+self.total_bets    
        return self.total_bets

(抱歉格式化,我对此很新。在现实生活中,它就像在链接中一样缩进)

我做的唯一其他改变是添加底部的两行来打印获胜者赢得的赌注:

def win(self):
    print(self.name, "wins.")
    # awarding bets
    print("You win $", self.total_bets)

当我运行时,我收到错误:

AttributeError: 'BJ_Game' object has no attribute '_BJ_Game__additional_cards'

我不明白我所做的更改是如何导致这个问题的。非常感谢帮助。

1 个答案:

答案 0 :(得分:0)

这一行:

def __additional_cards(self, player):

仍在您的计划中?如果没有,你有答案。如果是,请仔细查看此行正上方的代码。