[Tutor] Blackjack Betting
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 3 10:00:03 CEST 2011
"David Merrick" <merrickdav at gmail.com> wrote
> class BJ_Player(BJ_Hand):
> """ A Blackjack Player. """
>
> def betting(stash):
You forgot self.... so stash will take on the value of
the instance.
> try:
> if stash > 0:
> wager = int(input("\nHow much do you want to wager?:
> "))
> if wager > bet.stash:
> int(input("\n You can only wager what you have.
> How
> much?: "))
and you don't assign the result here to any variables
> class BJ_Game(object):
> """ A Blackjack Game. """
> def __init__(self, names):
> self.players = []
> for name in names:
> player = BJ_Player(name)
> bet = BJ_Player(name).betting(stash = 10)
Here you call the method and python assigns the new
instance value to stash, but you are simultaneously
assigning 10 to stash. Pyton is confused...
You need a self in your method definition.
> File "I:/Python/Python Source Code/chapter09/blackjackBetting.py",
> line
> 120, in __init__
> bet = BJ_Player(name).betting(stash = 10)
> TypeError: betting() got multiple values for keyword argument
> 'stash'
>>>>
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list