python二级练习(4)

栏目: Python · 发布时间: 7年前

内容简介:python二级练习(4)

4. 用 Python 编写程序,输入一年份,判断该年份是否是闰年并输出结果。

注:凡符合下面两个条件之一的年份是闰年。 (1) 能被4整除但不能被100整除。 (2) 能被400整除。

#python 3.6
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579
#

year = int(input('请输入年份:'))
if year % 400 == 0:
    print(year, ' 是闰年。')
elif year % 4 == 0 and year % 100 != 0:
    print(year, ' 是闰年。')
else:
    print(year, ' 不是闰年。')

结果输出如下:

========== RESTART: D:/work/example/py_ex_004.py ==========

请输入年份:2018

2018  不是闰年。

>>> 

========== RESTART: D:/work/example/py_ex_004.py ==========

请输入年份:2100

2100  不是闰年。

>>> 

========== RESTART: D:/work/example/py_ex_004.py ==========

请输入年份:2016

2016  是闰年。

>>> 

========== RESTART: D:/work/example/py_ex_004.py ==========

请输入年份:2000

2000  是闰年。

>>> 

========== RESTART: D:/work/example/py_ex_004.py ==========

请输入年份:2200

2200  不是闰年。

>>> 

深入浅出Matplotlib

https://edu.csdn.net/course/detail/6859

深入浅出Numpy

http://edu.csdn.net/course/detail/6149

Python游戏开发入门


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Hacking Growth

Hacking Growth

Sean Ellis、Morgan Brown / Crown Business / 2017-4-25 / USD 29.00

The definitive playbook by the pioneers of Growth Hacking, one of the hottest business methodologies in Silicon Valley and beyond. It seems hard to believe today, but there was a time when Airbnb w......一起来看看 《Hacking Growth》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具