Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лаб. 3 Python (Вариант 1)

.docx
Скачиваний:
1
Добавлен:
31.08.2024
Размер:
265.91 Кб
Скачать

class Product: def __init__(self, name, price): self.name = name self.price = price def __add__(self, other): if isinstance(other, int): return self.price + other elif isinstance(other, float): return self.price + other else: print("Ошибка сложения (сложение не произведено)!\n") return self.price def display_info(self): print(f"Товар: {self.name}\nЦена: {self.price}\n")

from Product import Product class DiscountedProduct(Product): def __init__(self, name, price, discount): super().__init__(name, price) self.discount = discount def reducing_price(self): self.price = self.price - (self.discount * self.price / 100) return round(self.price, 2) def display_info(self): print(f"Товар: {self.name}\nЦена со скидкой: {self.price}\nСкидка: {self.discount}\n")

from Product import Product class ProductBox(Product): def __init__(self, name, price, width, height, depth): super().__init__(name, price) self.width = width self.height = height self.depth = depth def get_quantity(self, boxWidth, boxHeight, boxDepth): quantity = (boxWidth // self.width) * (boxHeight // self.height) * (boxDepth // self.depth) return int(quantity)

import re from Product import Product from DiscountedProduct import DiscountedProduct from ProductBox import ProductBox print("---№1---") nameValue = "Хлопья" priceValue = 80 discountValue = 12.5 widthValue = 1200 heightValue = 1500 depthValue = 1400 widthBoxValue = 4400 heightBoxValue = 7000 depthBoxValue = 5000 productValue = Product(nameValue, priceValue) discountedProductValue = DiscountedProduct(nameValue, priceValue, discountValue) discountedProductValue.reducing_price() boxedProductValue = ProductBox(nameValue, priceValue, widthValue, heightValue, depthValue) quantityProductValue = boxedProductValue.get_quantity(widthBoxValue, heightBoxValue, depthBoxValue) productValue.display_info() discountedProductValue.display_info() print(f"Количество товара в коробке: {quantityProductValue}\n") productValue.price = productValue + "12" productValue.display_info() print("---№2---") symbols = "^[а-яА-ЯёЁ]+$" while True: nameProduct = input("Введите название товара: ") check = re.match(symbols, nameProduct) is not None if check == True: break else: print("Ошибка ввода!") while True: try: priceProduct = float(input("Введите цену товара: ")) if priceProduct < 0.1: print("Невозможная цена!") else: break except ValueError: print("Ошибка ввода!") while True: try: discountProduct = float(input("Введите размер скидки на товар (в процентах): ")) if discountProduct < 0 or discountProduct > 99: print("Невозможная скидка!") else: break except ValueError: print("Ошибка ввода!") while True: try: widthProduct = float(input("Введите ширину товара (в миллиметрах): ")) if widthProduct < 0.1: print("Невозможная ширина!") else: break except ValueError: print("Ошибка ввода!") while True: try: heightProduct = float(input("Введите высоту товара (в миллиметрах): ")) if heightProduct < 0.1: print("Невозможная высота!") else: break except ValueError: print("Ошибка ввода!") while True: try: depthProduct = float(input("Введите глубину товара (в миллиметрах): ")) if depthProduct < 0.1: print("Невозможная глубина!") else: break except ValueError: print("Ошибка ввода!") while True: try: widthBox = float(input("Введите ширину коробки (в миллиметрах): ")) if widthBox < 0.1: print("Невозможная ширина!") else: break except ValueError: print("Ошибка ввода!") while True: try: heightBox = float(input("Введите высоту коробки (в миллиметрах): ")) if heightBox < 0.1: print("Невозможная высота!") else: break except ValueError: print("Ошибка ввода!") while True: try: depthBox = float(input("Введите глубину коробки (в миллиметрах): ")) if depthBox < 0.1: print("Невозможная глубина!") else: break except ValueError: print("Ошибка ввода!") print("\n") productOne = Product(nameProduct, priceProduct) discountedProductOne = DiscountedProduct(nameProduct, priceProduct, discountProduct) discountedProductOne.reducing_price() boxedProductOne = ProductBox(nameProduct, priceProduct, widthProduct, heightProduct, depthProduct) quantityProductOne = boxedProductOne.get_quantity(widthBox, heightBox, depthBox) productOne.display_info() discountedProductOne.display_info() print(f"Количество товара в коробке: {quantityProductOne}")

Соседние файлы в предмете Программирование на Python