输入年和月份,输出该年该月份的天数
时间: 2024-05-08 10:18:10 浏览: 20
该月的天数输出如下:
```python
import calendar
year = int(input("请输入年份:"))
month = int(input("请输入月份:"))
days = calendar.monthrange(year, month)[1]
print(f"{year}年{month}月共有{days}天")
```
示例输出:
```
请输入年份:2021
请输入月份:7
2021年7月共有31天
```
相关问题
输入年和月份,输出该年该月份的天数C语言
好的,这是一个计算月份天数的问题,可以用 C 语言编写一个函数来实现。代码如下:
```
#include <stdio.h>
int getDaysOfMonth(int year, int month) {
int days = 0;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
days = 29;
} else {
days = 28;
}
break;
default:
printf("Invalid month\n");
break;
}
return days;
}
int main() {
int year, month;
printf("请输入年份和月份:\n");
scanf("%d%d", &year, &month);
int days = getDaysOfMonth(year, month);
printf("%d 年 %d 月份的天数为 %d\n", year, month, days);
return 0;
}
```
输入年份和月份,就可以计算出该年该月份的天数,例如:
输入:2000 2
输出:2000 年 2 月份的天数为 29
输入年份和月份,输出该月份天数
我可以回答这个问题。不同的月份有不同的天数,一般来说,1月、3月、5月、7月、8月、10月和12月有31天,4月、6月、9月和11月有30天,而2月份的天数则根据是否为闰年而有所不同。如果是闰年,2月份有29天,否则有28天。
相关推荐
![html](https://img-home.csdnimg.cn/images/20210720083451.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)