I am fairly experienced in java and I was wondering how to use java in
python code, if you could give me any tips.\
On Thu, Feb 16, 2012 at 6:00 AM, tutor-requ...@python.org wrote:
Send Tutor mailing list submissions to
tutor@python.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org
You can reach the person managing the list at
tutor-ow...@python.org
When replying, please edit your Subject line so it is more specific
than Re: Contents of Tutor digest...
Today's Topics:
1. Debugging While Loops for Control (Luke Thomas Mergner)
2. Re: Debugging While Loops for Control (Alan Gauld)
--
Message: 1
Date: Wed, 15 Feb 2012 23:57:08 -0500
From: Luke Thomas Mergner lmerg...@gmail.com
To: tutor@python.org
Subject: [Tutor] Debugging While Loops for Control
Message-ID: a8bdf988-fe78-4ca1-8cb7-c0a0e68fd...@gmail.com
Content-Type: text/plain; charset=us-ascii
Hi,
I've been translating and extending the Blackjack project from
codeacademy.com into Python. My efforts so far are here:
https://gist.github.com/1842131
My problem is that I am using two functions that return True or False to
determine whether the player receives another card. Because of the way it
evaluates the while condition, it either prints too little information or
previously called the hitMe() function too many times. I am assuming that
I am misusing the while loop in this case. If so, is there an elegant
alternative still running the functions at least once.
e.g.
while ask_for_raw_input() AND is_the_score_over_21():
hitMe(hand)
Any advice or observations are appreciated, but please don't solve the
whole puzzle for me at once! And no, not all the functionality of a real
game is implemented. The code is pretty raw. I'm just a hobbyist trying to
learn a few things in my spare time.
Thanks in advance.
Luke
--
Message: 2
Date: Thu, 16 Feb 2012 09:05:39 +
From: Alan Gauld alan.ga...@btinternet.com
To: tutor@python.org
Subject: Re: [Tutor] Debugging While Loops for Control
Message-ID: jhigt3$jdp$1...@dough.gmane.org
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 16/02/12 04:57, Luke Thomas Mergner wrote:
My problem is that I am using two functions that return True or False
to determine whether the player receives another card.
Because of the way it evaluates the while condition, it either
prints too little information or previously called the hitMe()
function too many times.
I am assuming that I am misusing the while loop in this case.
while ask_for_raw_input() AND is_the_score_over_21():
hitMe(hand)
I haven't looked at the code for the functions but going
by their names I'd suggest you need to reverse their order to
while is_the_score_over_21() and ask_for_raw_input():
hitMe(hand)
The reason is that the first function will always get called
but you (I think) only want to ask for, and give out, another
card if the score is over 21 (or should that maybe be
*under* 21?).
Personally I would never combine a test function with
an input one. Its kind of the other side of the rule that
says don't don;t put print statements inside logic functions.
In both cases its about separating himan interaction/display from
program logic. So I'd make the ask_for_raw_input jusat return a value(or
set of values) and create a new funtion to test
the result and use that one in the while loop.
HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
--
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
End of Tutor Digest, Vol 96, Issue 69
*
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor