Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. class Student:
  2. # The __init__ method accepts arguments
  3.  
  4. def __init__(self, name, age, nationality):
  5. self.__name = name
  6. self.__age = age
  7. self.__nationality = nationality
  8.  
  9. def set_name(self, name):
  10. self.__name = name
  11.  
  12. def set_nationality(self, nationality):
  13. self.__nationality = nationality
  14.  
  15. def get_name(self):
  16. return self.__name
  17.  
  18. def get_age(self):
  19. return self.__age
  20.  
  21. def get_nationality(self):
  22. return self.__nationality
  23.  
  24.  
  25. class StudentInt(Student):
  26.  
  27. def __init__(self, name, nationality):
  28. super().__init__(name, nationality)
  29.  
  30.  
  31. class StudentIntNK(StudentInt):
  32.  
  33. def __init__(self, name, nationality, admission, welcomed):
  34. super().__init__(name, nationality)
  35. self.__admission = admission
  36. self.__welcomed = welcomed
  37.  
  38. def set_nationality(self, nationality):
  39. self.__nationality = "NK"
  40.  
  41. def set_welcomed(self):
  42. self.__welcomed = "Not welcomed"
  43.  
  44. def get_welcomed(self):
  45. return self.__welcomed
  46.  
  47.  
  48. student_list = []
  49.  
  50. def make_list():
  51. # Create an empty list.
  52.  
  53. # Add Student objects to the list.
  54. n = int(input('How many students you want to add?: '))
  55. print('Enter data for each student.')
  56. for count in range(0, n):
  57. # Get the students data.
  58. print('Index number ' + str(count) + ':')
  59. name = input('Enter name: ')
  60. age = float(input('Enter age: '))
  61. nationality = input('Enter Nationality: ')
  62. welcomed = True
  63. if nationality != 'PL':
  64. s = Student(name, age, nationality)
  65. student_list.append(s)
  66. elif nationality == 'NK':
  67. student_int_nk = Student.__init__(name, age, nationality, welcomed)
  68. student_list.append(student_int_nk)
  69. else:
  70. student = Student(name, age, nationality)
  71. student_list.append(student)
  72.  
  73. # Return the list.
  74. return student_list
  75.  
  76.  
  77. def display_list(student_list):
  78. for data in student_list:
  79. print(data.get_name())
  80. print(data.get_age())
  81. print(data.get_nationality())
  82. print()
  83.  
  84.  
  85. # The display_list function accepts a list containing
  86. # Student objects as an argument and displays the
  87. # data stored in each object.
  88.  
  89. def main():
  90. # Get a list of Student objects.
  91. students = make_list()
  92.  
  93. # Display the data in the list.
  94. print('Here is the list of students you entered:')
  95. display_list(students)
  96.  
  97.  
  98. # Call the main function.
  99. if __name__ == '__main__':
  100. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement