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个空格分开,会显示星座名和星座符号。
时间: 2023-06-24 09:04:53 浏览: 397
根据出生年月可做的星座测试
4星 · 用户满意度95%
以下是Python的代码实现:
```python
year, month, day = map(int, input().split())
if month == 1 and day <= 20 or month == 12 and day >= 23:
name = "摩羯座"
symbol = chr(9809)
elif month == 2 and day <= 19 or month == 1 and day >= 21:
name = "水瓶座"
symbol = chr(9810)
elif month == 3 and day <= 20 or month == 2 and day >= 20:
name = "双鱼座"
symbol = chr(9811)
elif month == 4 and day <= 20 or month == 3 and day >= 21:
name = "白羊座"
symbol = chr(9800)
elif month == 5 and day <= 21 or month == 4 and day >= 21:
name = "金牛座"
symbol = chr(9801)
elif month == 6 and day <= 21 or month == 5 and day >= 22:
name = "双子座"
symbol = chr(9802)
elif month == 7 and day <= 22 or month == 6 and day >= 22:
name = "巨蟹座"
symbol = chr(9803)
elif month == 8 and day <= 23 or month == 7 and day >= 23:
name = "狮子座"
symbol = chr(9804)
elif month == 9 and day <= 23 or month == 8 and day >= 24:
name = "处女座"
symbol = chr(9805)
elif month == 10 and day <= 23 or month == 9 and day >= 24:
name = "天秤座"
symbol = chr(9806)
elif month == 11 and day <= 22 or month == 10 and day >= 24:
name = "天蝎座"
symbol = chr(9807)
elif month == 12 and day <= 22 or month == 11 and day >= 23:
name = "射手座"
symbol = chr(9808)
print(name, symbol)
```
代码逻辑比较简单,根据输入的年月日计算出对应的星座名称和符号,并输出。注意要使用 `chr()` 函数将unicode编码转换为对应的符号。
阅读全文