[Tutor] Blackjackbetting

Alan Gauld alan.gauld at btinternet.com
Mon Jul 4 02:09:07 CEST 2011


"David Merrick" <merrickdav at gmail.com> wrote

> I feel I'm starting to go round in circles solving this problem.
> I feel I made significant progress.

That sounds like a contradiction.
Did you make progress or are you going in circles?

Do you understand what self is?

>  File "I:/Python/Python Source Code/chapter09/blackjackBettingB.py", 
> line
> 166, in __additional_cards
>    player.bust(self,stash,wager)
> TypeError: bust() takes exactly 1 positional argument (4 given)

OK, It looks a bit confusing but here are some observations.

player.bust() takes 1 argument. You have provided 4
It looks like 3, but remember that Python fills in the 'self'
argument using the current instance to make 4 in total.

Now why are you explicitly passing self as the first argument?
It looks like you don't really understand how self is used?

But where does the 1 argument come from, BJ Player
takes 3 arguments.... but BJ Hand.bust only takes one.

Could you have managed to create a BJHand instance
where you intended a BJPlayer?

I don't know, and I'm not going to try to unravel that
mass of code for you! But it's something to check.
(print is your friend)

But remember, we said away back at the beginning:
"don't try to debug a load of code at once.
Build it up slowly, testing as you go" ?

It's a lot easier to find bugs that way. If you continue
to pursue the "built it big and then ask for help" approach
you may run out of sympathetic readers before your code
ever works...

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list