本题要求实现一个函数,可输出姓名、出生日期、性别、国籍和电话,并根据出生日期算出岁数(需要判断是否足岁)。函数可以对输入中的错误信息进行捕获。
函数接口定义:
def student(name,*birth,**information)
name参数是姓名,birth参数是出生年、月、日,information参数是性别、国籍和电话。
裁判测试程序样例:
name = input()
birth = input()
student(name,birth,sex='Female', nation='China', phone='123456789')
输入样例0:
在这里给出一组输入。例如:
zhangsan
1999 2 3
输出样例0:
在这里给出一组输出。例如:
name:zhangsan
birth:1999-2-3
age is 20
sex:Female
nation:China
phone:123456789
输入样例1:
在这里给出一组输入。例如:
zhangsan
1999-2-3
输出样例1:
在这里给出一组输出。例如:
name:zhangsan
The interval in the input 'birth' is a space
import datetime
def student(name,*birth,**information):
s=birth[0]
if ' ' not in s:
print("name:"+name)
print("The interval in the input 'birth' is a space")
else:
s=list(map(int,s.split()))
today=datetime.date.today()
age=today.year-s[0]-1+((today.month,today.day)>(s[1],s[2]))
print("name:"+name)
print("birth:{}-{}-{}".format(s[0], s[1], s[2]))
print("age is %d"%age)
print("sex:{sex}".format(**information))
print("nation:{nation}".format(**information))
print("phone:{phone}".format(**information))
name=input()
birth=input()
student(name,birth,sex='Female', nation='China', phone='123456789')