Re: [Tutor] Blackjack Betting

2011-07-01 Thread Vincent Balmori

Sorry. Here is the entire Error stack if this can help.

Traceback (most recent call last):
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 240, in module
main()
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 236, in main
game.play()
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 204, in play
player.win()
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 129, in win
bet.stash += bet.wager



Prasad, Ramit wrote:
 
I keep getting the error: “NameError: global
name 'bet' is not defined.” I know I came across this error before in a
previous thread, but I am confused on how to solve this, since I am also
trying to juggle it with inherited methods at the same time.
 
 Telling us this without the stack trace is pretty unhelpful. The Python
 exceptions include a very good stack trace (with line numbers +- 1 line)
 and a decent description. This error means that wherever this error was
 raised was a reference to the name bet and it had no reference to any
 bet at that point. The reasons could be that you forgot to assign a
 value to the name first, maybe it was a typo, in a preceding function,
 forgot the reference to self, etc, etc.
 
 I took a *quick* look at the code and found this (I did not check for
 other problems or if this error happens in more than one place):
 
 
 class BJ_Player(BJ_Hand, Bet):
  A Blackjack Player. 
 def is_hitting(self):
 response = games.ask_yes_no(\n + self.name + , do you want a
 hit? (Y/N): )
 return response == y
 
 def bust(self):
 print(self.name, busts.)
 self.lose()
 
 def lose(self):
 print(self.name, loses.)
 betting = Bet()
 bet.stash -= bet.wager
 
 def win(self):
 print(self.name, wins.)
 bet = Bet()
 bet.stash += bet.wager
 
 def push(self):
 print(self.name, pushes.)
 
 
 There are a couple things wrong with this class. First, you never define
 an __init__ which might be technically okay but is unlikely to be what you
 want for any user defined class (especially one with multiple
 inheritance). Since there is no __init__ defined, it will call the first
 parent class BJ_Hand.__init__ but not the second parent class Bet.__init__
 (if it has one). 
 
 Next for BJ_Player.lose(), bet is never defined and thus neither is
 bet.stash. Maybe you meant betting.stash -= betting.wager? I bet if you
 ran lint/pylint on this module it would have told you the error without
 even having to run it.
 
 
 Ramit
 
 
 Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
 712 Main Street | Houston, TX 77002
 work phone: 713 - 216 - 5423
 
 
 
 -Original Message-
 From: tutor-bounces+ramit.prasad=jpmchase@python.org
 [mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of
 Vincent Balmori
 Sent: Thursday, June 30, 2011 1:49 PM
 To: tutor@python.org
 Subject: [Tutor] Blackjack Betting
 
 
 I have been working on another challenge that involves improving the
 Blackjack program so the players can wager an amount. If a player loses
 they
 will be removed from the game.  I keep getting the error: “NameError:
 global
 name 'bet' is not defined.” I know I came across this error before in a
 previous thread, but I am confused on how to solve this, since I am also
 trying to juggle it with inherited methods at the same time. Here is the
 old
 and new file for the blackjack program for comparison:
 
 http://old.nabble.com/file/p31966195/blackjack.py blackjack.py 
 http://old.nabble.com/file/p31966195/blackjackbetting.py
 blackjackbetting.py 
 -- 
 View this message in context:
 http://old.nabble.com/Blackjack-Betting-tp31966195p31966195.html
 Sent from the Python - tutor mailing list archive at Nabble.com.
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 This communication is for informational purposes only. It is not
 intended as an offer or solicitation for the purchase or sale of
 any financial instrument or as an official confirmation of any
 transaction. All market prices, data and other information are not
 warranted as to completeness or accuracy and are subject to change
 without notice. Any comments or statements made herein do not
 necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
 and affiliates.
 
 This transmission may contain information that is privileged,
 confidential, legally privileged, and/or exempt from disclosure
 under applicable law. If you are not the intended recipient, you
 are hereby notified that any disclosure, copying, distribution, or
 use of the information contained herein (including any reliance
 thereon) is STRICTLY PROHIBITED. Although this transmission and any
 

Re: [Tutor] Blackjack Betting

2011-07-01 Thread Vincent Balmori

Here is the other one that occurs when I lose

Traceback (most recent call last):
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 240, in module
main()
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 236, in main
game.play()
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 211, in play
player.lose()
  File
/Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
line 124, in lose
bet.stash -= bet.wager
NameError: global name 'bet' is not defined


Prasad, Ramit wrote:
 
I keep getting the error: “NameError: global
name 'bet' is not defined.” I know I came across this error before in a
previous thread, but I am confused on how to solve this, since I am also
trying to juggle it with inherited methods at the same time.
 
 Telling us this without the stack trace is pretty unhelpful. The Python
 exceptions include a very good stack trace (with line numbers +- 1 line)
 and a decent description. This error means that wherever this error was
 raised was a reference to the name bet and it had no reference to any
 bet at that point. The reasons could be that you forgot to assign a
 value to the name first, maybe it was a typo, in a preceding function,
 forgot the reference to self, etc, etc.
 
 I took a *quick* look at the code and found this (I did not check for
 other problems or if this error happens in more than one place):
 
 
 class BJ_Player(BJ_Hand, Bet):
  A Blackjack Player. 
 def is_hitting(self):
 response = games.ask_yes_no(\n + self.name + , do you want a
 hit? (Y/N): )
 return response == y
 
 def bust(self):
 print(self.name, busts.)
 self.lose()
 
 def lose(self):
 print(self.name, loses.)
 betting = Bet()
 bet.stash -= bet.wager
 
 def win(self):
 print(self.name, wins.)
 bet = Bet()
 bet.stash += bet.wager
 
 def push(self):
 print(self.name, pushes.)
 
 
 There are a couple things wrong with this class. First, you never define
 an __init__ which might be technically okay but is unlikely to be what you
 want for any user defined class (especially one with multiple
 inheritance). Since there is no __init__ defined, it will call the first
 parent class BJ_Hand.__init__ but not the second parent class Bet.__init__
 (if it has one). 
 
 Next for BJ_Player.lose(), bet is never defined and thus neither is
 bet.stash. Maybe you meant betting.stash -= betting.wager? I bet if you
 ran lint/pylint on this module it would have told you the error without
 even having to run it.
 
 
 Ramit
 
 
 Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
 712 Main Street | Houston, TX 77002
 work phone: 713 - 216 - 5423
 
 
 
 -Original Message-
 From: tutor-bounces+ramit.prasad=jpmchase@python.org
 [mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of
 Vincent Balmori
 Sent: Thursday, June 30, 2011 1:49 PM
 To: tutor@python.org
 Subject: [Tutor] Blackjack Betting
 
 
 I have been working on another challenge that involves improving the
 Blackjack program so the players can wager an amount. If a player loses
 they
 will be removed from the game.  I keep getting the error: “NameError:
 global
 name 'bet' is not defined.” I know I came across this error before in a
 previous thread, but I am confused on how to solve this, since I am also
 trying to juggle it with inherited methods at the same time. Here is the
 old
 and new file for the blackjack program for comparison:
 
 http://old.nabble.com/file/p31966195/blackjack.py blackjack.py 
 http://old.nabble.com/file/p31966195/blackjackbetting.py
 blackjackbetting.py 
 -- 
 View this message in context:
 http://old.nabble.com/Blackjack-Betting-tp31966195p31966195.html
 Sent from the Python - tutor mailing list archive at Nabble.com.
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 This communication is for informational purposes only. It is not
 intended as an offer or solicitation for the purchase or sale of
 any financial instrument or as an official confirmation of any
 transaction. All market prices, data and other information are not
 warranted as to completeness or accuracy and are subject to change
 without notice. Any comments or statements made herein do not
 necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
 and affiliates.
 
 This transmission may contain information that is privileged,
 confidential, legally privileged, and/or exempt from disclosure
 under applicable law. If you are not the intended recipient, you
 are hereby notified that any disclosure, copying, distribution, or
 use of the information contained herein (including any reliance
 thereon) is STRICTLY PROHIBITED. 

Re: [Tutor] Blackjack Betting

2011-07-01 Thread Andre Engels
On Fri, Jul 1, 2011 at 9:29 AM, Vincent Balmori vincentbalm...@yahoo.comwrote:


 Here is the other one that occurs when I lose

 Traceback (most recent call last):
  File

 /Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
 line 240, in module
main()
  File

 /Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
 line 236, in main
game.play()
  File

 /Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
 line 211, in play
player.lose()
   File

 /Users/vincentbalmori/Desktop/Python/py3e_source/chapter09/blackjackbetting.py,
 line 124, in lose
bet.stash -= bet.wager
 NameError: global name 'bet' is not defined


That error message is really quite expressive, it would much more help you
to learn to read it yourself than to run to us every time something goes
wrong. The most interesting part of an error message are its last few lines,
they say what went wrong, and where it happened. The rest tells you how it
got there, which also is important to know sometimes, but many errors can
already be solved without looking at it.

In this case, the error message says:

NameError: global name 'bet' is not defined

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?

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Limit raw_input to hundredth decimal point

2011-07-01 Thread Ryan Kirk
Is there a way to limit raw_input to the hundredth decimal point?

For example, I'd like to allow the user to enter 5.75 but not 5.756:

dollars = raw_input(Please enter a dollar amount: $)

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem reading script

2011-07-01 Thread Lisi
I am supposed to be looking at scripts on-line, reading them and making sure 
that I understand them.  I think taht most of teh things I can't make more 
than a guess at, are modules taht I don't know, and I can mostly make them 
out.  But the unpaired double quotation mark,  , in the following has me 
stumped:

report['BzrLogTail'] = ''.join(bzr_log_tail)

The line ends accurately as it did in the script I was looking at.  In case 
you need the whole script to make out what the  means, the URL is:
http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/view/head:/apport/source_bzr.py

and I have copied and pasted the function definition in which it is to be 
found after my signature.

I would be extremely grateful for an explanation/translation!

Lisi

def _add_log_tail(report):

  # may have already been added in-process

  if 'BzrLogTail' in report:

   return

  
  bzr_log_lines = open(bzr_log).readlines()

   bzr_log_lines.reverse()

  
  bzr_log_tail = []

   blanks = 0

   for line in bzr_log_lines:

   if line == '\n':

   blanks += 1

   bzr_log_tail.append(line)

  27 
  if blanks = 2: 

  28 
  break

  29 
  30 
  bzr_log_tail.reverse()

  31 
  report['BzrLogTail'] = ''.join(bzr_log_tail)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Lisi
On Friday 01 July 2011 10:15:08 Lisi wrote:
 I am supposed to be looking at scripts on-line, reading them and making
 sure that I understand them.  I think taht most of teh things I can't make
 more than a guess at, are modules taht I don't know, and I can mostly make
 them out.  But the unpaired double quotation mark,  , in the following has
 me stumped:

 report['BzrLogTail'] = ''.join(bzr_log_tail)

 The line ends accurately as it did in the script I was looking at.  In case
 you need the whole script to make out what the  means, the URL is:
 http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/view/head:/apport/source_b
zr.py

So sorry.  Forgot to check typos before clicking on send.  :-(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Martin A. Brown

Greetings Lisi,

 : I am supposed to be looking at scripts on-line, reading them and 
 : making sure that I understand them. 

When you see an example that you don't understand, consider trying 
to do something similar in an interactive Python interpreter.  This 
is a simple way to learn in Python.

 : I think taht most of teh things I can't make more than a guess 
 : at, are modules taht I don't know, and I can mostly make them 
 : out.  But the unpaired double quotation mark,  , in the 
 : following has me stumped:

Look carefully.  It is not an unpaired double-quotation mark.  Are 
you using a monospaced font to read code?  If you are using a 
variable width font, you should change to monospaced.  Save yourself 
some future headache.  Really.  Use a monospaced font.

 : report['BzrLogTail'] = ''.join(bzr_log_tail)

Do you have a Python interpreter handy?  This is a fairly typical 
pythonic expression for concatenating elements of a list into a 
string.  Try the following in a python interpreter:

   l = list()
   l.append(a)
   l.append(b)
   l.append(c)
   l
  ['a', 'b', 'c']
   ''.join(l)
  'abc'

Now, you are probably wondering about that peculiar looking syntax 
for calling join() on a list.  This single quoted empty string '' is 
still a string, so it has methods that can be called on it.  Read up 
on methods available on strings [0] to get a better idea.  For other 
examples of using the string join() method, consider the following:

   ':'.join(l)
  'a:b:c'

   vampire = [ 'The','Deluxe','Transitive','Vampire' ]
   ' '.join(vampire)
  'The Deluxe Transitive Vampire'

And, for something just a bit fancier, make a list of ints, using 
the function called range():

   range(10)
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Convert them to a list of strings:

   [str(x) for x in range(10)]
  ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

Now, concatenate them and separate with some spacedash!

   visual_separator = ' -- '
   visual_separator.join(str(x) for x in range(10))
  '0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -- 8 -- 9'

With any luck, these examples help explain what you were reading.

-Martin

 [0] http://docs.python.org/dev/library/stdtypes.html#string-methods

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Limit raw_input to hundredth decimal point

2011-07-01 Thread Izz ad-Din Ruhulessin
You can use a regular expression or plain simple len()

2011/7/1 Ryan Kirk ryank...@me.com

 Is there a way to limit raw_input to the hundredth decimal point?

 For example, I'd like to allow the user to enter 5.75 but not 5.756:

 dollars = raw_input(Please enter a dollar amount: $)

 Thanks!
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Limit raw_input to hundredth decimal point

2011-07-01 Thread Christian Witts

On 2011/07/01 09:30 AM, Ryan Kirk wrote:

Is there a way to limit raw_input to the hundredth decimal point?

For example, I'd like to allow the user to enter 5.75 but not 5.756:

dollars = raw_input(Please enter a dollar amount: $)

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



If you're using Windows you can use the msvcrt module which has an 
implementation of getch() which gets 1 character at a time. Then you 
would just scan your input 1 character at a time and as soon as a the 
`.` is used you can limit it to 2 further key-strokes before you ban 
input and carry on in your process flow.

--

Christian Witts
Python Developer

//

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2to3 conversion

2011-07-01 Thread Steven D'Aprano

Zubin Mithra wrote:

Hey everyone,

I was running 2to3 on a particular file and I got the following traceback(
http://paste.pocoo.org/show/223468/).


For short amounts of text, such as a traceback, please don't use a paste 
bin, just copy it into your post.


Some people are reading mail at a time or place where they might not 
have web access, or from somewhere that blocks access to the paste bin, 
but they can still read mail.


In your case, the error is:


Traceback (most recent call last):
  File setup.py, line 86, in module
util.run_2to3([i])
  File /usr/lib/python3.0/distutils/util.py, line 572, in run_2to3
r.refactor(files, write=True)
  File /usr/lib/python3.0/lib2to3/refactor.py, line 196, in refactor
self.refactor_file(dir_or_file, write, doctests_only)
  File /usr/lib/python3.0/lib2to3/refactor.py, line 224, in refactor_file
input = f.read() + \n # Silence certain parse errors
  File /usr/lib/python3.0/io.py, line 1728, in read
decoder.decode(self.buffer.read(), final=True))
  File /usr/lib/python3.0/io.py, line 1299, in decode
output = self.decoder.decode(input, final=final)
  File /usr/lib/python3.0/codecs.py, line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 232-234: 
invalid data



which looks like a bug in the 2to3 script.

This is not really a tutor question -- this list is for learning Python, 
not general Python related questions. In future, you might have better 
responses on the main python list, python-l...@python.org.


But my guess is that the source file you are trying to convert contains 
an encoded character that doesn't exist in UTF-8. Try opening the 
original file (not the copy on the paste bin) and extracting those three 
bytes, and see what they are:



fp = open('distutils.util.py', 'r')
text = fp.read(234)
fp.close()
n = len(text.split('\n'))
s = text[232:235]
print(Bad bytes %r on line %d % (s, n))



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2to3 conversion

2011-07-01 Thread Steven D'Aprano

Steven D'Aprano wrote:

Zubin Mithra wrote:

Hey everyone,

I was running 2to3 on a particular file and I got the following 
traceback(

http://paste.pocoo.org/show/223468/).


For short amounts of text, such as a traceback, please don't use a paste 
bin, just copy it into your post.



*blinks*

Oh my, that's hilarious.

Sorry folks, nothing to see here... I accidentally clicked on an unread 
email from 2010 (!!!) and thought it had just come in.



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Limit raw_input to hundredth decimal point

2011-07-01 Thread Steven D'Aprano

Ryan Kirk wrote:

Is there a way to limit raw_input to the hundredth decimal point?


No. raw_input is a tool that does one thing: it collects input from the 
user. It doesn't understand numbers, check for decimal places, check the 
input for spelling errors, or anything else. It's a hammer, not a 
combination hammer-screwdriver-wrench-drill-saw-axe :)


One solution is to build a new tool that checks for decimal places:


def check(text):
try:
x = float(text)
except ValueError:
print please enter a number
return None
y = x*100
if y - int(y) != 0:
print please enter only two decimal places
return None
return x


def get_number(prompt):
answer = None
while answer is None:
text = raw_input(prompt)
answer = check(text)
return answer


At first, this seems to work well:

 get_number(Please enter a number with two decimal places: )
Please enter a number with two decimal places: 77.25
77.25


but there's a fundamental problem. The user is entering numbers in 
decimal (base 10), but Python does calculations in binary (base 2), and 
something that has two decimal places may not be exact in binary:


 get_number(Please enter a number with two decimal places: )
Please enter a number with two decimal places: 77.21
please enter only two decimal places

Huh? 77.21 does have two decimal places. But the closest float to 77.21 
is in fact 77.204. No computer on Earth can store 77.21 
*exactly* as a binary float, no matter how hard you try!


So, what to do...? You can:

(1) Give up on forcing the user to only enter two decimal places, and 
instead use the round() function to round to two places:


 round(77.2123456, 2)
77.204

This is still not two decimal places, but it is the closest possible 
float to 7.21, so you can't do any better.


(2) Or give up on using float, and use the decimal module instead. 
(However decimals are slower and less convenient than floats.)


 from decimal import Decimal
 x = Decimal(77.21)
 x
Decimal(77.21)


If you are working with currency, then you should use decimal, and not 
floats.




Good luck!



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Blackjack Betting

2011-07-01 Thread Emile van Sebille

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Steven D'Aprano

Lisi wrote:
I am supposed to be looking at scripts on-line, reading them and making sure 
that I understand them.  I think taht most of teh things I can't make more 
than a guess at, are modules taht I don't know, and I can mostly make them 
out.  But the unpaired double quotation mark,  , in the following has me 
stumped:


report['BzrLogTail'] = ''.join(bzr_log_tail)


There is no unpaired double quote mark. Compare:

''  # pairs single quote marks
   # unpaired double quote mark

If they look the same to you, then you need to increase your font size, 
change to a programmers font, or possible clean your glasses :)



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Lisi
On Friday 01 July 2011 14:26:07 Steven D'Aprano wrote:
 If they look the same to you, then you need to increase your font size,
 change to a programmers font, or possible clean your glasses :)

Thanks for the reply, Steven.  

Suggestions for a programmers font gratefully received.  I do have problems 
with my sight, and need to have my browser set to a font that I can read.  
But I could copy and paste to a WP and change the font for just that little 
bit.  This particular text seems to work with a serif font.

But it would be useful to know a specific programmer's font for when I am 
having difficulty seeing this particular distinction.  I am used to having to 
look at just one word in a different font to distinguish between I and l 
(which currently look identical to me), where the context doesn't help.

All I have to do now is work out/ look up what '' means!!

Lisi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Card Game

2011-07-01 Thread Christopher King
Sorry, I haven't upgraded to 3 yet.

On Thursday, June 30, 2011, Steven D'Aprano st...@pearwood.info wrote:
 Christopher King wrote:

 I would go with __cmp__ which covers them all. 1 for greater, 0 for equal,
 -1 for less than.



 So-called rich comparisons using __lt__, __gt__, etc. have been preferred 
 since Python 2.1. The major advantage of them is that they can be used for 
 more complicated data types, e.g. with sets where  means superset and  
 means subset:


 a = set([1, 2, 3, 4])
 b = set([2, 3, 4, 5])

 a  b  # a is not a subset of b
 False
 a  b  # neither is it a superset
 False
 a == b  # and they're not equal either
 False
 a  b  # but they do overlap:
 set([2, 3, 4])



 In Python 2.x, __cmp__ is only used as a fall-back if the rich comparisons 
 aren't defined. In Python 3.x, __cmp__ is gone: even if you define it, it 
 won't be used.



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2to3 conversion

2011-07-01 Thread Lisi
On Friday 01 July 2011 14:05:22 Steven D'Aprano wrote:
 Oh my, that's hilarious.

 Sorry folks, nothing to see here... I accidentally clicked on an unread
 email from 2010 (!!!) and thought it had just come in.

I'm glad that my eyes hadn't mislead me that much!!  I was trying to find the 
original.

Lisi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Card Game

2011-07-01 Thread Steven D'Aprano

Christopher King wrote:

Sorry, I haven't upgraded to 3 yet.


No need to apologise for that! Python 2.7 will be around a long time yet.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Steven D'Aprano

Lisi wrote:

On Friday 01 July 2011 14:26:07 Steven D'Aprano wrote:

If they look the same to you, then you need to increase your font size,
change to a programmers font, or possible clean your glasses :)


