SHARE
TWEET

Untitled

a guest Dec 8th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Student:
  2.     # The __init__ method accepts arguments
  3.  
  4.     def __init__(self, name, nationality):
  5.         self.__name = name
  6.         self.__nationality = nationality
  7.  
  8.     def set_name(self, name):
  9.         self.__name = name
  10.  
  11.     def set_nationality(self, nationality):
  12.         self.__nationality = nationality
  13.  
  14.  
  15.     def get_name(self):
  16.         return self.__name
  17.  
  18.     def get_nationality(self):
  19.         return self.__nationality
  20.  
  21.  
  22. class StudentInt(Student):
  23.  
  24.     def __init__(self, name, nationality):
  25.  
  26.         super().__init__(name, nationality)
  27.  
  28.  
  29. class StudentIntNK(StudentInt):
  30.  
  31.     def __init__(self, name, nationality, admission, welcomed):
  32.  
  33.         super().__init__(name, nationality)
  34.         self.__admission = admission
  35.         self.__welcomed = welcomed
  36.  
  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. def main():
  48.     # Get a list of Student objects.
  49.     students = make_list()
  50.  
  51.     # Display the data in the list.
  52.     print('Here is the list of students you entered:')
  53.     display_list(students)
  54.  
  55. def make_list():
  56.     # Create an empty list.
  57.     student_list = []
  58.  
  59.     # Add Student objects to the list.
  60.     n = int(input('How many students you want to add?: '))
  61.     print('Enter data for each student.')
  62.     for count in range(1, n):
  63.         # Get the students data.
  64.         print('Index number ' + str(count) + ':')
  65.         name = input('Enter name: ')
  66.         age = float(input('Enter age: '))
  67.         nationality = input('Enter Nationality: ')
  68.         welcomed = True
  69.         print
  70.         if nationality != 'PL':
  71.             student_int = Student.__init__(name, age, nationality)
  72.             student_list.append(student_int)
  73.         elif nationality == 'NK':
  74.             student_int_nk = Student.__init__(name, age, nationality, welcomed)
  75.             student_list.append(student_int_nk)
  76.         else:
  77.             student = Student.__init__(name, age, nationality)
  78.             student_list.append(student)
  79.  
  80.     # Return the list.
  81.     return student_list
  82.  
  83. # The display_list function accepts a list containing
  84. # Student objects as an argument and displays the
  85. # data stored in each object.
  86.  
  87. def display_list(student_list):
  88.     for data in student_list:
  89.         print(data.get_name())
  90.         print(data.get_age())
  91.         print(data.get_nationality())
  92.         print()
  93.  
  94. # Call the main function.
  95. if __name__ == '__main__':
  96.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top