7-4 身份证号处理

7-4 身份证号处理

输出样例:

在这里给出相应的输出。例如:

复制代码
from datetime import datetime

def process_id_card(id_card):
    # 提取出生年月日
    year = id_card[6:10]
    month = id_card[10:12]
    day = id_card[12:14]
    
    # 计算年龄
    birth_year = int(year)
    current_year = 2022
    age = current_year - birth_year
    
    # 处理月份和日期的前导零
    formatted_month = month.zfill(2)
    formatted_day = day.zfill(2)
    
    # 确定性别
    gender_digit = int(id_card[16])
    gender = "男" if gender_digit % 2 == 1 else "女"
    
    # 输出结果
    print(f"你出生于{year}年{formatted_month}月{formatted_day}日")
    print(f"你今年{age}周岁")
    print(f"你的性别为{gender}")

# 获取输入
id_card = input().strip()
process_id_card(id_card)

你出生于1973年05月16日
你今年49周岁
你的性别为男
相关推荐
二狗哈6 小时前
Cesium快速入门22:fabric自定义着色器
运维·开发语言·前端·webgl·fabric·cesium·着色器
李星星BruceL6 小时前
Pytest第三章(参考指南1)
python·自动化·pytest
白狐_7986 小时前
计算机网络复习全书(详细整理)
开发语言·计算机网络·php
黑岚樱梦6 小时前
Linux系统编程
java·开发语言·前端
乌萨奇也要立志学C++6 小时前
【洛谷】贪心专题之推公式 用 “相邻元素交换” 推导最优规则
c++·算法
哎呀呦呵6 小时前
pytest基本使用
python·pytest
阿关@6 小时前
Vscode中Python无法将pip/pytest”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
vscode·python·pip
Kristen_YXQDN6 小时前
PyCharm 中 pytest 运行 python 测试文件报错:D:\Python_file\.venv\Scripts\python.exe: No module named pytest
运维·开发语言·python·pycharm·pytest
Low--Key6 小时前
pytest框架快速入门
python·自动化·pytest
IMPYLH6 小时前
Lua 的 Debug(调试) 模块
开发语言·笔记·python·单元测试·lua·fastapi