- 帖子
- 25
- 精华
- 0
- 积分
- 72
- 阅读权限
- 20
- 注册时间
- 2018-4-5
- 最后登录
- 2018-10-21
|
本帖最后由 司南 于 2018-4-8 22:32 编辑
终于整出来了,总结经验:提前画好流程,整理思路,事半功倍
有个问题想请问一下Crossin先生,提前结束的部分,感觉自己滥用了break,请问有其他的解决办法啥的麽?- #football_game.py
- #司南 2018.04.07
- #方向设定
- direction=['left','middle','right']
- #扑救方
- def keeper(name='computer'):
- import random
- dic=random.choice(direction)
- if name=='computer':
- print('天哪,快看,守门员扑向了%s方向' %dic)
- else:
- print('天哪,快看,守门员%s扑向了%s方向' %(name,dic))
- return dic
- #射门方
- def shoot(man):
- dic=input('请输入射球方向:left/middle/right')
- print('快看,%s能否射进呢?' %man)
- return dic
- #比赛规则
- def fight(keeperdic,shootdic):
- if keeperdic==shootdic:
- print('omg,the goalkeeper win!')
- return True
- else:
- print('天哪,球进了!!')
- return False
- #开始比赛(提前比赛)
- score_keeper=0
- score_shoot=0
- man=input('Hei,man please tell us your name:')
- round_game=eval(input('how many round do you do'))
- #判断总分胜负:
- def final():
- if score_keeper>score_shoot:
- print('总冠军:伟大的守门员!!')
- elif score_keeper<score_shoot:
- print('总冠军:%s 你赢啦!'%man)
- else:
- print('平手!决胜局来啦')
- shootdic=shoot(man)
- keeperdic=keeper()
- res=fight(keeperdic,shootdic)
- if res:
- print('Everybody!!Winner is goalkeeper')
- else:
- print('Everybody!!Winner is %s'%man)
-
- #开始比赛
- for i in range(round_game):
- print('====Everybody the %dth round begin!===='%(i+1))
- shootdic=shoot(man)
- keeperdic=keeper()
- res=fight(keeperdic,shootdic)
- if res:
- score_keeper=score_keeper+1
- if score_keeper>=round_game//2+1:
- final()
- break
- else:
- score_shoot=score_shoot+1
- if score_shoot>=round_game//2+1:
- final()
- break
-
-
-
-
-
-
-
复制代码 |
|