用学号、姓名查询学生信息python

"""
功能:按功能查询学生记录
作者:
日期:
"""
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))

用学号、姓名查询学生信息python_第1张图片

"""
功能:按功能查询学生记录
作者:
日期:
"""
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))

用学号、姓名查询学生信息python_第2张图片

你可能感兴趣的:(python,开发语言,后端)