2. 编写程序,输入一个18位的身份证号码,从中提取出生日期,并以“某人于*年*月*日出生”的格式输出。
时间: 2023-08-19 22:04:10 浏览: 133
好的,我可以帮你编写这个程序。以下是 Python 代码实现:
```python
id_number = input("请输入18位身份证号码:")
birth_year = id_number[6:10]
birth_month = id_number[10:12]
birth_day = id_number[12:14]
print("某人于{}年{}月{}日出生".format(birth_year, birth_month, birth_day))
```
代码逻辑很简单,就是利用字符串的切片功能,从身份证号码中截取出生年月日,然后使用字符串格式化输出。注意,这里假设输入的身份证号码格式正确,如果输入错误的身份证号码,程序可能会出错。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)