- 帖子
- 5
- 精华
- 0
- 积分
- 23
- 阅读权限
- 10
- 注册时间
- 2016-4-12
- 最后登录
- 2016-9-13
|
本帖最后由 fishpanchax 于 2016-4-12 17:37 编辑
请问为什么我点Run Module没有任何反应呢,连保存都没法保存
from random import randint
name = raw_input('请输入你的名字:')
f = file('game.txt')
lines = f.readlines()
f.close()
scores = {}
for l in lines:
s = l.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,你已经玩了%d次,最少%d轮猜出答案,平均%.2f轮猜出答案'%(name,game_times,min_times,avg_times)
num = randint(1,100)
times = 0
print('Guess what I think')
a = 0
while a== 0:
answer = input('Your answer is:')
times += 1
if answer < num:
print'too small'
if answer > num:
print'too large'
if answer == num:
print'BINGO!!!'
a = 1
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 = ''
for n in scores:
line = n + ' ' + ' '.join(scores[n]) + '\n'
result += line
f = file('game.txt','w')
f.write(result)
f.close()
|
|