- 帖子
- 6
- 精华
- 0
- 积分
- 56
- 阅读权限
- 20
- 注册时间
- 2016-7-23
- 最后登录
- 2017-7-10
|
老师,程序可以运行,但是无法写入成绩,肿么回事啊@Crossin
本帖最后由 jinss 于 2017-6-23 15:19 编辑
f=file("E:\python\pycharm\python\game.txt")
score=f.read().split()
f.close()
game_times=int(score[0])
min_times=int(score[1])
total_times=int(score[2])
if game_times>0:
ave_times=float(total_times)/game_times
else:
ave_times=0
print'you have played %d round, at least is %d try ,avg is %.2f'%(game_times,min_times,ave_times)
from random import randint
times=0
print'guess what I think?'
num=randint(0,100)
bingo=False
while bingo==False:
times+=1
num1 = input()
if num1>num:
print'too big'
if num1<num:
print"too small"
if num1==num:
print'bingo'
bingo=True
if game_times==0 or times<min_times:
min_times=times
total_times+=times
game_times=game_times+1
result='%d,%d,%.2f'%(game_times,min_times,total_times)
f=file('E:\python\pycharm\python\game.txt','w')
f.write(result)
f.close() |
|