输入一个生日日期,输出其星座的C#程序,用switch
时间: 2024-05-01 14:18:32 浏览: 92
语言程序
好的,以下是输入生日日期,输出星座的Python例子程序:
```python
month = int(input("请输入你的出生月份:"))
day = int(input("请输入你的出生日期:"))
if month == 1 and day >= 20 or month == 2 and day <= 18:
print("水瓶座")
elif month == 2 and day >= 19 or month == 3 and day <= 20:
print("双鱼座")
elif month == 3 and day >= 21 or month == 4 and day <= 19:
print("白羊座")
elif month == 4 and day >= 20 or month == 5 and day <= 20:
print("金牛座")
elif month == 5 and day >= 21 or month == 6 and day <= 21:
print("双子座")
elif month == 6 and day >= 22 or month == 7 and day <= 22:
print("巨蟹座")
elif month == 7 and day >= 23 or month == 8 and day <= 22:
print("狮子座")
elif month == 8 and day >= 23 or month == 9 and day <= 22:
print("处女座")
elif month == 9 and day >= 23 or month == 10 and day <= 22:
print("天秤座")
elif month == 10 and day >= 23 or month == 11 and day <= 21:
print("天蝎座")
elif month == 11 and day >= 22 or month == 12 and day <= 21:
print("射手座")
else:
print("摩羯座")
```
解释一下,程序首先会让用户输入月份和日期。然后使用 if-elif-else 条件语句来判断用户输入的日期属于哪个星座,并输出其星座名称。具体来说,分别判断分别判断输入的日期在每个星座的起止日期范围内,如果在这个范围内则输出对应的星座名称。如果日期不在任何一个星座的范围内(比如2月30日),则输出摩羯座。
阅读全文