标签:
#!/usr/bin/env python #manage the grade of student def init(date): date=[[],[],[],[],[]] return date def store(date): ID=raw_input(‘Please your ID:‘) name=raw_input(‘Please your name:‘) english=raw_input(‘Please your english:‘) math=raw_input(‘Please your math:‘) science=raw_input(‘Please your science:‘) date[0].append(ID) date[1].append(name) date[2].append(english) date[3].append(math) date[4].append(science) def printone(date,key): print "ID:%s,name:%s,english:%s,math:%s,science:%s" % (date[0][key],date[1][key],date[2][key],date[3][key],date[4][key]) def printbyid(date): number=-1 count=0 key=raw_input(‘Please enter your ID‘) for i in date[0]: if key==i: number=i break count+=1 if number==-1: print ‘None‘ else: printone(base,count) def printbyname(date): number=-1 count=0 countadd=[] key=raw_input(‘Please enter your name‘) for i in date[1]: if i==key: number=i countadd.append(count) count+=1 if number==-1: print ‘None‘ else: for j in countadd: printone(base,j) def alterbyid(date): number=-1 count=0 key=raw_input(‘Please enter your ID‘) for i in date[0]: if key==i: number=i break count+=1 if number==-1: print ‘None‘ else: date[1][count]=raw_input(‘Please your name:‘) date[2][count]=raw_input(‘Please your english:‘) date[3][count]=raw_input(‘Please your math:‘) date[4][count]=raw_input(‘Please your science:‘) def allprint(date): count=len(date[0]) if count==0: print‘None‘ else: for i in range(count): printone(base,i) def deletebyid(date): number=-1 count=0 key=raw_input(‘Please enter your ID‘) for i in date[0]: if key==i: number=i break count+=1 if number==-1: print ‘None‘ else: base[0].pop(count) base[1].pop(count) base[2].pop(count) base[3].pop(count) base[4].pop(count) base=[] base=init(base) print‘‘‘s:store pd:printbyid pe:printbyname ay:alterbyid ap:allprint dd:deletebyid other:quit ‘‘‘ while True: choose=raw_input(‘Please choose a function:‘) if choose==‘s‘: store(base) elif choose==‘pd‘: printbyid(base) elif choose==‘pe‘: printbyname(base) elif choose==‘ay‘: alterbyid(base) elif choose==‘ap‘: allprint(base) elif choose==‘dd‘: deletebyid(base) else: break
标签:
原文地址:http://www.cnblogs.com/knowanddo/p/4838763.html