# -*- Coding:utf-8 -*-
import random
def cmp(x,y):
if x > y :
print "数字小了"
return False
elif x < y:
print "数字大了"
return False
else:
print "恭喜你答对了"
return True
file = open(r'D:\python\Crossin\record.txt','r')
score = file.read().split()
file.close()
#一共玩游戏的次数,最快猜对的轮数,总共玩的次数
game_times,min_times,total_times= int(score[0]),int(score[1]),int(score[2])
print game_times,total_times
# 平均每次猜对用的轮数
if game_times > 0:
avg_times = total_times / game_times
else:
avg_times = 0
print "你一共玩游戏的次数:%d,最快猜出的轮数是:%d,,平均每次猜对用的轮数:%d" \
% (game_times,avg_times)
print "猜数字游戏即将开始"
total = int(random.randint(0,9))
print total
times = 0
result = False
while result == False:
number = int(raw_input("请输入一个0-9的整数:"))
result = cmp(total,number)
times += 1
print "请重新输入一个数字"
#游戏次数
game_times += 1
#判断是否最快猜对的轮数
if game_times != 0 or times < min_times:
min_times = times
#一共玩的轮数
total_times += times
print game_times,total_times
result = '%d\t %d\t %d' % (game_times,total_times)
file = open(r'D:\python\Crossin\record.txt','w')
file.write(result)
file.close()
以上是内存溢出为你收集整理的python 猜数字游戏全部内容,希望文章能够帮你解决python 猜数字游戏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)