从键盘上输入某一年,请编写fun函数,判断是否为闰年
时间: 2024-02-11 17:06:10 浏览: 34
好的,以下是一个 Python 函数,可以判断输入的年份是否为闰年:
```python
def is_leap_year(year):
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
return True
else:
return False
```
使用方法如下:
```python
year = int(input("请输入一个年份:"))
if is_leap_year(year):
print(year, "是闰年")
else:
print(year, "不是闰年")
```
您只需要调用 `is_leap_year` 函数,并将要判断的年份作为参数传入即可。该函数会返回 `True` 表示是闰年,返回 `False` 表示不是闰年。
相关问题
Python从键盘输入某一年,请编写fun函数,其功能为判断该年是否为闰年
好的,我可以帮你编写这个函数。闰年是指公历年份中能被4整除但不能被100整除的年份,或者能被400整除的年份。下面是一个简单的 Python 代码实现:
```python
def is_leap_year(year):
"""判断是否为闰年"""
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
return True
else:
return False
```
该函数接受一个参数 year,判断该年是否为闰年,如果是则返回 True,否则返回 False。你可以在代码中调用这个函数,来判断某一年是否为闰年。
c语言编写函数fun判断某一年是否为闰年
下面是一个用C语言编写的判断某一年是否为闰年的函数:
```c
int isLeapYear(int year){
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
return 1; //是闰年
}else{
return 0; //不是闰年
}
}
```
函数接受一个年份作为参数,如果该年是闰年则返回1,否则返回0。判断闰年的规则是:能被4整除但不能被100整除,或者能被400整除的年份为闰年。