[Python] 纯文本查看 复制代码 def determine_zodiac_sign(birth_date):
month = birth_date.month
day = birth_date.day
if (month == 1 and day >= 20) or (month == 2 and day <= 18):
return "水瓶座"
elif (month == 2 and day >= 19) or (month == 3 and day <= 20):
return "双鱼座"
elif (month == 3 and day >= 21) or (month == 4 and day <= 19):
return "白羊座"
elif (month == 4 and day >= 20) or (month == 5 and day <= 20):
return "金牛座"
elif (month == 5 and day >= 21) or (month == 6 and day <= 21):
return "双子座"
elif (month == 6 and day >= 22) or (month == 7 and day <= 22):
return "巨蟹座"
elif (month == 7 and day >= 23) or (month == 8 and day <= 22):
return "狮子座"
elif (month == 8 and day >= 23) or (month == 9 and day <= 22):
return "处女座"
elif (month == 9 and day >= 23) or (month == 10 and day <= 23):
return "天秤座"
elif (month == 10 and day >= 24) or (month == 11 and day <= 22):
return "天蝎座"
elif (month == 11 and day >= 23) or (month == 12 and day <= 21):
return "射手座"
else:
return "摩羯座"
def personality_traits_and_advice(zodiac_sign):
traits_and_advice = {
"水瓶座": ("独立,理性,进取。建议:保持自己的独特性,勇敢追求理想。"),
"双鱼座": ("敏感,梦幻,有同情心。建议:学会保护自己,控制情绪,珍惜现实生活。"),
"白羊座": ("热情,冲动,勇敢。建议:学会耐心,考虑他人,谨慎决策。"),
"金牛座": ("稳重,务实,忠诚。建议:勇于尝试新事物,灵活变通,不要固步自封。"),
"双子座": ("聪明,好奇,多才多艺。建议:保持专注,坚持目标,避免过分分散注意力。"),
"巨蟹座": ("细腻,情感丰富,有家庭观念。建议:学会拥抱变化,勇于面对挑战,不要过于依赖他人。"),
"狮子座": ("自信,慷慨,领导力强。建议:尊重他人,学会合作,不要过于自我中心。"),
"处女座": ("谨慎,理性,追求完美。建议:接受自己和他人的缺点,学会放松,不要过于苛求完美。"),
"天秤座": ("和谐,美感,追求公正。建议:勇于表达自己的想法,学会做出决定,不要优柔寡断。"),
"天蝎座": ("深沉,热情,复杂。建议:学会信任他人,放下怨恨,追求内心的平静。"),
"射手座": ("乐观,热情,爱好自由。建议:保持耐心,避免冲动行事,认真对待生活。"),
"摩羯座": ("稳重,实际,有责任感。建议:放松心情,享受生活,不要过分追求物质成功。")
}
return traits_and_advice.get(zodiac_sign, "未知星座")
# 主程序
if __name__ == "__main__":
from datetime import datetime
while True:
try:
input_date = input("请输入生日 (YYYY-MM-DD):")
birth_date = datetime.strptime(input_date, "%Y-%m-%d")
break
except ValueError:
print("请输入正确的日期格式 (YYYY-MM-DD)!")
zodiac_sign = determine_zodiac_sign(birth_date)
traits_and_advice = personality_traits_and_advice(zodiac_sign)
print(f"您的星座是{zodiac_sign},性格特点及建议如下:\n{traits_and_advice}")
|