Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Student:
- # The __init__ method accepts arguments
- def __init__(self, name, nationality):
- self.__name = name
- self.__nationality = nationality
- def set_name(self, name):
- self.__name = name
- def set_nationality(self, nationality):
- self.__nationality = nationality
- def get_name(self):
- return self.__name
- def get_nationality(self):
- return self.__nationality
- class StudentInt(Student):
- def __init__(self, name, nationality):
- super().__init__(name, nationality)
- class StudentIntNK(StudentInt):
- def __init__(self, name, nationality, admission, welcomed):
- super().__init__(name, nationality)
- self.__admission = admission
- self.__welcomed = welcomed
- def set_nationality(self, nationality):
- self.__nationality = "NK"
- def set_welcomed(self):
- self.__welcomed = "Not welcomed"
- def get_welcomed(self):
- return self.__welcomed
- def main():
- # Get a list of Student objects.
- students = make_list()
- # Display the data in the list.
- print('Here is the list of students you entered:')
- display_list(students)
- def make_list():
- # Create an empty list.
- student_list = []
- # Add Student objects to the list.
- n = int(input('How many students you want to add?: '))
- print('Enter data for each student.')
- for count in range(1, n):
- # Get the students data.
- print('Index number ' + str(count) + ':')
- name = input('Enter name: ')
- age = float(input('Enter age: '))
- nationality = input('Enter Nationality: ')
- welcomed = True
- print
- if nationality != 'PL':
- student_int = Student.__init__(name, age, nationality)
- student_list.append(student_int)
- elif nationality == 'NK':
- student_int_nk = Student.__init__(name, age, nationality, welcomed)
- student_list.append(student_int_nk)
- else:
- student = Student.__init__(name, age, nationality)
- student_list.append(student)
- # Return the list.
- return student_list
- # The display_list function accepts a list containing
- # Student objects as an argument and displays the
- # data stored in each object.
- def display_list(student_list):
- for data in student_list:
- print(data.get_name())
- print(data.get_age())
- print(data.get_nationality())
- print()
- # Call the main function.
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement