print('姓名'+a)
print('年龄'+b)
return
a= input()
b= input()
PrintNameAge(a,b)
# -*- coding:utf-8 -*-#filename: test.py
import time
def action (number):
current = int(time.strftime("%Y"))
year = int(number[6:10])
print("你今年 {} 岁了".format(current - year))
action(input('输入你的身份证号\n'))
python输⼊出⽣⽇期和当前⽇期计算年龄_python根据出⽣⽇期计算年龄的代码
python根据出⽣⽇期计算年龄的代码,运⾏后会提醒⽤户输出出⽣的年⽉⽇,然后输出年龄,可以改写为⼀个通⽤函数
from time import *
#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()
¥
5.9
百度文库VIP限时优惠现在开通,立享6亿+VIP内容
立即获取
python输入出生日期和当前日期计算年龄_python根据出生日期计算年龄的代码
python输⼊出⽣⽇期和当前⽇期计算年龄_python根据出⽣⽇
期计算年龄的代码
python根据出⽣⽇期计算年龄的代码,运⾏后会提醒⽤户输出出⽣的年⽉⽇,然后输出年龄,可以改写为⼀个通⽤函数
from time import *
#a function to find your age
def age():
print "Enter Your Date of Birth"
第 1 页
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