import random
a=random.randint(1,10000)for i inrange(30):# 电脑随机出一个数字# 我们猜一个数字
b=int(input("输入一个数字"))# 判断结果if b==a:print("六块钱去开特斯拉")breakelif b<a:print("你比你爷爷————x?")elif b>a:print("你爷爷比你————d?")import random
b =int(input("输入一个数字"))
a = random.randint(1,10000)for i inrange(3000):while0<1:if a==b :print("nubi")breakelse:
a = random.randint(1,10000)
i=i+1print(a)break
3.0
import random
big=10001
small =1
b =int(input("输入一个数字"))
a = random.randint(small, big)for i inrange(3000):while0<1:if a==b :print("newbee")breakelse:# 不重复,看大还是小,取2分之一
a =(big-small)//2+small
i=i+1print(a)if a < b:
small = a
elif a>b:
big=a
breakprint("策略1猜了%d次"%i)
big=10001
small =1
a = random.randint(small, big)for i inrange(3000):while0<1:if a==b :print("newbee")breakelse:# 不重复,看大还是小,取2分之一
a =random.randint(small,big)
i=i+1print(a)if a < b:
small = a+1elif a>b:
big = a-1breakprint("策略2猜了%d次"%i)# 猜1000次 最大值 最小值 平均数