- 帖子
- 9
- 精华
- 0
- 积分
- 88
- 阅读权限
- 20
- 注册时间
- 2018-3-7
- 最后登录
- 2019-7-16
|
from random import randint
f=open('d:\Others\\text.txt')
score=f.read().split()
f.close()
cishu=int(score[0])
lunshu=int(score[1])
avg=int(score[2])
if cishu>0:
avg=float(lunshu)/cishu
else:
avg==0
print('游戏次数:%d,猜出所用的轮数:%d,平均每次所用轮数:%.2f'%(
cishu,lunshu,avg))
num=randint(1,50)
print('猜一个1到50之间的数')
Biggo=False
time=0
while Biggo==False:
time+=1
answer=int(input())
if answer>num:
print('大了')
Biggo==True
if answer<num:
print('小了')
Biggo==True
if answer==num:
print('Biggo')
Biggo==False
if cishu==0 or time<lunshu:
lunshu==time
cishu=cishu+1
avg=float(lunshu)/cishu
data='%d,%d,%.2f'%(cishu,lunshu,avg)
f=open('d:\Others\\text.txt','w')
f.write(data)
f.clsoe()
能运行,但最后无法写入最新结果,自查半天也差不是原因,求教。。。
|
|