python_rag_system/lesson_11/home_task/task37.py
2025-10-23 09:57:04 +03:00

12 lines
618 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Инкапсуляция и property
# todo: Класс "Товар" (Защита от отрицательной цены)
# Создайте класс Product. У него есть свойства name (простая строка) и price.
# При установке цены проверяйте, что она не отрицательная.
# Если пытаются установить отрицательную цену, устанавливайте 0.
# Пример использования
product = Product("Book", 10)
print(product.price) # 10
product.price = -5
print(product.price) # 0