菜鸟学python(9) 射门游戏(综合练习)

想写点东西把自己学习python的过程记录下来,于是就有了菜鸟学python

前段时间看了Crossin老师的python教程

里面有些小游戏很不错

比如这个射门游戏

我也试着写了一个


#coding:UTF-8                   #注释中有中文所以要加这个
"""this is a football game"""

from random import choice            

score = [0,0]        #数组:分别表示com_score和you_score
direction = ['left','center','right']      #数组:电脑表示防守方向

def kick():         #函数:射门
    print '=====%s kick=====' % (playername)
    print 'choice one side to shoot'
    print 'left center right'
    you_kick = raw_input()
    com_save = choice(direction)
    if you_kick != com_save:
        print 'goal!!!'
        score[1] += 1
    else:
        print 'oops...'
    print '=====score:(com)%d:(%s)%d====='%(score[0],playername,score[1])

def save():         #函数:防守
    com_kick = choice(direction)
    print '=====%s save=====' % (playername)
    print 'choice one side you save'
    you_save = raw_input()
    print 'left center right'
    if you_save != com_kick:
        print 'goal!!!'
        score[0] += 1
    else:
        print 'oops...'
    print '=====score:(com)%d:(%s)%d====='%(score[0],playername,score[1])

print 'please input you name:'
playername = raw_input()
print 'please input round you want to play'
round = input()
for i in range(round):                       #循环
    print '=====round %d====='%(i+1)
    kick()
    save()

while score[0] == score[1]:           #平手的加时赛
    i += 1
    print '=====overtime====='
    print '=====round %d====='%(i+1)
    kick()
    save()

if score[0] > score[1]:                    #判断输赢
    print '%s lose...'%(playername)
else :
    print '%s win!!!'%(playername)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值