class Person(object):
def __init__(self, name = 'Bob', age = 25): #Значения по умолчанию заданы в конструкторе
self._name = name
self._age = age
@property
def name(self): #Свойство, возвращающее значение obj._name
return self._name
@property
def age(self): #Свойство, возвращающее значение obj._age
return self._age
def say_hi(self): #Рандомный метод
print(f'Hi, im {self._name}, im {self._age} yo')
def set_age(self, value): #Метод для изменения значения свойства obj._age
if value in range(1, 101):
self._age = value
else: raise RuntimeError('Bad Argument', f'Cant set age {value}, age must be in range [1, 100]')
Объяснение:
Второй класс попробуй реализовать сам
1)
def in_1(x, y):
if x >= 0 and y >= 0:
print("точка в 1 четверти")
else:
print("точка не в 1 четверти")
in_1(1, 1)
in_1(0, 0)
in_1(-1, 5)
2)
x = 5
y = 10
if x > y:
x_output = (x - y) / 2
y_output = x * y * 2
else:
x_output = x * y * 2
y_output = (x - y) / 2
x = x_output
y = y_output