输入1个整型数据(1-12),代表数字月份,输出其对应的英文月份名称
时间: 2023-05-26 11:05:08 浏览: 213
以下是Python代码实现:
```python
month = int(input("请输入数字月份:"))
if month == 1:
print("January")
elif month == 2:
print("February")
elif month == 3:
print("March")
elif month == 4:
print("April")
elif month == 5:
print("May")
elif month == 6:
print("June")
elif month == 7:
print("July")
elif month == 8:
print("August")
elif month == 9:
print("September")
elif month == 10:
print("October")
elif month == 11:
print("November")
elif month == 12:
print("December")
else:
print("输入的数字不在1-12之间")
```
输出示例:
```
请输入数字月份:6
June
```
```
请输入数字月份:13
输入的数字不在1-12之间
```
相关问题
由键盘任意输入1个整型数据(1-12),代表数字月份,输出其对应的英文月份名称。
以下是Python代码实现:
```
month = int(input("请输入数字月份(1-12):"))
if month == 1:
print("January")
elif month == 2:
print("February")
elif month == 3:
print("March")
elif month == 4:
print("April")
elif month == 5:
print("May")
elif month == 6:
print("June")
elif month == 7:
print("July")
elif month == 8:
print("August")
elif month == 9:
print("September")
elif month == 10:
print("October")
elif month == 11:
print("November")
elif month == 12:
print("December")
else:
print("输入有误,请输入1-12之间的数字。")
```
思路:通过if-elif语句判断输入的数字月份,然后输出对应的英文月份名称。如果输入不在1-12之间,则输出提示信息。
键盘任意输入1个整型数据(1-12),代表数 字月份,输出其对应的英文月份名称 用C语言
#include <stdio.h>
int main() {
int month;
printf("请输入一个整数(1-12)代表月份:");
scanf("%d", &month);
switch (month) {
case 1:
printf("January\n");
break;
case 2:
printf("February\n");
break;
case 3:
printf("March\n");
break;
case 4:
printf("April\n");
break;
case 5:
printf("May\n");
break;
case 6:
printf("June\n");
break;
case 7:
printf("July\n");
break;
case 8:
printf("August\n");
break;
case 9:
printf("September\n");
break;
case 10:
printf("October\n");
break;
case 11:
printf("November\n");
break;
case 12:
printf("December\n");
break;
default:
printf("输入有误,请输入一个整数(1-12)。\n");
break;
}
return 0;
}
阅读全文