请问这题怎么写?
应该贴代码,而不是图片 import randomdef isEqual(x,y):
if x < y :
print('too small')
return False
elif x > y :
print('too big')
return False
else:
print('bingo')
return True
times = 0
times2 = 0
dic = {}
carry_on = 'y'
print('请输入猜谜数字,范围(0-100)')
randint = random.randint(0,100)
while carry_on == 'y':
guess = int(input())
if guess >100 or guess <1:
break
result = isEqual(guess,randint)
if result:
times2 += 1
dic=times
times = 0
carry_on = input('本次游戏您已经猜中,是否继续?')
if carry_on == 'y':
print('请输入猜谜数字,范围(0-100)')
randint = random.randint(0,100)
else:
with open('game.txt','w') as f:
for i in dic:
text = '第%d次,经过%d轮后猜中答案!'%(i,dic)
print(text)
f.write(text+'\n')
average = sum(dic.values())/i
text = '统计消息:您已经猜中%d次,平均每次需要猜%d轮'%(i,int(average))
print(text)
f.write(text)
times+=1
谢谢
页:
[1]