Thanks for the reply, Steven.  


Suggestions for a programmers font gratefully received.


Here are some links I found useful:

http://www.codinghorror.com/blog/2007/10/revisiting-programming-fonts.html
http://damieng.com/blog/2008/05/26/envy-code-r-preview-7-coding-font-released
http://www.kuro5hin.org/story/2004/12/6/11739/5249
http://www.ms-studio.com/FontSales/anonymous.html
http://www.levien.com/type/myfonts/inconsolata.html

This link astonishes me:

http://www.sitepoint.com/top-10-programming-fonts/

How can anyone claim that Arial is a good programming font? Or even a 
good font for on-screen work at all? It has to be said that Arial does 
look reasonably good printed out, but on the low resolution of computer 
monitors, it's garbage. rn and m are virtually indistinguishable in 
Arial, which essentially disqualifies it as a programmer font.



But it would be useful to know a specific programmer's font for when I am 
having difficulty seeing this particular distinction.  I am used to having to 
look at just one word in a different font to distinguish between I and l 
(which currently look identical to me), where the context doesn't help.


All I have to do now is work out/ look up what '' means!!


'' is the empty string, the same as . In Python, single quotes and 
double quotes have the same meaning. That allows you to embed one inside 
the other without escaping:


# Don't do this:
s = He said, \Waiter, there is a fly in my soup!\

