- 帖子
- 18
- 精华
- 0
- 积分
- 116
- 阅读权限
- 20
- 注册时间
- 2017-7-25
- 最后登录
- 2018-11-6
|
对于标红语句请问crosssin先生,如果我的初始文件设置为0 0 0 那么最小游戏次数(mintimes)就会永远为零, 如何实现将第一次游戏的times赋给mintimes,其后所有times与最小值mintimes比较?
from random import randint
f = open('c:\python\game.txt')
score = f.read().split()
f.close()
gametimes = int(score[0])
mintimes = int (score[1])
totaltimes = int (score[2])
if gametimes > 0:
avgtimes = totaltimes / gametimes
else:
avgtimes =0
print('你完了%d次,最少%d轮猜出,平均%.3f猜出答案'%(
gametimes, mintimes, avgtimes))
num = randint (1,10)
times = 0
print("开始猜")
bingo = False
while bingo == False:
times += 1
answer = int(input ())
if answer < num:
print ('small')
if answer == num:
print ('bingo')
bingo = True
if answer > num:
print('big')
totaltimes += times
gametimes +=1
if gametimes == 0 or times < mintimes :
mintimes = times
result = '%d %d %d'%(gametimes, mintimes, totaltimes)
f = open ('c:\python\game.txt','w')
f.write (result)
f.close()
|
|