用Python13、编程实现一个新生报到程序。可以实现如下功能:录入功能:至少能够同时录入学生姓名、学号、宿舍号及班级,并能检查是否重复录入
时间: 2023-12-19 12:07:04 浏览: 56
好的,以下是一个简单的新生报到程序的Python代码:
```python
# 定义一个空字典用于存储学生信息
students = {}
# 录入学生信息
def add_student():
while True:
name = input("请输入学生姓名:")
student_id = input("请输入学生学号:")
dormitory = input("请输入学生宿舍号:")
class_name = input("请输入学生班级:")
# 检查是否重复录入
if student_id in students:
print("该学生已经录入,请勿重复录入!")
else:
students[student_id] = {"姓名": name, "宿舍号": dormitory, "班级": class_name}
print("录入成功!")
break
# 查询学生信息
def search_student():
student_id = input("请输入要查询的学生学号:")
if student_id in students:
print(f"学号为{student_id}的学生信息如下:")
print(f"姓名:{students[student_id]['姓名']}")
print(f"宿舍号:{students[student_id]['宿舍号']}")
print(f"班级:{students[student_id]['班级']}")
else:
print("该学生不存在!")
# 主程序
while True:
print("欢迎使用新生报到系统!")
print("1. 录入新生信息")
print("2. 查询学生信息")
print("3. 退出系统")
choice = input("请输入操作编号:")
if choice == "1":
add_student()
elif choice == "2":
search_student()
elif choice == "3":
print("感谢使用新生报到系统!")
break
else:
print("输入有误,请重新输入!")
```
以上代码中,程序使用一个字典来存储学生信息,键为学号,值为一个包含学生姓名、宿舍号和班级的字典。录入功能中,先判断输入的学号是否已经存在字典中,如果存在就提示重复录入,否则将学生信息添加到字典中。查询功能中,根据输入的学号从字典中查询学生信息并输出。主程序中,通过循环实现用户可以反复进行操作,直到用户选择退出系统为止。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)