- 帖子
- 24
- 精华
- 0
- 积分
- 54
- 阅读权限
- 20
- 注册时间
- 2015-5-23
- 最后登录
- 2015-5-28
|
- #coding:utf-8
- from random import randint
- #load file
- f=open('game.txt')
- score=f.read().split()
- game_times = int(score[0])
- min_times = int(score[1])
- total_times = int(score[2])
- #judge
- if game_times>0:
- avg_times = float(total_times)/game_times
- else:
- avg_times = 0
- #output result
- print "你已经玩了%d次,最少%d轮猜出了答案,平均%.2f轮猜出了答案"%(game_times,min_times,avg_times)
- num=randint(1,100)
- times = 0
- print "Guess what i think?"
- bingo = False
- while bingo == False:
- times+=1
- answer = input()
- if answer < num:
- print "太小了!"
- if answer > num:
- print "太大了!"
- if answer == num:
- print "BINGO!"
- bingo = True
- if game_times ==0 or times <= min_times:
- min_times = times
- total_times +=times
- game_times +=1
- result = '%d %d %d'%(game_times,min_times,total_times)
- f = open('game.txt','w')
- f.write(result)
- f.close()
复制代码 |
|