XD
点都不好:
#Python3.6.5+,需要random库
import random
p = random.randint(1, 1000)
n = int(input("Guess what number I'm thinking of! From 1 to 1000, you have 15 chances: "))
cnt = 14
while n != p and cnt > 0:
if n > p:
try:
n = int(
input(f"Too large! You still have {cnt} chances. Try one smaller: "))
except ValueError:
print("Please enter a NUMBER!")
cnt += 1
else:
try:
n = int(input(f"Too small! You still have {cnt} chances. Try one larger: "))
except ValueError:
print("Please enter a NUMBER!")
cnt += 1
cnt -= 1
if cnt > 0:
print("Congratulation! That's the right number.")
else:
print(f"It is {p}, Idiot. Have you ever learned Binary-Searching?")