Advertisement
Guest User

loh

a guest
Oct 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. class Person:
  2.     def __init__(self, name, age):
  3.         self.name = name
  4.         self.age = age
  5.  
  6.     def displayPerson(self):
  7.         print(self.name, '-', self.age)
  8.  
  9. class Student(Person):
  10.     def __init__(self, name, age, univer, grant):
  11.         super().__init__(name, age)
  12.         self.univer = univer
  13.         self.grant = grant
  14.  
  15.     def displayStudent(self):
  16.         if self.grant:
  17.             print(self.name, '-', self.age, 'studies at:', self.univer, ' and has grant')
  18.         else:
  19.             print(self.name, '-', self.age, 'studies at:', self.univer, " and hasn't grant")
  20.  
  21.     def setGrant(self, grant): # Установщик  гранта, есть он или нет
  22.         self.grant = grant
  23.  
  24. vlad = Person('Vlad', 26)
  25. Person.displayPerson(vlad) # Вызывай как хочешь
  26. vlad.displayPerson() # Вызывай как хочешь
  27.  
  28. igor = Student('Igor', 23, 'SPBGMTU', True)
  29. Student.displayStudent(igor) # Вызывай как хочешь
  30. igor.displayStudent() # Вызывай как хочешь
  31.  
  32. igor.setGrant(False) # Присваиваем grant = false
  33. igor.displayStudent()
  34.  
  35. #================================================================
  36.  
  37. class Mammal(object):
  38.     def __init__(self, mammalName):
  39.         # self.mammalName = mammalName # НИХУЯ НЕ ИЗМЕНИТСЯ
  40.         print(mammalName, 'is a warm-blooded animal.')
  41.  
  42.  
  43. class Dog(Mammal):
  44.     def __init__(self):
  45.         print('Dog has four legs.')
  46.         super().__init__('Dog')
  47.  
  48.  
  49. d1 = Dog()
  50.  
  51. #================================================================
  52.  
  53. class Mammal(object): # Mammal - млекопитающие
  54.     def __init__(self, mammalName):
  55.         print(mammalName, 'is a warm-blooded animal.')
  56.  
  57.  
  58. class Dog(Mammal):
  59.     def __init__(self, mammalName):
  60.         print('Dog has four legs.')
  61.         super().__init__(mammalName)
  62.  
  63. print('=' * 20)
  64. d1 = Dog("KEK")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement