- 帖子
- 10
- 精华
- 0
- 积分
- 41
- 阅读权限
- 10
- 注册时间
- 2017-1-25
- 最后登录
- 2017-2-13
|
import random
RD = random.randint(1,100)
f=open(r'C:\Python27\test\game.txt')#说下这个game.txt文件中最开始有默认值0 0 0 ,但是执行一次程序后,手动打开game文件是空白文档,
score=f.read().split() #在执行一次,却能成功运行,而且还能显示出数据,下面有个print score ,真不懂为啥
highest_times=int(score[0])
lowest_times=int(score[1])
current_times=int(score[2])
print score
f.close
print '''
请选择功能:
1.现在开始游戏
2.查看排行榜
3.退出
'''
you_id=input()
if you_id==1:
i=0
print "Guess what you think the number? And i will tips you big or samll."
while True:
you = input()
if you>RD:
print "%d is too big."%you
i=i+1
elif you<RD:
print "%d is too small."%you
i=i+1
elif you==RD:
i=i+1
print "Bingo!Congratulations!%d is right!And you used %d chance."%(you,i)
break;
current_times=i
if current_times>highest_times:
highest_times=current_times
score[0]=highest_times
elif current_times<lowest_times:
lowest_times=current_times
score[1]=lowest_times
score[2]=current_times
score='%d %d %d'%(int(score[0]),int(score[1]),int(score[2]))
print score
f=open(r'C:\Python27\test\game.txt','w')
f.write(score)
f.close
elif you_id==2:
print f.read()
f.close()
else:
exit()
|
|