Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3657159
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2021-04-28 17:00:04

def reverse_list(lst):

    """

    准换列表的先后顺序

    :param lst: 原始列表

    :return: 新的列表

    """

    return [ele for ele in reversed(lst)]

low_list = ["01", "02", "03", "04", "05"]

# 设置比较小的数字的列表

high_list = ["06", "07", "08", "09", "10"]

# 设置比较大的数字的列表

N = 0

# 设置一个数字N来记录一共有多少期可以购买

n = 0

# 设置一个数字n来记录命中了多少期彩票

record_number = 1  

# 设置记录数据的一个判断值

list_data_number = []

# 设置一个空的列表来存储一天之中的连续挂掉的期数

dict_time_record = {}

# 设置一个空的字典来存储连挂掉的期数满足所列条件的时间节点

for k in range(1152):  

    # 循环遍历所有的数据点

    if k < 1150:

        new_result1 = reverse_list(new_response["result"]["data"])[k]  

        # 第一期数据

        new_result2 = reverse_list(new_response["result"]["data"])[k + 1]  

        # 第二期数据

        new_result3 = reverse_list(new_response["result"]["data"])[k + 2]  

        # 第三期数据

        data1 = new_result1['preDrawCode'].split(',')

        # 第一期数据

        data2 = new_result2['preDrawCode'].split(',')

        # 第二期数据

        data3 = new_result3['preDrawCode'].split(',')

        # 第三期数据

        for m in range(10):

            # 通过循环来判断是否满足购买的条件,并且实现一定的功能

            if m == 0:

                if data2[0] == data1[1]:  

                    # 如果相等就要结束循环

                    N += 1

                    # 可以购买的期数应该要自加一

                    if (data2[0] in low_list and data3[0] in low_list) or (data2[0] in high_list and data3[0] in high_list):

                        n += 1

                        # 命中的期数应该要自加一

                        # 如果命中了的话,本轮结束,开启下一轮

                        list_data_number.append(record_number)

                        if f"{record_number}" in dict_time_record.keys():

                            # 如果已经有了这个键,那么值添加时间点

dict_time_record[f"{record_number}"].append(new_result3['preDrawTime'][11:])

                        else:

                            # 如果没有这个键,那么添加一个键值对,值为一个列表,而且初始化为当前的时间

                            dict_time_record[f"{record_number}"] = [new_result3['preDrawTime'][11:]]

                        record_number = 1  

                        # 初始化下一轮的开始

                    else:

                        record_number += 1  

                        # 如果没有命中的话,次数就应该要自加一

                    break  

                    # 如果满足相等的条件就要结束循环

            elif m == 9:  

                # 与上面差不多的算法

                if data2[9] == data1[8]:  

                    # 如果相等

                    N += 1

                    if (data2[9] in low_list and data3[9] in low_list) or (data2[9] in high_list and data3[9] in high_list):

                        n += 1

                        list_data_number.append(record_number)

                        if f"{record_number}" in dict_time_record.keys():

dict_time_record[f"{record_number}"].append(new_result3['preDrawTime'][11:])

                        else:

                            dict_time_record[f"{record_number}"] = [new_result3['preDrawTime'][11:]]

                        record_number = 1

                    else:

                        record_number += 1

                    break

            else:  

                # 与上面差不多的算法

                if data2[m] == data1[m + 1] or data2[m] == data1[m - 1]:  

                    # 如果相等

                    N += 1

                    if (data2[m] in low_list and data3[m] in low_list) or (data2[m] in high_list and data3[m] in high_list):

                        n += 1

                        list_data_number.append(record_number)

                        if f"{record_number}" in dict_time_record.keys():

dict_time_record[f"{record_number}"].append(new_result3['preDrawTime'][11:])

                        else:

                            dict_time_record[f"{record_number}"] = [new_result3['preDrawTime'][11:]]

                        record_number = 1

                    else:

                        record_number += 1

                    break

print(f"日期:{new_response['result']['data'][0]['preDrawTime'][:10]},总的梯子数为{N},一共有{n}次命中,一共有{N - n}次挂了")

# 打印时间,以及,可以购买的期数,命中的期数,没有命中的期数

list_data_number.sort()

# 按照大小顺序来进行排序

dict_record = {}

# 设置空字典进行记录

for i in list_data_number:

    if f"{i}" in dict_record.keys():  # 判断是否已经有了这个数字?

        dict_record[f"{i}"] += 1

        # 货币代码如果有的话,那么就会自加一

    else:  # 如果没有的话,那么就会创建并且赋值等于 1

        dict_record[f"{i}"] = 1

        # 创建一个新的字典元素,然后进行赋值为 1

for j in dict_record.keys():

    if (int(j) >= 6) and (int(j) < 15):

        # 实际的结果表明,我们需要的是大于等于6期的数据,而没有出现大于15的数据,因此有这样的一个关系式

        print(f"{j}次才中奖的次数为{dict_record[j]}")

        # 打印相关信息

        print(dict_time_record[j])

        str0 = ""

        for letter in dict_time_record[j]:

            str0 += letter

            str0 += ", "

        print(str0)

        # 打印相关信息

阅读(1115) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~