# Instead do this:
s = 'He said, Waiter, there is a fly in my soup!'



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Alan Gauld


Lisi lisi.re...@gmail.com wrote

Suggestions for a programmers font gratefully received.  


I generally use Courier.

Its ugly and old fashioned but it clearly shows 
the differences between i,l, | and 1 and '' and  
and between ' and ` etc.


and spaces are big enough to see clearly. :-)

But I could copy and paste to a WP 


Never read code in a word processor. Use a 
proper programmer's editor (and there are 
loads, most free, each with its supporters) 
like:  vim, emacs, scite, Eclipse, etc


Not only will the code be clearer with syntax 
colouring etc but you will have a lot of cursor 
movement and text operations that you don't 
get in a word processor (like commenting 
out a block, or folding/hiding a block inside 
a loop, auto indenting etc, etc)


HTH,


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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Corey Richardson
Excerpts from Alan Gauld's message of Fri Jul 01 13:03:40 -0400 2011:
 
 Lisi lisi.re...@gmail.com wrote
 
  Suggestions for a programmers font gratefully received.  
 
 I generally use Courier.
 
 Its ugly and old fashioned but it clearly shows 
 the differences between i,l, | and 1 and '' and  
 and between ' and ` etc.
 

I use and love inconsolata[0], it's a great font for programming,
and looks great as well (both on screen and off).

