日期转星座(上)

现有一用户选择指定的日期,需要我们将日期处理成对应的星座

  • 需要分析

    • 用户选择日期(date)
    • 将数据传入后台
    • 将日期转换成对应的星座
    • 将星座展示给用户
  • 要如何将日期变成对应星座

  • 需要理解到日期是如何对应星座的
    在这里插入图片描述
    从图中可以了解到每个星座都有对应时间区域
    所以我们就可以找出其中的规律

…编写中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
的输入和异常处理的处理 以下是一个Python Unicode转换星座图案的代码,同时在日期输入和异常处理方面进行了处理: ``` def convert_to_constellation(date_str): try: date = datetime.datetime.strptime(date_str, "%Y-%m-%d") month = date.month day = date.day if month == 1: if day <= 19: return '\u2650' # Capricorn else: return '\u2651' # Aquarius elif month == 2: if day <= 18: return '\u2651' # Aquarius else: return '\u2652' # Pisces elif month == 3: if day <= 20: return '\u2652' # Pisces else: return '\u2653' # Aries elif month == 4: if day <= 19: return '\u2653' # Aries else: return '\u2648' # Taurus elif month == 5: if day <= 20: return '\u2648' # Taurus else: return '\u2649' # Gemini elif month == 6: if day <= 20: return '\u2649' # Gemini else: return '\u264a' # Cancer elif month == 7: if day <= 22: return '\u264a' # Cancer else: return '\u264b' # Leo elif month == 8: if day <= 22: return '\u264b' # Leo else: return '\u264c' # Virgo elif month == 9: if day <= 22: return '\u264c' # Virgo else: return '\u264d' # Libra elif month == 10: if day <= 22: return '\u264d' # Libra else: return '\u264e' # Scorpio elif month == 11: if day <= 21: return '\u264e' # Scorpio else: return '\u264f' # Sagittarius elif month == 12: if day <= 21: return '\u264f' # Sagittarius else: return '\u2650' # Capricorn except ValueError: print("Invalid date format. Please enter a date in the format of 'YYYY-MM-DD'") ``` 使用时,可以将日期字符串传递给`convert_to_constellation()`函数,该函数将返回Unicode表示的对应星座图案。如果输入的日期格式不正确,则函数将返回一条错误消息。 例如,以下是一个使用该函数的示例: ``` >>> convert_to_constellation('1990-05-23') '♊' >>> convert_to_constellation('2000-06-30') '♋' >>> convert_to_constellation('2022-13-01') Invalid date format. Please enter a date in the format of 'YYYY-MM-DD' ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小羊Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值