N5-5 国外有星相:摩羯座, 水瓶座, 双鱼座, 白羊座, 金牛座, 双子座, 巨蟹座, 狮子座, 处女座, 天秤座, 天蝎座, 射手座。出生在1月20日前(含)是摩羯座, 2月19日前是水瓶座, 后面3月21日,4月21日, 5月12日, 6月22日, 7月23日, 8月23日, 9月23日, 10月23日, 11月23日, 12月23日以此类推。unicode中的图形符号中有代表星座的符号,十进制表示的unicode编码按顺序为:9809 9810 9811 9800 9801...9808等。例如,chr(9809)可以得到对应的摩羯座符号♑。 请编写一个程序,键盘一行输入年月日,中间以1个空格分开,会显示星座名和星座符号。 例如,输入2000 1 1,则会显示: 摩羯座 ♑
时间: 2023-06-25 19:08:27 浏览: 305
以下是Python的代码实现:
```python
year, month, day = map(int, input().split())
# 计算出生日期对应的星座
if month == 1 and day <= 20 or month == 12 and day >= 23:
constellation = "摩羯座"
symbol = chr(9809)
elif month == 1 and day >= 21 or month == 2 and day <= 19:
constellation = "水瓶座"
symbol = chr(9810)
elif month == 2 and day >= 20 or month == 3 and day <= 20:
constellation = "双鱼座"
symbol = chr(9811)
elif month == 3 and day >= 21 or month == 4 and day <= 20:
constellation = "白羊座"
symbol = chr(9800)
elif month == 4 and day >= 21 or month == 5 and day <= 21:
constellation = "金牛座"
symbol = chr(9801)
elif month == 5 and day >= 22 or month == 6 and day <= 21:
constellation = "双子座"
symbol = chr(9802)
elif month == 6 and day >= 22 or month == 7 and day <= 22:
constellation = "巨蟹座"
symbol = chr(9803)
elif month == 7 and day >= 23 or month == 8 and day <= 23:
constellation = "狮子座"
symbol = chr(9804)
elif month == 8 and day >= 24 or month == 9 and day <= 23:
constellation = "处女座"
symbol = chr(9805)
elif month == 9 and day >= 24 or month == 10 and day <= 23:
constellation = "天秤座"
symbol = chr(9806)
elif month == 10 and day >= 24 or month == 11 and day <= 22:
constellation = "天蝎座"
symbol = chr(9807)
elif month == 11 and day >= 23 or month == 12 and day <= 22:
constellation = "射手座"
symbol = chr(9808)
# 输出结果
print(constellation, symbol)
```
输入格式为三个整数,分别代表出生年月日,中间以空格分开。程序首先将输入的年月日赋值给变量`year`、`month`、`day`。然后根据输入的月份和日期计算出对应的星座,并将星座名和星座符号分别赋值给变量`constellation`和`symbol`。最后输出结果即可。
阅读全文