python入门之小栗子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python入门之小栗子相关的知识,希望对你有一定的参考价值。

点球小游戏:

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入门之小栗子的主要内容,如果未能解决你的问题,请参考以下文章

Apache Iceberg入门教程系列之小文件合并

入门神经网络-Python 实现(下)

微信程序开发之小程序入门

补充(代码)-入门神经网络-Python 实现(下)

Python 正则表达式入门(中级篇)

webRTC初探之小知识