1.运行结果
2. 源代码如下
import random
n = random.randint(0, 9)
count = 0
print(n)
s = int(input("please enter a number!: \n"))
while True:
if 0 <= s <= 9 and s != n:
if s > n:
count += 1
print("is bigger")
else:
count += 1
print("is smaller")
s = int(input("please enter a number!: \n"))
elif s == n:
count += 1
print(f"ok enter_times : {count}")
break
else:
print("enter error!")
s = int(input("please enter a number!: \n"))