用Python开发学生管理系统_Python源码实例篇

用Python开发学生管理系统_Python源码实例篇

用Python开发学生管理系统_Python源码实例篇

学生信息管理程序:

      编写两个函数用于封装 录入学生信息 和 打印学生信 息的功能

        1) 

        def input_student():

            #此函数获取学生信息,并返回学生信息的字典的列表

            ....

        2. 

        def output_student(L):

            # 以表格形式再打印学生信息

            ...

      验证测试:

        L = input_studnet()

        output_student(L)

        print("再添加几个学生信息")

        L += input_student()

        print("添加学生后的学生信息如下:")

        output_student(L)


def output_student(L):

tmp ={}

p=0

for l in L:

for i in l:

if i not in tmp:

tmp[i] = len(str(l[i]))

else:

tmp[i] = tmp[i] if tmp[i] > len(str(l[i])) else len(str(l[i]))

tmp['name'] = tmp['name']  if tmp['name'] > len('name') else len('name')

tmp['age'] = tmp['age']  if tmp['age'] > len('age') else len('age')

tmp['score'] = tmp['score']  if tmp['score'] > len('score') else len('score')

s1=''

for i in tmp:

s1 += '+'+('-'*(tmp[i]+2))

s1 += '+'

print(s1)

s2 = ''

for i in tmp:

s2 += '|'+(i.center(tmp[i]+2))

s2 += '|'

print(s2)

print(s1)

for l in L:

s3=''

for i in l:

s3 += '|'+(str(l[i]).center(tmp[i]+2))

s3+='|'

print(s3)

print(s1)

L = input_student()

output_student(L)

print('再输入几个:')

L += input_student()

output_student(L)


input()

程序运行结果:

程序运行结果:

最后编辑于:2019/09/19作者: 牛逼PHP

发表评论