Advertisement
kompilainenn

Untitled

Nov 17th, 2023
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 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.     def introduce(self):
  22.         print(self.create_str_intro())
  23.  
  24.  
  25. class DeveloperSchool:
  26.     def __init__(self, language):
  27.         self.language = language
  28.         self.counter = 0
  29.        
  30.     def to_teach(self, human):
  31.         self.counter += 1
  32.         return SoftwareDeveloper(human.name, human.gender, self.language)
  33.    
  34.     def get_how_many_times(self):
  35.         print(f'We already trained how to use {self.language} {self.counter} person(s)')
  36.        
  37. class DebugSchool():
  38.     def __init__(self, school):
  39.         self.school = school
  40.        
  41.     def to_teach(self, human):
  42.         return self.school.to_teach(human)
  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.  
  68. js_dev_school.get_how_many_times()
  69. cpp_dev_school.get_how_many_times()
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement