[Tutor] Debugging While Loops for Control

Luke Thomas Mergner lmergner at gmail.com
Thu Feb 16 05:57:08 CET 2012


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


More information about the Tutor mailing list