"""
功能:按功能查询学生记录
作者:
日期:
"""
students = []

f = open('学生.txt')

for line in f:
    line = line.replace('\n', '')
    student = tuple(line.split(' '))
    students.append(student)

id = input('请输入待查学生的学号:')
found = False
for student in students:
    if (student[0]  == id):
        found = True
        for i in range(len(student)):
            print(student[i], end = ' ')
        break
if not found:
    print('学号为[{}]的学生没找到!'.format(id))

在这里插入图片描述

"""
功能:按功能查询学生记录
作者:
日期:
"""
students = []

f = open('学生.txt')

for line in f:
    line = line.replace('\n', '')
    student = tuple(line.split(' '))
    students.append(student)

name = input('请输入待查学生的姓名:')
found = False
for student in students:
    if (student[1] == name):
        found = True
        for i in range(len(student)):
            print(student[i], end= ' ')
        
if not found:
    print('姓名为[{}]的学生没找到!'.format(name))

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