#!/usr/bin/env python
#--- coding: gbk ---
import random
select = ['石头', '剪刀', '布']
N = len(select)
result = [
'nobody win',
'you win',
'computer win',
]
M = len(result)
choice_title = '\n'.join(
[
'%s: %s' % (
i, select[i]
) for i in range(N)
]
)
while True:
i = int(
raw_input(
'please enter your choice: \n%s\n' % choice_title
)
)
if not i in range(N):
print 'exit'
break
j = random.choice(range(N))
print 'your choice: ' + select[i]
print "computer's choice: " + select[j]
print result[(2 * i + j) % M]
#--- coding: gbk ---
import random
select = ['石头', '剪刀', '布']
N = len(select)
result = [
'nobody win',
'you win',
'computer win',
]
M = len(result)
choice_title = '\n'.join(
[
'%s: %s' % (
i, select[i]
) for i in range(N)
]
)
while True:
i = int(
raw_input(
'please enter your choice: \n%s\n' % choice_title
)
)
if not i in range(N):
print 'exit'
break
j = random.choice(range(N))
print 'your choice: ' + select[i]
print "computer's choice: " + select[j]
print result[(2 * i + j) % M]