diff --git a/python/src/main.py b/python/src/main.py index e37a77c..e76d7ef 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,7 +1,28 @@ -def summ(a: int, b: int) -> int: - return a + b +from pistol import Pistol if __name__ == "__main__": - print("Hello world") - print(summ(3, 4)) + #print("Hello world") + #print(summ(3, 4)) + + # Хосровян Александр Арменович 1/279 + print("Lab 1 on python:") + + pistol1 = Pistol(9, "Desert Eagler", ".357 Magnum") + pistol2 = Pistol(15, "...", "...") + + pistol2.set_model("Glock") + pistol1.set_model("Revolver") + + pistol1.set_magazine_capacity(6) + pistol2.set_caliber("9х19 Luger") + + print("Pistol 1") + print("Модель пистолета - {}".format(pistol1.get_model())) + print("Ёмкость магазина - {}".format(pistol1.get_magazine_capacity())) + print("Калибр - {}".format(pistol1.get_caliber())) + + print("Pistol 2") + print("Модель пистолета - {}".format(pistol2.get_model())) + print("Ёмкость магазина - {}".format(pistol2.get_magazine_capacity())) + print("Калибр - {}".format(pistol2.get_caliber())) \ No newline at end of file diff --git a/python/src/pistol.py b/python/src/pistol.py new file mode 100644 index 0000000..1665e34 --- /dev/null +++ b/python/src/pistol.py @@ -0,0 +1,27 @@ +class Pistol: + def __init__(self, magazine_capacity: int, model: str, caliber: str): + if magazine_capacity < 5 or magazine_capacity > 30: + raise ValueError("Invalid pistol magazine capacity") + self.magazine_capacity = magazine_capacity + self.model = model + self.caliber = caliber + + def set_magazine_capacity(self, magazine_capacity: int): + if magazine_capacity < 5 or magazine_capacity > 30: + raise ValueError("Invalid pistol magazine capacity") + self.magazine_capacity = magazine_capacity + + def set_model(self, model: str): + self.model = model + + def set_caliber(self, caliber: str): + self.caliber = caliber + + def get_magazine_capacity(self) -> int: + return self.magazine_capacity + + def get_model(self) -> str: + return self.model + + def get_caliber(self) -> str: + return self.caliber \ No newline at end of file