18位身份证中数字包含如下信息: (1)前1、2位数字表示:所在省份的代码; (2)第3、4位数字表示:所在城市的代码; (3)第5、6位数字表示:所在区县的代码; (4)第7~14位数字表示:
身份证号码,然后根据上述规则输出对应的信息。
解析:
1. 输入一个18位的身份证号码
2. 根据规则提取相应的信息
3. 输出提取的信息
代码:
```python
def get_id_info(id_number):
if len(id_number) != 18:
return "请输入正确的18位身份证号码"
province_code = id_number[:2]
city_code = id_number[2:4]
district_code = id_number[4:6]
birth_date = id_number[6:14]
police_code = id_number[14:16]
gender = "男" if int(id_number[16]) % 2 == 1 else "女"
check_digit = id_number[17]
return {
"省份代码": province_code,
"城市代码": city_code,
"区县代码": district_code,
"出生年月日": birth_date,
"派出所代码": police_code,
"性别": gender,
"校检码": check_digit
}
id_number = input("请输入一个18位的身份证号码:")
info = get_id_info(id_number)
print(info)
```
解析:
1. 输入一个18位的身份证号码
2. 根据规则提取相应的信息
3. 输出提取的信息
代码:
```python
def get_id_info(id_number):
if len(id_number) != 18:
return "请输入正确的18位身份证号码"
province_code = id_number[:2]
city_code = id_number[2:4]
district_code = id_number[4:6]
birth_date = id_number[6:14]
police_code = id_number[14:16]
gender = "男" if int(id_number[16]) % 2 == 1 else "女"
check_digit = id_number[17]
return {
"省份代码": province_code,
"城市代码": city_code,
"区县代码": district_code,
"出生年月日": birth_date,
"派出所代码": police_code,
"性别": gender,
"校检码": check_digit
}
id_number = input("请输入一个18位的身份证号码:")
info = get_id_info(id_number)
print(info)
```