码迷,mamicode.com
首页 > 编程语言 > 详细

python入门之小栗子

时间:2017-07-23 11:20:33      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:else   from   com   oal   imp   ice   oop   one   ide   

点球小游戏:

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=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])

print ‘=====You Save=====‘
print ‘Choose one side to save!‘
print ‘left center right‘
you=input()
print ‘You saved ‘+you
com=choice(direction)
print ‘Computer kickde ‘+com
if you==com:
  print ‘Saved!‘
else:
  print ‘Oops...‘
  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.‘


python入门之小栗子

标签:else   from   com   oal   imp   ice   oop   one   ide   

原文地址:http://www.cnblogs.com/-ONE-/p/7223707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!