- 帖子
- 2
- 精华
- 0
- 积分
- 18
- 阅读权限
- 10
- 注册时间
- 2018-3-19
- 最后登录
- 2018-3-28
|
#coding:utf-8
from random import randint
#load file
f=open('C:\\Users\chenh\Desktop\game.txt')
score=f.read().split()
f.close()
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('C:\Users\chenh\Desktop\game.txt','w')
f.write(result)
f.close() |
|