题目转载: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}')
运行结果:

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

被折叠的 条评论
为什么被折叠?



