/
sejeenn
/
python_basic
Обзор
Документация
Войти
/
sejeenn
/
python_basic
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Module24/06_magic/main.py
114 строк
2 KB
Eugene Vorontsov
Copy repo python basic
03 фев 2025, 20:23
03 фев 2025, 20:23
a8fce4a
Код
Авторство
О чём код?
class Water: title = 'Вода' def __add__(self, other): if isinstance(other, Air): return Storm() elif isinstance(other, Fire): return Steam() elif isinstance(other, Earth): return Dirt() else: return None class Air: title = 'Воздух' def __add__(self, other): if isinstance(other, Fire): return Lighting() elif isinstance(other, Earth): return Dust() elif isinstance(other, Water): return Storm() else: return None class Fire: title = 'Огонь' def __add__(self, other): if isinstance(other, Earth): return Lava() elif isinstance(other, Water): return Steam() elif isinstance(other, Air): return Lighting() else: return None class Earth: title = 'Земля' def __add__(self, other): if isinstance(other, Fire): return Lava() elif isinstance(other, Water): return Dirt() elif isinstance(other, Air): return Dust() else: return None class Lighting: answer = 'Молния' class Lava: answer = 'Лава' class Dirt: answer = 'Грязь' def __add__(self, other): if isinstance(other, Fire): return Brick() else: return None class Dust: answer = 'Пыль' def __add__(self, other): if isinstance(other, Fire): return Glass() else: return None class Storm: answer = 'Шторм' class Steam: answer = 'Пар' class Brick: answer = 'Кирпич' class Glass: answer = 'Стекло' earth = Earth() water = Water() fire = Fire() air = Air() result = earth + water result_1 = fire + air result_2 = earth + water + fire result_3 = earth + air + fire print('Складываем: {} + {}, получаем: {}'.format(fire.title, air.title, result_1.answer)) print('Складываем: {} + {}, получаем: {}'.format(earth.title, water.title, result.answer)) print('Складываем: {} + {} + {}, получаем: {}'.format(earth.title, water.title, fire.title, result_2.answer)) print('Складываем: {} + {} + {}, получаем: {}'.format(earth.title, air.title, fire.title, result_3.answer))