当前位置: 首页 > article >正文

【小六壬占卜代码】

小六壬占卜代码

    • 【代码逻辑】
    • 【使用方法】
    • 【ChatGPT 直接运行】
    • 【ChatGPT询问进阶】

【代码逻辑】

  1. 将阳历转换成阴历
  2. 将时间转换为时辰和数字
  3. 根据这些时间输出结果
import datetime
import lunarcalendar

# 第一个函数:阳历转换为阴历
def solar_to_lunar(year, month, day):
    # 假设你已经安装了 `lunarcalendar` 库来处理阳历到阴历的转换
    solar_date = datetime.date(year, month, day)
    lunar_date = lunarcalendar.SolarDate.from_date(solar_date).get_lunar()
    # 获取阴历年月日
    return f"{lunar_date.year}{lunar_date.month}{lunar_date.day}日", lunar_date.month, lunar_date.day

# 第二个函数:时间转换为时辰和数字
def time_to_chinese_hour(hour, minute):
    # 定义时辰与时间的对应关系
    chinese_hours = [
        ("子时", 23, 1),  # 23:00 - 00:59
        ("丑时", 1, 2),   # 01:00 - 02:59
        ("寅时", 3, 3),   # 03:00 - 04:59
        ("卯时", 5, 4),   # 05:00 - 06:59
        ("辰时", 7, 5),   # 07:00 - 08:59
        ("巳时", 9, 6),   # 09:00 - 10:59
        ("午时", 11, 7),  # 11:00 - 12:59
        ("未时", 13, 8),  # 13:00 - 14:59
        ("申时", 15, 9),  # 15:00 - 16:59
        ("酉时", 17, 10), # 17:00 - 18:59
        ("戌时", 19, 11), # 19:00 - 20:59
        ("亥时", 21, 12), # 21:00 - 22:59
    ]

    for chinese_hour, start_hour, number in chinese_hours:
        if start_hour <= hour < start_hour + 2:
            return f"{hour}:{minute:02d} 属于 {chinese_hour},对应的数字是 {number}", number
    
    # 如果时间在 23:00 - 00:59
    return f"{hour}:{minute:02d} 属于 子时,对应的数字是 1", 1

# 第三个函数:根据n1, n2, n3 获取元素
def get_elements(n1, n2, n3):
    elements = ["大安", "留连", "速喜", "赤口", "小吉", "空亡", "病符", "桃花", "天德"]

    # 从“大安”开始,获取对应的元素
    first_index = (n1 - 1) % len(elements)
    second_index = (n1 + n2 - 2) % len(elements)
    third_index = (n1 + n2 + n3 - 3) % len(elements)

    return elements[first_index], elements[second_index], elements[third_index]

# 综合函数:根据输入的阳历日期和时间获取最终结果
def get_result_from_solar_date(year, month, day, hour, minute):
    # 1. 获取阴历日期
    lunar_date_str, lunar_month, lunar_day = solar_to_lunar(year, month, day)
    print(f"阴历日期为: {lunar_date_str}")
    
    # 2. 获取时辰和对应的数字
    time_result, hour_number = time_to_chinese_hour(hour, minute)
    print(time_result)
    
    # 3. 使用提取出的阴历月份、日期和时辰数字,调用 get_elements
    result = get_elements(lunar_month, lunar_day, hour_number)
    
    return result

# 示例调用
year = 2024
month = 9
day = 24
hour = 19
minute = 42

# 获取结果
final_result = get_result_from_solar_date(year, month, day, hour, minute)
print("最终结果为:", final_result)

【使用方法】

  1. 可以直接复制到 ChatGPT中运行,prompt :“请你运行上面的代码,帮我预测 , 2024.9.22, 19:42 的最终输出” (修改阳历时间)
  2. 复制代码到 python 中运行,(需要安装对应的库),输入“year, month, day, hour, minute
  3. 复制代码到 python 中运行,(需要安装对应的库),使用下面的函数对阳历时间进行解析 输入示例:“2024.9.22, 19:42” (逗号是英文逗号,逗号后面有一个空格)
def parse_datetime(datetime_str):
    date_part, time_part = datetime_str.split(', ')
    year, month, day = map(int, date_part.split('.'))
    hour, minute = map(int, time_part.split(':'))
    return year, month, day, hour, minute

【ChatGPT 直接运行】

""
import datetime
import lunarcalendar

# 第一个函数:阳历转换为阴历
def solar_to_lunar(year, month, day):
    # 假设你已经安装了 `lunarcalendar` 库来处理阳历到阴历的转换
    solar_date = datetime.date(year, month, day)
    lunar_date = lunarcalendar.SolarDate.from_date(solar_date).get_lunar()
    # 获取阴历年月日
    return f"{lunar_date.year}{lunar_date.month}{lunar_date.day}日", lunar_date.month, lunar_date.day

