输入一个年份判断是否为闰年,若是闰年输出yes,
时间: 2023-05-21 22:05:13 浏览: 89
若不是闰年则输出no。
以下是代码示例:
```python
year = int(input("请输入一个年份:"))
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print("yes")
else:
print("no")
```
该代码的作用是判断输入的年份是否为闰年。如果输入的年份能被4整除且不能被100整除,或者能被400整除,则认为是闰年,输出“yes”,否则输出“no”。
相关问题
用Python实现 输入一个年份判断是否为闰年 是输出yes 不是输出no
以下是Python代码实现闰年判断:
```
year = int(input("请输入一个年份:"))
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print("yes")
else:
print("no")
```
你可以输入年份进行测试。
编写一个函数判断是否为输入数字为闰年,如果是输出yes
好的,以下是一个 Python 编写的判断闰年的函数:
```python
def is_leap_year(year):
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
return "yes"
else:
return "no"
```
你可以传入一个年份作为参数,函数将返回字符串 "yes" 或 "no",表示该年份是否为闰年。比如:
```python
>>> is_leap_year(2020)
'yes'
>>> is_leap_year(2021)
'no'
```
希望能够帮到你!