- 帖子
- 2
- 精华
- 0
- 积分
- 8
- 阅读权限
- 10
- 注册时间
- 2015-10-5
- 最后登录
- 2015-10-7
|
本帖最后由 zhangxw 于 2015-10-5 15:28 编辑
- from random import randint
- name = raw_input('Please input your name:')
- f = open('G:\PL\game.txt')
- lines=f.readlines()
- f.close()
- scores= {}
- for I in lines:
- s = I.split()
- scores[s[0]] = s[1:]
- score = scores.get(name)
- if score is None:
- score = [0,0,0]
- game_times = int(score[0])
- min_times = int(score[1])
- total_times = int(score[2])
- if game_times>0:
- avg_times = float(total_times)/game_times
- else:
- avg_times = 0
- print '%s,you have played %d times,at least take %d times guess the answer,the \
- average time to guess the answer is %.2f'%(name,game_times,min_times,avg_times)
- #game process
- num = randint(1,100)
- times = 0
- print 'Guesss what I think?'
- bingo = False
- while bingo == False:
- times += 1
- answer = input()
- if answer < num:
- print 'Too small'
- if answer > num:
- print 'Too big'
- if answer == num:
- print 'bingo'
- False = True
- if game_times == 0 or times < min_times:
- min_times = times
- total_times += times
- game_times += 1
- scores[name] = [str[(game_times),str(min_times),str(total_times)]
- result = '' #这一行报错 SyntaxError: invalid syntax 仔细看了 没错啊
- for n in scores:
- line = n+''+''.join(scores[n])+'\n'
- result += line
- f = open('G:\PL\game.txt','w')
- f.write(result)
- f.close()
复制代码 百思不得啊 明明没有错误 还是我有什么不知道的
python2.7 |
|