马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
猜数字游戏,快来和我一起创作吧
代码复制到IDLE中即可运行!import random
try:
h=open("temp.txt")
temp=h.read()
h.close()
except FileNotFoundError:
h=open("temp.txt","w")
h.close
h=open("temp.txt","r+")
temp=h.read()
h.close()
if temp=='1':
a=input("你已经试过了,输入1即可再玩一次!")
try:
if a=="1":
f = open("temp.txt","r+")
f.write("2")
f.close()
secret = random.randint(1,10)
temp = input("不妨猜一下我现在心里想的是哪个数字(1到10):")
guess = int(temp)
times = 1
while (guess != secret) and (times < 3):
if guess > secret:
print("哥,大了大了~~~")
else:
print("嘿,小了小了~~~")
temp = input("请再试试吧:")
guess = int(temp)
times = times + 1
if times < 3:
print("哎呀,你是我心里的蛔虫吗?!")
print("哼,猜中了也没有奖励噢~")
input()
else:
print("唔,给三次机会都猜错,不跟你玩了!")
input()
else:
print("输入错误")
input()
except:
print("输入错误")
elif temp=="":
print("为响应国家防沉迷措施,最多玩两次哦!")
f = open("temp.txt","r+")
f.write("1")
f.close()
secret = random.randint(1,10)
temp = input("不妨猜一下我现在心里想的是哪个数字(1到10):")
guess = int(temp)
times = 1
while (guess != secret) and (times < 3):
if guess > secret:
print("哥,大了大了~~~")
else:
print("嘿,小了小了~~~")
temp = input("请再试试吧:")
guess = int(temp)
times = times + 1
if times < 3:
print("哎呀,你是我心里的蛔虫吗?!")
print("哼,猜中了也没有奖励噢~")
input()
else:
print("唔,给三次机会都猜错,不跟你玩了!")
input()
elif temp=='2':
print("超过游戏限制!")
input()
如果有bug,可以帮忙改进吗?谢谢! |