- 帖子
- 3
- 精华
- 0
- 积分
- 17
- 阅读权限
- 10
- 注册时间
- 2018-1-25
- 最后登录
- 2018-2-9
|
本帖最后由 LeeYoung 于 2018-1-27 11:17 编辑
第28课下的点球小游戏,
下边是我打的代码,
第一个问题是 for i inrange(1) 这行代码的(1)是什么意思,另外我运行了ROUND 4 就结束了
第二个问题是,在运行过程中,有一轮我输入的 lef 少打一t, 但是仍然可以进行,这是为什么?- from random import choice
- score=[0,0]
- direction=['left','center','right']
- def kick():
- print'===YOU KICK!==='
- print'Choose one side to kick'
- print'left,center,right'
- you=raw_input()
- print'you kicked '+you
- com=choice(direction)
- print'com saved '+com
- if you!=com:
- score[0]+=1
- print'KICKED!'
- else:
- print'Oops..'
- print'Score: %d(you)-%d(com)'%(score[0],score[1])
- print'===YOU SAVE!==='
- print'Choose one side to save'
- print'left,center,right'
- you=raw_input()
- print'You saved '+you
- com=choice(direction)
- print'Com kicked '+com
- if you==com:
- print'SAVED!'
- else:
- print'Oops..'
- score[1]+=1
- print'Score:%d(you)-%d(com)'%(score[0],score[1])
- for i in range(1):
- print'ROUND %d'%(i+1)
- kick()
- while (score[0]==score[1]):
- i=i+1
- print'===ROUND %d==='%(i+1)
- kick()
- if score[0]>score[1]:
- print'YOU WIN'
- else:
- print'YOU LOSE'
复制代码 |
|