from datetime import datetime #直接引用datetime.datetime |
def f(n): |
""" |
判断n是不是闰年 |
是,返回true |
否,返回folse |
""" |
g = False |
if (n / 400 = = 0 ) or ((n / 4 = = 0 ) and (n / 100 ! = 0 )): |
g = True |
return g |
def main(): |
""" |
主函数 |
""" |
x = print ( '继续运行程序请输入“是”,反之则“否”!' ) |
while x ! = "否" : |
if x = = '是' : |
try : |
a = input ( '请输入日期(****/**/**):' ) |
b = datetime.strptime(a, '%Y/%m/%d' ) |
print (b) |
n = b.year |
y = b.month |
r = b.day |
#月份字典 # 包含30天的月份集合 |
gg = { 1 : 31 , #_30_ = {4, 6, 9, 11} |
2 : 28 , #_31_ = {1, 3, 5, 7, 8, 10, 12} |
3 : 31 , |
4 : 30 , |
5 : 31 , |
6 : 30 , |
7 : 31 , |
8 : 31 , |
9 : 30 , |
10 : 31 , |
11 : 30 , |
12 : 31 } |
h = 0 |
h + = r |
for i in range ( 1 , y): |
h + = gg[i] |
# if i in _30_: |
# h += 30 |
# else: |
# h += 31 |
if y > 2 and f(n) and y > 2 : |
h + = 1 |
print ( '这是{}年第{}天!' . format (n,h)) |
except ValueError: |
print ( '请输入正确信息!' ) |