# [Tutor] blackJack problem

Matthew D computer_dude15 at hotmail.com
Wed Oct 24 05:01:36 CEST 2012

```Thanks Alan Gauld for your help. After taking a little break and coming back it all seemed to make sense...i understand why there is gonna be some really weird outputs to the interchanging of the player1.py files...that really could get interesting LOL...I seemed to have got the program running good now i have only a few pretty simple questions, If you have the GetBet in the player1.py file you have to pass in the total value right?...that is the only way to get the total into the function? the professor told us straight out that he doesnt really know what he is doing...he wanted us to put in (currentBet, previousBet, and win/lose). I think it only makes sense if you put in the total value in as prevousBet. also he wanted us to pass in (player_hand, dealer_hand) in as parameters for the HitStand function...why would we want to total the hand more than once if we already have the total value? wouldn't we want to just pass in those values instead of the hand itself?
Im starting to think im not really learning anything from this class...if anything its just confusing me and teaching me the wrong way to go about things thanks again for your help :)> To: tutor at python.org
> From: alan.gauld at btinternet.com
> Date: Wed, 24 Oct 2012 01:23:30 +0100
> Subject: Re: [Tutor] blackJack problem
>
> On 24/10/12 01:00, Matthew D wrote:
>
> >  > > I thought by having a value outside
> >  > > of the functions made the value global.
> >  >
> > ok...is there an easier way to write this? the reason i was calling that
> > global value the same as the currentBet is because i need to add that
> > value to 5...
>
> You need to read about global variables and namespaces in Python.
>
> But using a global name as a parameter name will not make the function
> use the global name as the first parameter, in fact the opposite will
> happen in that the parameter will hide the global value.
>
> If you want to pass the global value into your function then call it
> with the global name as the first argument. If you want to change the
> global value from your function then you need to declare the name global
>
> ##########
> changeMe=666  # global valuer we will change
>
> def foo(param1):
>      print param1
>      print readMe    # accesses the global value
>
> def bar():
>     global changeMe   # use global value rather than local
>     print 'old: ', changeMe
>     changeMe = 99
>     print 'new: ', changeMe
>
> print readMe, changeMe   # print original values
>
> foo(readMe)  #prints 42 twice, once as param1, once as global value
>
> bar()   # prints old and new values
>
> print readMe, changeMe    # print after values
>
> ##################
>
> > l...still cant get even a slight idea as of what should work
>
> Try the above and variations. If you are still stuck ask here for more
> detail.
>
> You can also try reading the "Whats in a Name?" topic of my tutorial for
> a different explanation.
>
> >  > > peoples "player1.py" files on my game.
> >  >
> >  > Interesting concept. And if the other peoples files are calling your
> >  > functions with values in those parameters you will just ignore them I
> >  > presume? Hmmm, that should produce some interesting results...
> > it should work in theory correct?
>
> No, in theory users will get unpredictable results since other people
> will assume that the values they pass into your functions will influence
> the result. They will not expect you to ignore them and apply some
> totally arbitrary values of your own. The theory is that the parameters
> in a function control the behaviour, not act as simply placeholders for
> random data. If your teacher wants the function to have certain
> parameters I suspect he wants you to use them in your function!
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121023/21fd4eef/attachment-0001.html>
```