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游戏开发入门


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

查看所有标签

猜你喜欢:

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

Advanced Web Metrics with Google Analytics

Advanced Web Metrics with Google Analytics

Brian Clifton / Sybex / 2008 / USD 39.99

Are you getting the most out of your website? Google insider and web metrics expert Brian Clifton reveals the information you need to get a true picture of your site's impact and stay competitive usin......一起来看看 《Advanced Web Metrics with Google Analytics》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具