您的位置:首页 > 编程语言 > Python开发

python 简单习题系列1

2014-06-01 23:05 246 查看
题目: 计算今年是不是闰年? 闰年的条件: 满足整除400,或者整除4而不能整除100.

#coding:utf-8
'''
check this year is a leap year or not
'''

import time

# get this year
this_year = time.localtime()[0]
#this_year = 2008 #you can test any year you want
print ('This year is: %s . ' % this_year)

# check this year if is a leap year, and print the check result.
if this_year%400 == 0 or this_year%4 == 0 and this_year%100 != 0:
print ('It is a leap year.')
else:
print ('It is not a leap year.')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: