import student
def main():
listOfst=list_st()
display(listOfst)
def list_st():
listOfst=[]
flag='Y'
while flag=='Y':
name=raw_input("亲输入名字:")
grade=float(input("请输入成绩"))
choice=raw_input("请输入(L or P)")
if choice.upper()=='L':
s=student.LevelSt(name, grade)
else:
s=student.PassSt(name,grade)
listOfst.append(s)
flag=raw_input("继续?(Y/N):")
return listOfst
def display(listOfst):
print("\n姓名 \t 等级")
listOfst.sort(key=lambda x:x.getName())
for each in listOfst:
each.show()
main()
---------------------------------------------------------------------------------------------------------------------------------
class Student:
def _init_(self, name='', grade=0):
self._name = name
self._grade = grade
def setName(self, name):
self._name = name
def setGrade(self, grade):
self._grade = grade
def getName(self):
return self._name
def show(self):
print("%s\t %s" % (self._name, self.calcLevcl()))
class LevelSt(Student):
def calcLevel(self):
if self ._grade>=90:
return 'A'
elif self._grade>=80:
return 'B'
elif self._grade>=70:
return 'C'
elif self._grade>=60:
return 'D'
else:
return 'E'
class PassSt(Student):
def calcLevel(self):
if self._grade>=60:
return '通过'
else:
return '不通过'