[0] - http://www.levien.com/type/myfonts/inconsolata.html
-- 
Corey Richardson
  Those who deny freedom to others, deserve it not for themselves
 -- Abraham Lincoln
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem reading script

2011-07-01 Thread Steve Willoughby

On 01-Jul-11 10:56, Corey Richardson wrote:

Excerpts from Alan Gauld's message of Fri Jul 01 13:03:40 -0400 2011:
I use and love inconsolata[0], it's a great font for programming,
and looks great as well (both on screen and off).


I like inconsolata and Envy Code R, although just to be weird I tried 
using an old OCR font and kind of got to like that too.  A little weird 
but the glyphs are certainly distinct :)


--
Steve Willoughby / st...@alchemy.com
A ship in harbor is safe, but that is not what ships are built for.
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Thank you. Was: Re: problem reading script

2011-07-01 Thread Lisi
Thank you all for such a lot of very helpful replies.  I have been looking 
through the recommended fonts and am pleasantly surprised by how clear, 
legible and well differentiated some of them are.

I have been using Bitstream Vera Sans Mono in KWrite, which gives me all the 
colours and spacing and is very easy to read, but Bitstream Vera Sans Mono, 
like Bitstream Vera Sans itself, does not distinguish well between I and l, 
nor between '' and  (which are in fact different, but the difference is 
noticeable only if you juxtapose them).

