标题: python入门26课 点球游戏如何用函数构造? [打印本页] 作者: hc251880306 时间: 2016-6-1 14:35 标题: python入门26课 点球游戏如何用函数构造? python入门课程26课中点球小游戏
from random import choice
score_you = 0
scroe_com = 0
direction = ['left', 'center', 'right']
for i in range(0,5):
print '==== Round %d - You Kick!====' %(i+1)
print 'Choose one side to shoot:',
print 'left, center, right'
you = raw_input()
print 'You kicked: ' + you
com = choice(direction)
print 'Computer saved ' + com
if you != com:
print 'Goal!'
score_you += 1
else:
print 'Oops..'
print 'Your Score: %d --- Computer Score: %d \n' %(score_you,scroe_com)
print '==== Round %d - You Save! ====' %(i+1)
print 'Choose one side to save:'
print 'left, center, right'
you = raw_input()
print 'You save ' + you
com = choice (direction)
print 'Computer kicked: ' + com
if you == com:
print 'saved!'
else:
print 'Oops...'
scroe_com += 1
print 'Your Score: %d --- Computer Score: %d' % (score_you,scroe_com)