python根据出生日期计算年龄的代码,python出生日期计算,python根据出生日期
python根据出生日期计算年龄的代码,python出生日期计算,python根据出生日期
python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数
from time import *#a function to find your agedef 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()
相关内容
- python 定时执行指定的函数,python指定函数,python定时执
- python 冒泡排序,python冒泡,[Python]代码
- python scrapy 网络采集使用代理的方法,pythonscrapy,1.在S
- 使用libvirt抓取linux kvm虚拟机的缩略图,libvirtkvm,import
- 一组python用于验证数据的函数,一组python,这是一组py
- python设置进程的环境变量,python环境变量,import ospri
- python2.7自动创建虚拟机,python2.7虚拟机,# -*- coding
- 购物,,#!/usr/bin/e
- if elif else 使用,elifelse,1 #!/usr/bin
- sys.argv经典代码,sys.argv经典,import osimp
评论关闭