I have already installed Inconsolata because there turned out to be a Debian 
package for it, so it took less than a minute to search for it - yes, it was 
there - and install it.  And I have set KWrite to use it.

Sadly, I am tied up all day tomorrow (it is late on Friday here) so I'll look 
into the other fonts on Sunday and work through the rest of your advice.

I might even end up being able to code in Python - but if I do it will be 
because you have all hauled me over the fences.

Lisi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Blackjack Betting

2011-07-01 Thread Vincent Balmori

I was able to get the program started without errors now. What is left now is
to: 

Having the stash change after winning and losing. No matter what, the value
in stash stays the same. The conditional statement I made which prevents
players with no money from playing is dependent on this.

After each game when I choose to play again, the betting options do not come
up again before the cards are drawn.

Apply the betting option to more than one player the same way each player
can choose to hit. I think the key involves modifying the init function in
class BJ_Game, where it adds the number of players and names.

http://old.nabble.com/file/p31977263/blackjackbetting.py blackjackbetting.py 




Emile van Sebille wrote:
 
 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
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 

-- 
View this message in context: 
http://old.nabble.com/Blackjack-Betting-tp31966195p31977263.html
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Blackjack Betting

2011-07-01 Thread Vincent Balmori

Also I must be doing something wrong if I have to enter a bet = Bet() into
each function where it is used. I tried putting Bet into the other classes'
arguments but it did not have any effect.


