[Tutor] more rps
Bob Gailer
bgailer at alum.rpi.edu
Tue Aug 15 22:43:46 CEST 2006
FWIF Here's my "minimalist" version:
# rock paper scissors
import random
media = ('rock', 'paper', 'scissors')
outcome = ('tie', 'human', 'computer')
winner = ((0,2,1), (1,0,2), (1,2,0))
print 'Human Computer Winner'
while 1:
h = "rpsvq".find(raw_input('Rock Paper Scissors Verify Quit').lower())
if h == -1: print "Don't recognize " + x
elif h == 4: break
elif h == 3: # print table of all combinations to verify the winner matrix
for r in [(media[h], media[c], outcome[winner[h][c]]) for h in
range(3) for c in range(3)]:
print '%10s%10s%10s' % r
else:
c = random.randint(0,2)
print '%10s%10s%10s' % (media[h], media[c], outcome[winner[h][c]])
--
Bob Gailer
510-978-4454
More information about the Tutor
mailing list