[Tutor] Blackjack Betting

Emile van Sebille emile at fenx.com
Fri Jul 1 15:17:20 CEST 2011


On 7/1/2011 12:51 AM Andre Engels said...

> In this case, the error message says:
>
> NameError: global name 'bet' is not defined

Note use of the term global?

>
> That means, at some time at the program, it is told to do something with
> 'bet', but there is no variable bet. And when does that happen? That too
> is told: at line 124, which says:
>
> bet.stash -= bet.wager
>
> Go to that line and read your code yourself - what is this 'bet' of
> which the stash is to be lessened by its wager? Have you told your
> program that this is the value of the variable 'bet'? Where and how?

Further, because global is used, it tells you that 'bet' is not in the 
local scope, nor in the global scope.  Python's general scoping 
resolution rule is local-global-builtin.  So bet, wherever you think it 
may be defined, lives in a different namespace.

See http://docs.python.org/tutorial/classes.html

Emile



More information about the Tutor mailing list