0


python根据出生日期计算年龄的源码

将内容过程经常用的内容做个收藏,下面的内容段是关于python根据出生日期计算年龄的的内容。

#a function to find your age
def age():
print “Enter Your Date of Birth”
d=input(“Day:”)
m=input(“Month:”)
y=input(“Year:”)
#get the current time in tuple format
a=gmtime()
#difference in day
dd=a[2]-d
#difference in month
dm=a[1]-m
#difference in year
dy=a[0]-y
#checks if difference in day is negative
if dd<0:
dd=dd+30
dm=dm-1
#checks if difference in month is negative when difference in day is also negative
if dm<0:
dm=dm+12
dy=dy-1
#checks if difference in month is negative when difference in day is positive
if dm<0:
dm=dm+12
dy=dy-1
print “Your current age is %s Years %s Months & %s Days”%(dy,dm,dd)

age()

标签:

本文转载自: https://blog.csdn.net/stalk58/article/details/122368412
版权归原作者 stalk58 所有, 如有侵权,请联系我们删除。

“python根据出生日期计算年龄的源码”的评论:

还没有评论