# 点球小游戏 2

rest = [5, 5]

if rest[0] > 0:

rest[0] -= 1

if score[0] < score[1] and score[0] + rest[0] < score[1]:

return True

if score[1] < score[0] and score[1] + rest[1] < score[0]:

return True

i = 0

end = False

while(i < 5 and not end)

print '==== Round %d ====' % (i+1)

end = kick()

i += 1

from random import choice

score = [0, 0]

rest = [5, 5]

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)

print 'Computer saved ' + com

if you != com:

print 'Goal!'

score[0] += 1

else:

print 'Oops...'

print 'Score: %d(you) - %d(com)\n' % (score[0], score[1])

if rest[0] > 0:

rest[0] -= 1

if score[0] < score[1] and score[0] + rest[0] < score[1]:

return True

if score[1] < score[0] and score[1] + rest[1] < score[0]:

return True

print '==== You Save! ===='

print 'Choose one side to save:'

print 'left, center, right'

you = raw_input()

print 'You saved ' + you

com = choice(direction)

print 'Computer kicked ' + com

if you == com:

print 'Saved!'

else:

print 'Oops...'

score[1] += 1

print 'Score: %d(you) - %d(com)\n' % (score[0], score[1])

if rest[1] > 0:

rest[1] -= 1

if score[0] < score[1] and score[0] + rest[0] < score[1]:

return True

if score[1] < score[0] and score[1] + rest[1] < score[0]:

return True

return False

i = 0

end = False

while(i < 5 and not end):

print '==== Round %d ====' % (i+1)

end = kick()

i += 1

while(score[0] == score[1]):

print '==== Round %d ====' % (i+1)

kick()

i += 1

if score[0] > score[1]:

print 'You Win!'

else:

print 'You Lose.'

#==== Crossin的编程教室 ====#

406 篇文章48 人订阅

0 条评论

## 相关文章

2204

2692

1012

3886

### 器—术—道：程序设计教材建设经验谈

《计算机教育》2017年第11期 封面文章 引 言 程序设计的境界有3种：器—术—道。在程序设计能力培养方面，一般由“器”入门，通过熟悉“术”，最终达到“道”的...

2209

1223

1K0

4149

4479

### 初级程序员面试不靠谱指南（一）

“来到这英雄宴中的人物，就算本身武功不是甚高，见识也必广博，“太祖拳法”的精要所在，可说无人不知。乔峰一招打出，人人都是情不自禁的喝了一声采！这满堂大采...

3619