Emile van Sebille wrote:
 
 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
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 

-- 
View this message in context: 
http://old.nabble.com/Blackjack-Betting-tp31966195p31977301.html
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2011-07-01 Thread David Merrick
# Blackjack
# From 1 to 7 players compete against a dealer

import cards, games

class BJ_Card(cards.Card):
 A Blackjack Card. 
ACE_VALUE = 1

@property
def value(self):
if self.is_face_up:
v = BJ_Card.RANKS.index(self.rank) + 1
if v  10:
v = 10
else:
v = None
return v

class BJ_Deck(cards.Deck):
 A Blackjack Deck. 
def populate(self):
for suit in BJ_Card.SUITS:
for rank in BJ_Card.RANKS:
self.cards.append(BJ_Card(rank, suit))


class BJ_Hand(cards.Hand):
 A Blackjack Hand. 
def __init__(self, name):
super(BJ_Hand, self).__init__()
self.name = name

def __str__(self):
rep = self.name + :\t + super(BJ_Hand, self).__str__()
if self.total:
rep += ( + str(self.total) + )
return rep

@property
def total(self):
# if a card in the hand has value of None, then total is None
for card in self.cards:
if not card.value:
return None

# add up card values, treat each Ace as 1
t = 0
for card in self.cards:
  t += card.value

