Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Pupil(object):
- ratings = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6]
- def __init__(self, name, surname):
- self.name = name
- self.surname = surname
- self.marks = {}
- @property
- def name(self):
- return self.__name
- @name.setter
- def name(self, value):
- while True:
- if isinstance(value, str) and str.isalpha(value) and len(value) >= 3:
- self.__name = value
- break
- else:
- value = input("Podałeś niepoprawne imię, podaj nowe: ")
- @property
- def surname(self):
- return self.__surname
- @surname.setter
- def surname(self, value):
- while True:
- if isinstance(value, str) and str.isalpha(value) and len(value) >= 3:
- self.__surname = value
- break
- else:
- value = input("Podałeś niepoprawne nazwisko, podaj nowe: ")
- def complete_marks(self):
- while True:
- subject = input("Podaj przedmiot:\t")
- rating = float(input(f"Podaj ocene (dostępne oceny: {self.ratings}):\t"))
- while True:
- if rating in self.ratings:
- self.marks[subject] = rating
- break
- else:
- rating = input(f"Podaj ocene (dostępne oceny: {self.ratings}):\t")
- action = int(input("Dodać kolejny przedmiot (wpisz 1 jeżeli tak):\t"))
- if action != 1:
- break
- def print_marks(self):
- for i in self.marks:
- print(f"{i}: \t{self.marks[i]}")
- def mean(self):
- sum = 0
- count = 0
- for i in self.marks:
- count +=1
- sum += self.marks[i]
- return sum / count
- def __str__(self):
- return f"Imie: {self.__name}, Nazwisko: {self.__surname}, Średnia ocen:\t{self.mean()}"
- class Student(Pupil):
- weights_range = (0, 1)
- def __init__(self, name, surname):
- Pupil.__init__(self, name, surname)
- self.weights = {}
- def print_weights(self):
- for i in self.weights:
- print(f"{i}: {self.weights[i]}")
- if __name__ == '__main__':
- name = input("Podaj imie:\t")
- surname = input("Podaj nazwisko:\t")
- pupil = Student(name, surname)
- pupil.complete_marks()
- pupil.print_marks()
- print(pupil)
- pupil.print_weights()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement