# coding=utf-8
# 猜数
# 记录猜数的过程
import random
com_result=[] #存放电脑结果,数组
com_count=0 #存放电脑猜测次数
ran=random.randint(0,100) #随机生成数字
print('Start Guessing 开始猜测')
up=100 #设置上限和下限
down=0
print('Human provide random number is: ',ran) #人随机提供一个数
guessing=0 #为循环初始化
while (guessing<=0):
com_number=round((down+up)/2) #设置每次循环,电脑猜测的随机数
if com_number
down=com_number #猜小了,把下限提高
com_result.append(com_number) #把猜测的数字存入数组
com_count+=1 #猜测次数+1
print(com_number,' is smaller than' ,ran) #显示猜测数字
if com_number>ran:
up=com_number
com_result.append(com_number)
com_count+=1
print(com_number,' is bigger than',ran)
if com_number==ran:
com_result.append(com_number)
com_count+=1
print('Finally')
print('Computer\'s guessing list: ',com_result)
print('Computer have tried: ',com_count)
guessing=1 #结束猜测