将内容过程经常用的内容做个收藏,下面的内容段是关于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)文章来源:https://www.toymoban.com/news/detail-417475.html
age()文章来源地址https://www.toymoban.com/news/detail-417475.html
到了这里,关于python根据出生日期计算年龄的源码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!