石頭剪刀布
#!/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]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.