用python编程实现一个新生报到程序。可以实现如下功能:录入功能:至少能够同时录入学生姓名、学号、宿舍号及班级,并能检查是否重复录入
时间: 2024-03-03 20:49:28 浏览: 111
好的,以下是一个简单的新生报到程序的Python代码,实现了录入功能,并可以检查重复录入:
```python
students = [] # 存储学生信息的列表
while True:
print("欢迎使用新生报到系统!")
print("请选择操作:1. 录入新生信息 2. 显示已录入信息 3. 退出程序")
choice = input("请输入操作编号:")
if choice == "1": # 录入新生信息
name = input("请输入学生姓名:")
student_id = input("请输入学生学号:")
dorm_num = input("请输入学生宿舍号:")
class_num = input("请输入学生班级:")
# 检查是否已经录入该学生信息
for student in students:
if student["学号"] == student_id:
print("该学生信息已经录入,请勿重复录入!")
break
else:
# 将学生信息加入列表中
student_info = {"姓名": name, "学号": student_id, "宿舍号": dorm_num, "班级": class_num}
students.append(student_info)
print("学生信息录入成功!")
elif choice == "2": # 显示已录入信息
if len(students) == 0:
print("目前没有已录入信息!")
else:
print("已录入学生信息如下:")
for student in students:
print("姓名:{},学号:{},宿舍号:{},班级:{}".format(student["姓名"], student["学号"], student["宿舍号"], student["班级"]))
elif choice == "3": # 退出程序
print("感谢使用新生报到系统,再见!")
break
else:
print("输入有误,请重新输入!")
```
代码中,我们使用一个`students`列表来存储已录入的学生信息。在录入新生信息时,我们使用一个`for`循环遍历已录入的学生信息,检查是否已经录入该学生信息。如果已经录入,则输出提示信息,否则将学生信息加入`students`列表中。在显示已录入信息时,我们使用一个`for`循环遍历`students`列表,输出每个学生的信息。如果`students`列表为空,则输出提示信息。在退出程序时,我们使用`break`语句退出程序。
阅读全文
相关推荐


















