#guess a number
import random
i = 1
while i < 2:
ii = 1
game = input ("Do you want to play? If playing, type 'y'")
if game == 'y':
while ii < 2:
z_max = input ("你要猜的最大数字是什么?\n")
try:
a = int(z_max)
except:
print ("Please input a turly number.")
else:
if int(z_max) <11 or int(z_max) % 1 != 0 :
print ("请输入一个比十大的整数")
else:
number = int(random.choice(range(0,int(z_max))))
ii=3
iii = 1
z_min = 0
h = 0
while iii < 2:
g = input(f"请输入你要猜的数字({z_min}—{z_max}):")
try:
guess = int(g)
except:
print("Please input a turly number.")
else:
guess = int(g)
if guess<int(z_min) or guess > int(z_max):
print(f"Please input a turly number in {z_min}—{z_max}.")
else:
if guess > number:
print("猜错了")
h += 1
z_max = guess
elif guess < number:
z_min = guess
print("猜错了")
h += 1
else:
h += 1
print(f"恭喜你猜对了,一共用了{h}次机会")
iii = 3
ii = 3
i = 3