score = [0,0]
direction = ['left','center','right']
def kick():
print '=====You Kick!====='
print 'Choose one side to shoot:'
print 'left,center,right'
you = raw_input()
print 'You kicked ' + you
com = choice(direction)
if you != 'left' and you != 'center' and you != 'right':
print 'Game over!Spell right!'
exit()
else:
if you == com:
print 'Opps...'
else:
print 'Goal!'
score[0]+=1
print 'Score:%d(you)-%d(com)\n'%(score[0],score[1])
print '=====You Save!====='
print 'Choose one side to save'
print 'left,center,right'
you = raw_input()
print 'You save ' + you
com=choice(direction)
if you != 'left' and you != 'center' and you != 'right':
print 'Game over!Spell right!'
exit()
else:
if you == com:
print 'Saved!'
else:
print 'Opps...'
score[1]+=1
print 'Score:%d(you)-%d(com)\n'%(score[0],score[1])
for i in range(5):
print '=====Round %d====='%(i+1)
kick()
while(score[0]==score[1]):
i +=1
print'=====Round %d====='%(i+1)
kick()
if score[0]>score[1]:
print 'You Win!'
else:
print 'You Lose.'
wujinyekong 发表于 2017-9-6 10:44
from random import choice
score = [0,0]
from random import choice
score = [0,0]
direction = ['left','center','right']
def kick():
print '=====You Kick!====='
print 'Choose one side to shoot:'
print 'left,center,right'
you = raw_input()
while you != 'left' and you != 'center' and you != 'right':
print 'Choose again!Spell right!'
you = raw_input()
print 'You kicked ' + you
com = choice(direction)
if you == com:
print 'Opps...'
else:
print 'Goal!'
score[0]+=1
print 'Score:%d(you)-%d(com)\n'%(score[0],score[1])
print '=====You Save!====='
print 'Choose one side to save'
print 'left,center,right'
you = raw_input()
while you != 'left' and you != 'center' and you != 'right':
print 'Choose again!Spell right!'
you = raw_input()
print 'You save ' + you
com = choice(direction)
if you == com:
print 'Saved!'
else:
print 'Opps...'
score[1]+=1
print 'Score:%d(you)-%d(com)\n'%(score[0],score[1])
for i in range(5):
print '=====Round %d====='%(i+1)
kick()
while(score[0]==score[1]):
i +=1
print'=====Round %d====='%(i+1)
kick()
if score[0]>score[1]:
print 'You Win!'
else:
print 'You Lose.'
自问自答了……有while语句就可以了…… 作者: wujinyekong 时间: 2017-9-6 10:58
那我又有一个问题,判断 you 是不是 direction 的子集,有没有直接的判断语句,类似于集合中的包含于,这种符号?作者: crossin先生 时间: 2017-9-7 14:54
wujinyekong 发表于 2017-9-6 10:58
那我又有一个问题,判断 you 是不是 direction 的子集,有没有直接的判断语句,类似于集合中的包含于,这种 ...