[Tutor] Coin game

Guess?!? wtfwhoami at gmail.com
Mon Nov 28 01:43:37 CET 2011


Hello All,

I am learning python and hence was writing code for school assignments I
could find online. I wrote my solution for this problem below. Please find
it attached.

I would like someone to review and give me comments on it. Basically
improvements/ comments to make it more efficient

problem.py has print statements in them. problem_clean is cleaner version
of the same.

Thanks,

G


Two players take turns flipping a fair coin. The game ends when the same
outcome occurs on three flips in a row. Whichever player flipped the coin
last, wins. For example:

Player 1 flips H
Player 2 flips T
Player 1 flips T
Player 2 flips H
Player 1 flips H
Player 2 flips H <<< player 2 wins

or

Player 1 flips T
Player 2 flips T
Player 1 flips T <<< player 1 wins

or

Player 1 flips H
Player 2 flips H
Player 1 flips T
Player 2 flips H
Player 1 flips T
Player 2 flips H
Player 1 flips T
Player 2 flips T
Player 1 flips H
Player 2 flips H
Player 1 flips H <<< player 1 wins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111127/87f58250/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: problem_clean.py
Type: application/octet-stream
Size: 1656 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20111127/87f58250/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: problem.py
Type: application/octet-stream
Size: 1655 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20111127/87f58250/attachment-0001.obj>


More information about the Tutor mailing list