跳到正文

P01nsEr

648472

走了

在洛谷打开
资料、奖项与版本

资料

编号
648472
抓取

XD

点都不好vanvan:

Python
#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?")

初赛

LaTeX

学习资料

还没有收录这位用户的文章。