python 课程设计题目_python练习:做一个简易的课程设计。Student Information Management System...

Student Information Management System

犹记得,大一时候,用C语言做这个课程设计,我特么一口老血都要喷出来,现在用Python做,反而有一种亲切感。

做一个menu菜单,在while循环里调用定义的insert(),delete(),modify(),sort(),display(),exit()等函数。

import pickle as p

import os

#Class Item

class Item:

def __init__(self,name,age,gender,Chinese,Math,English):

self.name = name

self.age = age

self.gender = gender

self.Math = Math

self.Chinese = Chinese

self.English = English

#The main menu of Student Information Management System

def menu():

print('********************')

print('1.Insert an item')

print('2.Delete an item')

print('3.Modify an item')

print('4.Display all items')

print('5.Sort all items')

print('6.Exit the program')

print('********************')

print('What do you waht to do?')

#Initialization of system,load the menber list

def begin():

global itemlist

#if os.path.exists('Information.txt') == True: #To judge whether the file exists

listfile = open('Information.txt','rb')

'''

if len(listfile.read())!= 0: # To judge whether the file is empty

listfile.seek(0)

itemlist = p.load(listfile)'''

listfile.close()

#Exitance of system,store the member list

def end():

global itemlist

listfile = open('Information.txt','w+')

p.dump(itemlist,listfile)

listfile.close()

#Insert an item into the member list

def insert():

name = input('Enter the name:')

age = int(input('Enter the age:'))

gender = input('Enter the gender:')

Chinese = float(input('Enter the Chinese score:'))

Math = float(input('Enter the Math score:'))

English = float(input('Enter the English score:'))

item = Item(name,age,gender,Chinese,Math,English)

global itemlist

itemlist.append(item)

print('Insert done!')

#Print an item

def output(item):

#itemlist = p.load(listfile)

print('%-10s%-5d%-7s%-12f%-12f%-12f%f' % (item.name,item.age,item.gender,item.Chinese,item.Math,item.English,(item.Chinese+item.Math+item.English)/3.0))

#Print all items

def display():

global itemlist

l = len(itemlist)

print('name age gender Chinese Math English AVG(Score)')

for i in range(0,l):

output(itemlist[i])

print('')

#Delete an item by name from member list

def delete():

name = input('Enter the name what you want to delete:')

global itemlist

l = len(itemlist)

for i in range(0,l):

if (itemlist[i].name == name):

itemlist.pop(i)

break

#Update an item

def update(item):

item.name = input('Enter the name:')

age = int(input('Enter the age:'))

gender = input('Enter the gender:')

Chinese = float(input('Enter the Chinese score:'))

Math = float(input('Enter the Math score:'))

English = float(input('Enter the English score:'))

#Update an item's information ny name

def modify():

name = input('Enter the name what you want to modify:')

global itemlist

l = len(itemlist)

for i in range(0,l):

if (itemlist[i].name == name):

update(itemlist[i])

print('Update done!')

#Sort all items by age

def sort():

global itemlist

itemlist.sort(key = lambda item:item.age)

display()

print('Sort done')

#Here are the Scripts

itemlist = [] #!!!!

begin()

while True:

menu()

choice = int (input())

if choice == 1:

insert()

elif choice == 2:

delete()

elif choice == 3:

modify()

elif choice == 4:

display()

elif choice == 5:

sort()

elif choice == 6:

exit()

else:

print('Your input is incorrect , system will exit.')

break

end()

print('Good Bye!')

代码可以直接运行。

1175569-20170604142215602-1211701120.png

1175569-20170604142231711-1148581552.png

不吹不黑的说,Python做这个更简单。代码清晰,冗赘量小。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值