[Tutor] rockpaperscissors
Gregor Lingl
glingl@aon.at
Tue Jan 28 12:13:03 2003
Bob Gailer schrieb:
> Here's a "minimalist" version of rockpaperscissors:
>
> import random
> score = [0,0,0]
> for i in range(3):
> play = random.randint(0,2), random.randint(0,2)
> outcome = [2,1,0,2,1][play[0] - play[1] + 2]
> print '-'.join([['rock', 'scissors', 'paper'][p] for p in play]),
> ['tie', 'player 1 wins', 'player 2 wins'][outcome]
> score[outcome] += 1
> print 'player 1-%s ties=%s player 2=%s' % tuple(score)
>
I think the last line should read:
print 'ties=%s player 1=%s player 2=%s\n' % tuple(score)
Isn't it?
Moreover, if you would agree the following to be even
more minimalstic, you could replace line #5 by:
outcome = (play[1]-play[0]) % 3
If you now wonder, why this yields the same output,
you may feel that there's something slightly uncomfortable
with "minimalistic" solutions like this.
Sincerely, Gregor