Advertisement
Paarzivall

Untitled

Apr 9th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. class Pupil(object):
  2.     ratings = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6]
  3.  
  4.     def __init__(self, name, surname):
  5.         self.name = name
  6.         self.surname = surname
  7.         self.marks = {}
  8.  
  9.     @property
  10.     def name(self):
  11.         return self.__name
  12.  
  13.     @name.setter
  14.     def name(self, value):
  15.         while True:
  16.             if isinstance(value, str) and str.isalpha(value) and len(value) >= 3:
  17.                 self.__name = value
  18.                 break
  19.             else:
  20.                 value = input("Podałeś niepoprawne imię, podaj nowe: ")
  21.  
  22.     @property
  23.     def surname(self):
  24.         return self.__surname
  25.  
  26.     @surname.setter
  27.     def surname(self, value):
  28.         while True:
  29.             if isinstance(value, str) and str.isalpha(value) and len(value) >= 3:
  30.                 self.__surname = value
  31.                 break
  32.             else:
  33.                 value = input("Podałeś niepoprawne nazwisko, podaj nowe: ")
  34.  
  35.     def complete_marks(self):
  36.         while True:
  37.             subject = input("Podaj przedmiot:\t")
  38.             rating = float(input(f"Podaj ocene (dostępne oceny: {self.ratings}):\t"))
  39.             while True:
  40.                 if rating in self.ratings:
  41.                     self.marks[subject] = rating
  42.                     break
  43.                 else:
  44.                     rating = input(f"Podaj ocene (dostępne oceny: {self.ratings}):\t")
  45.             action = int(input("Dodać kolejny przedmiot (wpisz 1 jeżeli tak):\t"))
  46.             if action != 1:
  47.                 break
  48.  
  49.     def print_marks(self):
  50.         for i in self.marks:
  51.             print(f"{i}: \t{self.marks[i]}")
  52.  
  53.     def mean(self):
  54.         sum = 0
  55.         count = 0
  56.         for i in self.marks:
  57.             count +=1
  58.             sum += self.marks[i]
  59.         return sum / count
  60.  
  61.     def __str__(self):
  62.         return f"Imie: {self.__name}, Nazwisko: {self.__surname}, Średnia ocen:\t{self.mean()}"
  63.  
  64.  
  65. class Student(Pupil):
  66.     weights_range = (0, 1)
  67.  
  68.     def __init__(self, name, surname):
  69.         Pupil.__init__(self, name, surname)
  70.         self.weights = {}
  71.  
  72.     def print_weights(self):
  73.         for i in self.weights:
  74.             print(f"{i}: {self.weights[i]}")
  75.  
  76. if __name__ == '__main__':
  77.     name = input("Podaj imie:\t")
  78.     surname = input("Podaj nazwisko:\t")
  79.     pupil = Student(name, surname)
  80.     pupil.complete_marks()
  81.     pupil.print_marks()
  82.     print(pupil)
  83.     pupil.print_weights()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement