Advertisement
kompilainenn

Untitled

Nov 17th, 2023
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. class Human:
  2.     def __init__(self, name, gender):
  3.         self.name = name
  4.         self.gender = gender
  5.    
  6.     def create_str_intro(self):
  7.         return f'Hi! I\'m a {self.gender}, my name is {self.name}.'
  8.    
  9.     def introduce(self):
  10.         print(self.create_str_intro())
  11.  
  12.  
  13. class SoftwareDeveloper(Human):
  14.     def __init__(self, name, gender, language):
  15.         super().__init__(name, gender)
  16.         self.language = language
  17.  
  18.     def create_str_intro(self):
  19.         return super().create_str_intro() + f' I write {self.language}.'
  20.    
  21.  
  22. class DeveloperSchool:
  23.     def __init__(self, language):
  24.         self.language = language
  25.         self.counter = 0
  26.        
  27.     def to_teach(self, human):
  28.         self.counter += 1
  29.         return SoftwareDeveloper(human.name, human.gender, self.language)
  30.    
  31.     def get_how_many_times(self):
  32.         print(f'We already trained how to use {self.language} {self.counter} person(s)')
  33.        
  34. class DebugSchool():
  35.     def __init__(self, school):
  36.         self.school = school
  37.        
  38.     def to_teach(self, human):
  39.         return self.school.to_teach(human)
  40.    
  41.     def get_how_many_times(self):
  42.         self.school.get_how_many_times()
  43.    
  44. first = Human('Vasya', 'man')
  45. first.introduce()
  46. second = Human('Sveta', 'woman')
  47. second.introduce()
  48. third = Human('Mobile-1', 'helicopter')
  49. third.introduce()
  50.  
  51. js_dev_school = DeveloperSchool('JS')
  52. cpp_dev_school = DeveloperSchool('C++')
  53. py_dev_school = DeveloperSchool('Python')
  54.  
  55. first = js_dev_school.to_teach(first)
  56. first.introduce()
  57.  
  58. # second = js_dev_school.to_teach(second)
  59. # second.introduce()
  60. #
  61. # third = cpp_dev_school.to_teach(third)
  62. # third.introduce()
  63.  
  64. debug_school_python = DebugSchool(py_dev_school)
  65. first = debug_school_python.to_teach(first)
  66. first.introduce()
  67. debug_school_python.get_how_many_times()
  68.  
  69. # js_dev_school.get_how_many_times()
  70. # cpp_dev_school.get_how_many_times()
  71. # py_dev_school.get_how_many_times()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement