Advertisement
VssA

student

Oct 31st, 2023
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. class Person:
  2.     def __init__(self, name="", age=0):
  3.         self.name = name
  4.         self.age = age
  5.  
  6.     def info(self):
  7.         print(f"имя = {self.name}, возраст = {self.age}")
  8.  
  9.  
  10. class Student(Person):
  11.     def __init__(self, name="", age=0, average_grade=0.0):
  12.         super().__init__(name, age)
  13.         self.average_grade = average_grade
  14.  
  15.     def scholarship(self):
  16.         if 4.0 <= self.average_grade <= 5.0:
  17.             print(f"Студент {self.name} получает стипендию")
  18.         else:
  19.             print(f"Студент {self.name} не получает стипендию")
  20.  
  21.  
  22. if __name__ == "__main__":
  23.     student1 = Student('Иван Иванович', 20, 3.5)
  24.     student2 = Student('Иван Степанович', 21, 4.0)
  25.     student3 = Student('Иван Фомич', 22, 2.0)
  26.     student4 = Student('Иван Кузьмич', 23, 5.0)
  27.  
  28.     print(student1.scholarship())
  29.     print(student2.scholarship())
  30.     print(student3.scholarship())
  31.     print(student4.scholarship())
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement