设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第28课】 字符串的分割

[复制链接]

0

主题

2

好友

72

积分

注册会员

Rank: 2

楼主
发表于 2018-4-7 14:02:58 |显示全部楼层
这次是几乎没有改动,直接加在后面加的几句话。
  1. #football_game.py
  2. #司南 2018.04.07
  3. #方向设定
  4. direction=['left','middle','right']
  5. #扑救方
  6. def keeper(name='computer'):
  7.     import random
  8.     dic=random.choice(direction)
  9.     if name=='computer':
  10.         print('天哪,快看,守门员扑向了%s方向' %dic)
  11.     else:
  12.         print('天哪,快看,守门员%s扑向了%s方向' %(name,dic))
  13.     return dic
  14. #射门方
  15. def shoot(man):
  16.     dic=input('请输入射球方向:left/middle/right')
  17.     print('快看,%s能否射进呢?' %man)
  18.     return dic
  19. #比赛规则
  20. def fight(keeperdic,shootdic):
  21.     if keeperdic==shootdic:
  22.         print('omg,the goalkeeper win!')
  23.         return True
  24.     else:
  25.         print('天哪,球进了!!')
  26.         return False
  27. #开始比赛
  28. score_keeper=0
  29. score_shoot=0
  30. man=input('Hei,man please tell us your name:')
  31. round=eval(input('how many round do you do'))
  32. for i in range(round):
  33.     print('====Everybody the %dth round begin!===='%(i+1))
  34.     shootdic=shoot(man)
  35.     keeperdic=keeper()
  36.     res=fight(keeperdic,shootdic)
  37.     if res:
  38.         score_keeper=score_keeper+1
  39.     else:
  40.         score_shoot=score_shoot+1
  41. #判断总分胜负:
  42. if score_keeper>score_shoot:
  43.     print('伟大的守门员赢啦!!')
  44. elif score_keeper<score_shoot:
  45.     print('%s 你赢啦!'%man)
  46. else:
  47.     print('平手!决胜局来啦')
  48.     shootdic=shoot(man)
  49.     keeperdic=keeper()
  50.     res=fight(keeperdic,shootdic)
  51.     if res:
  52.         print('Everybody!!Winner is goalkeeper')
  53.     else:
  54.         print('Everybody!!Winner is %s'%man)
  55.    
  56.         
  57.    


  58.               

  59.    
  60.         
复制代码
回复

使用道具 举报

0

主题

2

好友

72

积分

注册会员

Rank: 2

沙发
发表于 2018-4-7 14:06:38 |显示全部楼层
但是按照老师给的灵感,看到了一直没注意的操作方式,就是:
可以直接操作序列中的数字。
score=[0,0]
score[0]+=1
这样操作后的结果是
score[1,0]

而,score[0]+1
score[0]的结果就依旧等于0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-6-1 17:47 , Processed in 0.023294 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部