通讯录的录入与显示pta
时间: 2024-06-14 11:04:31 浏览: 6
以下是一个示例程序,用于录入通讯录记录并显示指定的记录:
```python
# 录入通讯录记录
def input_records(n):
records = []
for i in range(n):
name = input("请输入朋友的姓名:")
birthday = input("请输入朋友的出生日期:")
gender = input("请输入朋友的性别:")
phone = input("请输入朋友的固定电话号码:")
mobile = input("请输入朋友的移动电话号码:")
record = {
"姓名": name,
"出生日期": birthday,
"性别": gender,
"固定电话号码": phone,
"移动电话号码": mobile
}
records.append(record)
return records
# 显示指定的记录
def display_record(records, indices):
for index in indices:
if index < len(records):
record = records[index]
print("姓名:", record["姓名"])
print("出生日期:", record["出生日期"])
print("性别:", record["性别"])
print("固定电话号码:", record["固定电话号码"])
print("移动电话号码:", record["移动电话号码"])
print()
# 主程序
if __name__ == "__main__":
n = int(input("请输入要录入的通讯录记录数:"))
records = input_records(n)
k = int(input("请输入要查询的记录数:"))
indices = []
for i in range(k):
index = int(input("请输入要查询的记录编号:"))
indices.append(index)
display_record(records, indices)
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)