ziheng - 猜数字升级版


# 猜数字游戏
# 电脑随机出一个1-100的数字,电脑出数字,然后电脑1,2,3猜有没有猜中
# 电脑随机出一个1-100数字
import random
com1_score = []  # 电脑1分数 =  [] 是个空列表
com2_score = []
com3_score = []
for com3 in range(100):
    max_num = 1000000000   # 最大值  max
    min_num = 1    # 最小值
    we = random.randint(min_num, max_num)   # 字符串
    # print(computer)
    # 我们猜一个数字  input
    for i in range(1000):
        # 人类策略:最小值和最大值中间出一个中间数,慢慢缩小范围
        computer = random.randint(min_num, max_num) # 最小值和最大值中间出一个随机数
        # computer = int((min_num + max_num)/2)
        # 判断
        if computer < we:
            # print("电脑1猜小了")
            min_num = computer+1
        elif we < computer:
            # print("电脑1猜大了")
            max_num = computer-1
        elif we == computer:
            print("天选之脑1")
            break
        # print("电脑猜的是%d"%computer)
    print("电脑1一共猜了%d局"%(i+1))
    com1_score.append(i+1)

    max_num = 1000000000  # 最大值  max
    min_num = 1    # 最小值
    for i in range(1000):
        # 人类策略:最小值和最大值中间出一个出一个中间数,慢慢缩小范围
        # compter 50
        # computer = random.randint(min_num, max_num) # 最小值和最大值中间出一个随机数
        computer = int((min_num + max_num)/2)
        # 判断  15  16
        if computer < we:
            # print("电脑2猜小了")
            min_num = computer
        elif we < computer:
            # print("电脑2猜大了")
            max_num = computer
        elif we == computer:
            print("天选之脑2")
            break
        # print("电脑猜的是%d"%computer)

    print("电脑2一共猜了%d局"%(i+1))
    com2_score.append(i+1)


    max_num = 100000000  # 最大值  max
    min_num = 1    # 最小值
    for i in range(1000):
        # 人类策略:最小值和最大值中间出一个出一个中间数,慢慢缩小范围
        # compter 50
        # computer = random.randint(min_num, max_num) # 最小值和最大值中间出一个随机数
        # computer = int((min_num + max_num)/2)
        computer = random.randint(min_num, max_num)
        # 判断  15  16
        if computer < we:
            # print("电脑2猜小了")
            # min_num = computer
            pass
        elif we < computer:
            # print("电脑2猜大了")
            # max_num = computer
            pass
        elif we == computer:
            print("天选之脑3")
            break
        # print("电脑猜的是%d"%computer)

    print("电脑3一共猜了%d局"%(i+1))
    com3_score.append(i+1)

print(com1_score)
print(com2_score)
print(com3_score)

# 数据分析
# 最大值
com1_max = 0
for i in com1_score:
    if i > com1_max:
        com1_max = i
print(com1_max)





# 最小值



# 平均值



# 出现次数最多的值









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值