- 帖子
- 7
- 精华
- 0
- 积分
- 22
- 阅读权限
- 10
- 注册时间
- 2017-12-10
- 最后登录
- 2017-12-24
|
代码如下,每次猜完,最小轮数都是0.看了好久没看出问题……谢谢各位!
from random import randint
f=open("C:\Python27\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:
avg_times=float(total_times)/game_times
else:
avg_times=0
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"too small"
if answer>num:
print"too big"
if answer==num:
print"bingo"
bingo=True
if game_times==0 or times<=min_times:
min_timens=times
total_times+=times
game_times+=1
result="%d %d %d"%(game_times,min_times,total_times)
f=open("C:\Python27\game.txt","w")
f.write(result)
f.close()
|
|