# 第二个函数:时间转换为时辰和数字
def time_to_chinese_hour(hour, minute):
    # 定义时辰与时间的对应关系
    chinese_hours = [
        ("子时", 23, 1),  # 23:00 - 00:59
        ("丑时", 1, 2),   # 01:00 - 02:59
        ("寅时", 3, 3),   # 03:00 - 04:59
        ("卯时", 5, 4),   # 05:00 - 06:59
        ("辰时", 7, 5),   # 07:00 - 08:59
        ("巳时", 9, 6),   # 09:00 - 10:59
        ("午时", 11, 7),  # 11:00 - 12:59
        ("未时", 13, 8),  # 13:00 - 14:59
        ("申时", 15, 9),  # 15:00 - 16:59
        ("酉时", 17, 10), # 17:00 - 18:59
        ("戌时", 19, 11), # 19:00 - 20:59
        ("亥时", 21, 12), # 21:00 - 22:59
    ]

    for chinese_hour, start_hour, number in chinese_hours:
        if start_hour <= hour < start_hour + 2:
            return f"{hour}:{minute:02d} 属于 {chinese_hour},对应的数字是 {number}", number
    
    # 如果时间在 23:00 - 00:59
    return f"{hour}:{minute:02d} 属于 子时,对应的数字是 1", 1

# 第三个函数:根据n1, n2, n3 获取元素
def get_elements(n1, n2, n3):
    elements = ["大安", "留连", "速喜", "赤口", "小吉", "空亡", "病符", "桃花", "天德"]

    # 从“大安”开始,获取对应的元素
    first_index = (n1 - 1) % len(elements)
    second_index = (n1 + n2 - 2) % len(elements)
    third_index = (n1 + n2 + n3 - 3) % len(elements)

    return elements[first_index], elements[second_index], elements[third_index]

# 综合函数:根据输入的阳历日期和时间获取最终结果
def get_result_from_solar_date(year, month, day, hour, minute):
    # 1. 获取阴历日期
    lunar_date_str, lunar_month, lunar_day = solar_to_lunar(year, month, day)
    print(f"阴历日期为: {lunar_date_str}")
    
    # 2. 获取时辰和对应的数字
    time_result, hour_number = time_to_chinese_hour(hour, minute)
    print(time_result)
    
    # 3. 使用提取出的阴历月份、日期和时辰数字,调用 get_elements
    result = get_elements(lunar_month, lunar_day, hour_number)
    
    return result

# 示例调用
year = 2024
month = 9
day = 24
hour = 19
minute = 42

# 获取结果
final_result = get_result_from_solar_date(year, month, day, hour, minute)
print("最终结果为:", final_result)
"""
请你详细分析理解上面的代码。请你帮我运行上面的代码,帮我预测, ”2024.9.22, 19:42“ 的最终输出。请确保结果是准确的,不能出现失误。感谢你专业的帮助。

【ChatGPT询问进阶】

请你分析上面的输出。请你学习这个领域所有的相关知识。帮我分析[“大安”, “留连”, “速喜”, “赤口”, “小吉”, “空亡”, “病符”, “桃花”, “天德”]的详细含义。
请你分析上面代码的输出,并结合该领域,这些输出的详细含义帮我进行详细分析。
我要预测的事情是“ XXXXXXXX ”,请你结合前面代码的输出和该领域的专家知识,帮我分析这件事情。
感谢你专业的帮助。


http://www.kler.cn/news/316686.html

相关文章:

  • STM32的GPIO的八种工作模式
  • 计算机毕业设计 奖学金评定管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • 牛客周赛 Round 60(思维、逆元、组合数、概率DP)
  • 箭头与数字识别系统源码分享
  • STM32F407单片机编程入门(十六) DMA详解及ADC-DMA方式采集含源码
  • 『功能项目』主角属性值显示【75】
  • html+css+js网页设计 旅游 穷游10个页面
  • 【Qt笔记】QTabWidget控件详解
  • 828华为云征文 | 云服务器Flexus X实例,搭建MC我的世界服务器
  • 力扣773:滑动谜题
  • K8s Calico替换为Cilium,以及安装Cilium过程
  • 进阶SpringBoot之集合 Redis
  • html/css怎么禁用浏览器自动填写
  • 使用 Nginx 搭建 Webdav 服务
  • 安全通信网络等保
  • Android OpenGLES2.0开发(二):环境搭建
  • 付费电表系统的通用功能和应用过程参考模型(中)
  • GPT1-GPT3论文理解
  • 关于wordPress中的用户登录注册等问题
  • MySQL函数介绍--日期与时间函数(二)
  • react hooks--useMemo
  • linux文件IO 缓存,行缓存,三类读写函数,fprint,sprintf等
  • 计算机网络-小型综合网络的搭建涉及到无线路由交换安全
  • Qt C++,QByteArray读取一个超过2GB的文件,写一类封装一下
  • Windows 配置docker和ubuntu系统
  • css如何设置间距
  • 防火墙详解(一) 网络防火墙简介
  • 网络爬虫到底难在哪里?
  • 数据结构(十二)——栈(下)(面试题)
  • Informer模型复现项目实战