# 将需要的模块导入
import datetime
# 定义字典,用来存储每个星座的开始日期和结束日期
constellation_date_dict = {
'摩羯座': (datetime.date(datetime.date.today().year, 12, 22), datetime.date(datetime.date.today().year, 1, 19)),
'水瓶座': (datetime.date(datetime.date.today().year, 1, 20), datetime.date(datetime.date.today().year, 2, 18)),
'双鱼座': (datetime.date(datetime.date.today().year, 2, 19), datetime.date(datetime.date.today().year, 3, 20)),
'白羊座': (datetime.date(datetime.date.today().year, 3, 21), datetime.date(datetime.date.today().year, 4, 19)),
'金牛座': (datetime.date(datetime.date.today().year, 4, 20), datetime.date(datetime.date.today().year, 5, 20)),
'双子座': (datetime.date(datetime.date.today().year, 5, 21), datetime.date(datetime.date.today().year, 6, 21)),
'巨蟹座': (datetime.date(datetime.date.today().year, 6, 22), datetime.date(datetime.date.today().year, 7, 22)),
'狮子座': (datetime.date(datetime.date.today().year, 7, 23), datetime.date(datetime.date.today().year, 8, 22)),
'处女座': (datetime.date(datetime.date.today().year, 8, 23), datetime.date(datetime.date.today().year, 9, 22)),
'天秤座': (datetime.date(datetime.date.today().year, 9, 23), datetime.date(datetime.date.today().year, 10, 23)),
'天蝎座': (datetime.date(datetime.date.today().year, 10, 24), datetime.date(datetime.date.today().year, 11, 21)),
'射手座': (datetime.date(datetime.date.today().year, 11, 22), datetime.date(datetime.date.today().year, 12, 21))
}
# 定义函数,用来查询用户输入日期所属的星座
def get_constellation(date):
for constellation_name, date_range in constellation_date_dict.items():
if date_range[0] <= date <= date_range[1]:
return constellation_name
# 提示用户输入出生日期
input_date_str = input('请输入您的出生日期(yyyy/mm/dd):')
# 将用户输入的字符串转换为日期格式
input_date = datetime.datetime.strptime(input_date_str, '%Y/%m/%d').date()
# 调用函数,查询用户的星座
constellation = get_constellation(input_date)
# 输出查询结果
print('您的星座是:{}'.format(constellation))
星座嘎嘎噶
最新推荐文章于 2024-09-09 22:31:51 发布