def caishuzi_game(x,y):
import random
x=int(random.randint(x,y))
a=0
try:
b=int(input("请输入你要猜的数字"))
except:
print("输入类型错误,请重新输入整数型类型数字")
b=int(input("请输入你要猜的数字"))
while a<5 and a>=0:
file = open("../text.aaa/foo.txt", "a")
file.write(str(b))
file.write(" ")
file.close()
if x==b:
print("恭喜!猜中了!")
file = open("../text.aaa/foo.txt", "a")
file.write("猜中啦,")
file.write(str(b))
file.write(" ")
file.close()
break
elif b+20<=x:
a+=1
print("至少猜小了20,再试试,只有",5-a,"次机会了")
b = int(input("请输入你要猜的数字"))
file=open("../text.aaa/foo.txt","a")
file.write(str(b))
file.write(" ")
file.close()
elif b-20>=x:
a += 1
print("至少猜大了20,再试试,只有",5-a,"次机会了")
b = int(input("请输入你要猜的数字"))
file = open("../text.aaa/foo.txt", "a")
file.write(str(b))
file.write(" ")
file.close()
else:
print("正确值在你猜的上下20之间,再试试(可无限次尝试)")
b = int(input("请输入你要猜的数字"))
file = open("../text.aaa/foo.txt", "a")
file.write(str(b))
file.write(" ")
file.close()
try:
x=int(input("请输入范围开始值"))
y=int(input("请输入范围结束值"))
file = open("../text.aaa/foo.txt", "a")
file.write("开始范围值:")
file.write(str(x))
file.write(" ")
file.write("结束范围值:")
file.write(str(y))
file.write(" ")
file.close()
except :
print("输入类型错误,请重新输入")
x = int(input("请输入范围开始值"))
y = int(input("请输入范围结束值"))
file = open("../text.aaa/foo.txt", "a")
file.write("开始范围值:")
file.write(str(x))
file.write(" ")
file.write("结束范围值:")
file.write(str(y))
file.write(" ")
file.close()
caishuzi_game(x,y)
import os
os.rename("../text.aaa/foo.txt","../text.aaa/foo.aa.txt")
标签:..,--,text,write,python,int,文档,file,txt
From: https://blog.51cto.com/u_16227531/8587078