题目57:输入18位的身份证号码,求其生日。。

该代码段展示了如何从18位的中国身份证号码中提取出生月份和日期。通过输入身份证号码,程序能确定并输出对应的生日。代码首先获取第10到12位作为出生月份,第12到14位作为出生日期。如果月份或日期小于10,它会调整为两位数的格式。最后,用f-string打印出生日。

题目转载:http://python.wzms.com/s/1/33

题目描述:

输入18位的身份证号码,求其生日。

输入格式:

输入一个包含18的字符串。

输出格式:

输出相应的生日。


代码:

national_identification_number = input()
birth_month = national_identification_number[10: 12]
birth_day = national_identification_number[12: 14]
if int(birth_month) < 9:
    birth_month = national_identification_number[11]
if int(birth_day) < 9:
    birth_day = national_identification_number[13]
print(f'Birthday is {birth_month}/{birth_day}')

运行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值