student.py 650 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. class Student(object):
  4. def __init__(self, name, score):
  5. self.name = name
  6. self.score = score
  7. def print_score(self):
  8. print('%s: %s' % (self.name, self.score))
  9. def get_grade(self):
  10. if self.score >= 90:
  11. return 'A'
  12. elif self.score >= 60:
  13. return 'B'
  14. else:
  15. return 'C'
  16. bart = Student('Bart Simpson', 59)
  17. lisa = Student('Lisa Simpson', 87)
  18. print('bart.name =', bart.name)
  19. print('bart.score =', bart.score)
  20. bart.print_score()
  21. print('grade of Bart:', bart.get_grade())
  22. print('grade of Lisa:', lisa.get_grade())