[Tutor] Beginner - explaining 'Flip a coin' bug

Marc Eymard marc_eymard at hotmail.com
Wed Feb 12 16:25:22 CET 2014


Hello there,

I want to emulate a coin flip and count how many heads and tails when flipping it a hundred times.

I first coded coinflip_WRONG.py with "count_flips += 1" statement within the if/else block.
When running it, either returned values are wrong or the script seems to enter in an infinite loop showing no return values at all.

coinflip.py is a corrected version I worked out myself. I moved "count_flips+= 1" out of if/else block and inserted it before if/else.

However, I still don't understand the bug since, in my understanding, both files are incrementing variable count_flips each time until the loop becomes false.

Can somebody explain the reason of the bug.
Cheers,

Marc
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140212/c3f30106/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coinflip.py
Type: text/x-script.phyton
Size: 482 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20140212/c3f30106/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coinflip_WRONG.py
Type: text/x-script.phyton
Size: 486 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20140212/c3f30106/attachment-0001.bin>


More information about the Tutor mailing list