# determine if hand contains an Ace
contains_ace = False
for card in self.cards:
if card.value == BJ_Card.ACE_VALUE:
contains_ace = True

# if hand contains Ace and total is low enough, treat Ace as 11
if contains_ace and t = 11:
# add only 10 since we've already added 1 for the Ace
t += 10

return t

def is_busted(self):
return self.total  21

class Bet(object):
 A Blackjack Gamble. 
# Values
def __init__(bet, money = 10):
stash  = money

# Betting options
def betting(bet,stash):
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?: ))
elif wager  0:
int(input(\n You can only wager what you have. How
much?: ))
except ValueError:
int(input(\n That's not valid! Choose a number: ))

# Money Conditions
def gamble(bet):
if bet.stash = 0:
print(\nYou are out of money! You're out of the game!)


class BJ_Player(BJ_Hand):
 A Blackjack Player. 
def is_hitting(self):
response = games.ask_yes_no(\n + self.name + , do you want a hit?
(Y/N): )
return response == y

def bust(self):
print(self.name, busts.)
self.lose()

def lose(self):
print(self.name, loses.)
betting = Bet()
stash = stash - wager
print(stash)

def win(self):
print(self.name, wins.)
bet = Bet()
stash += wager
print(stash)

def push(self):
print(self.name, pushes.)


class BJ_Dealer(BJ_Hand):
 A Blackjack Dealer. 
def is_hitting(self):
return self.total  17

def bust(self):
print(self.name, busts.)

def flip_first_card(self):
first_card = self.cards[0]
first_card.flip()


class BJ_Game(object):
 A Blackjack Game. 
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()

bet = 0
bet = Bet()
bet.betting(stash)

@property
def still_playing(self):
sp = []
for player in self.players:
if not player.is_busted():
sp.append(player)
return sp

def __additional_cards(self, player):
while not player.is_busted() and player.is_hitting():
self.deck.deal([player])
print(player)
if player.is_busted():
player.bust()

def play(self):
# deal initial 2 cards to everyone
self.deck.deal(self.players + [self.dealer], per_hand = 2)
self.dealer.flip_first_card()# hide dealer's first card
for player in self.players:
print(player)
print(self.dealer)

# deal additional cards to players
for player in self.players:
self.__additional_cards(player)

self.dealer.flip_first_card()# reveal dealer's first

if not self.still_playing:
# since all players have busted, just show the dealer's hand
print(self.dealer)
else:
# deal additional cards to dealer
print(self.dealer)
self.__additional_cards(self.dealer)

if self.dealer.is_busted():
# everyone still playing wins
for player in self.still_playing:
player.win()