Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.7 kB
0
Indexable
Never
class Person:

    def __init__(self, name, surname, age):
        self.name = name
        self.surname = surname
        self.age = age
        # uzupełnianie ma być z klawiatury

    @property
    def name(self):
        return self.__dict__["name"]

    @property
    def surname(self):
        return self.__dict__["surname"]

    @property
    def age(self):
        return self.__dict__["age"]

    @name.setter
    def name(self, value):
        if isinstance(value, str) and len(value) >= 3:
            self.__dict__["name"] = value
        else:
            self.__dict__["name"] = "Default"

    @surname.setter
    def surname(self, value):
        if isinstance(value, str) and len(value) >= 3:
            self.__dict__["surname"] = value
        else:
            self.__dict__["surname"] = "Default"

    @age.setter
    def age(self, value):
        if isinstance(value, int) and 0 <= value <= 130:
            self.__dict__["age"] = value
        else:
            self.__dict__["age"] = "Default"

    def __str__(self):
        return f"Name: {self.name}, \nSurname: {self.surname}, \nAge: {self.age}"


class Student(Person):

    def __init__(self, name, surname, age, field_of_study, kwargs):
        super().__init__(name, surname, age)
        self.field_of_study = field_of_study
        for key, value in kwargs.items():
            setattr(self, key, value)


class Employee(Person):

    def __init__(self, name, surname, age, job_title, skills):
        super().__init__(name, surname, age)
        self.job_title = job_title
        self.skills = skills


if __name__ == "__main__":

    p = input("pracownik czy student (p/s): ")

    if p == "p":
        while True:
            person = Employee("name", "surname", 1, "job_title", ["skills"])
            person.name = input("Imie: ")
            person.surname = input("Nazwisko: ")
            person.age = input("Wiek: ")
            person.job_title = input("Stanowisko: ")
            person.skills = input("Podaj umiejetnosci oddzielone spacja: ")
            user_skills = skills.split()
            print(str(person))

    elif p == "s":
        while True:
            person = Student()
            name = input("Imie: ")
            surname = input("Nazwisko: ")
            age = input("Wiek: ")
            field_of_study = input("Studia: ")

    else:
        print("wybierz poprawna opcje")

    # student_book = {"math": 1, "IT": 2, "IDK": 3}
    # student1 = Student("name", "surname", "age",
    #                    "field_of_study", student_book)
    # print(student1)