diff --git a/Lab3.ipynb b/Lab3.ipynb new file mode 100644 index 0000000..5d2f06b --- /dev/null +++ b/Lab3.ipynb @@ -0,0 +1,223 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 21, + "id": "3f0b5581-eed4-4b04-bcb3-f441c186c024", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert quantity of mugg: 2\n", + "Insert quantity of shirt: 3\n" + ] + } + ], + "source": [ + "\n", + "def initialize_inventory(*products): # **args \n", + " inventory = {}\n", + "\n", + " index=0 \n", + " \n", + " \n", + " while index < len(products):\n", + " item = products[index]\n", + " inventory[item] = int(input(f\"Insert quantity of {item}: \"))\n", + " index += 1 \n", + " \n", + " return inventory\n", + "\n", + "x = initialize_inventory(\"mugg\", \"shirt\")" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "8a1989d4-169b-46f0-8229-dcd5c5c1a9c6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mugg': 2, 'shirt': 3}\n" + ] + } + ], + "source": [ + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "2d9d0928-75c0-4d23-9c62-4e637aba568f", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert order: cup\n", + "Do you want to continue yes/no: y\n", + "Insert order: glass\n", + "Do you want to continue yes/no: no\n" + ] + } + ], + "source": [ + "def get_customer_orders():\n", + " x=0\n", + " order= []\n", + " \n", + " while x ==0:\n", + " order.append(input(\"Insert order: \")) \n", + " q = input(\"Do you want to continue yes/no:\")\n", + " if q == \"no\":\n", + " x=1\n", + " return order\n", + "\n", + "\n", + "x= get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "287c46d1-382b-46a4-a0d9-21dc2fc2d9f1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['cup', 'glass']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "b22fb6fc-6195-4ff9-b0a8-b6337a8a7eed", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert the inventory for apple? Currently at 10: 8\n", + "Insert the inventory for banana? Currently at 5: 8\n", + "Insert the inventory for cherry? Currently at 0: 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'apple': 8, 'banana': 8, 'cherry': 3, 'orange': 3}\n" + ] + } + ], + "source": [ + "def update_inventory(*customer_orders, **inventory):\n", + " for order in customer_orders:\n", + " if order in inventory:\n", + " # Prompt user for the new inventory value\n", + " new_stock = int(input(f\"Insert the inventory for {order}? Currently at {inventory[order]}: \"))\n", + " inventory[order] = new_stock # Update the inventory\n", + " else:\n", + " print(f\"{order} is not in the inventory.\")\n", + "\n", + " # Returning inventory for verification, if needed\n", + " return inventory\n", + "\n", + "# Example usage\n", + "new_inventory = update_inventory('apple', 'banana', 'cherry', apple=10, banana=5, cherry=0, orange=3)\n", + "print(new_inventory)\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32af3e41-eadd-4d42-bbf2-414fe037dbdf", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(*customer_orders, **products):\n", + " # Count all products ordered, whether duplicates or not\n", + " total_products_ordered = len(customer_orders)\n", + " \n", + " # Create a set to find unique orders\n", + " unique_orders = set(customer_orders)\n", + " total_unique_orders = len(unique_orders)\n", + " \n", + " # Calculate the percentage of unique products ordered\n", + " total_available_products = len(products)\n", + " if total_available_products > 0:\n", + " percentage_of_unique_products_ordered = (total_unique_orders / total_available_products) * 100\n", + " else:\n", + " percentage_of_unique_products_ordered = 0 # Avoid division by zero\n", + "\n", + " return total_products_ordered, percentage_of_unique_products_ordered\n", + "\n", + "# Example usage\n", + "products_info = {'apple': True, 'banana': True, 'cherry': True, 'date': True}\n", + "total_products, unique_percentage = calculate_order_statistics('apple', 'banana', 'cherry', 'apple', **products_info)\n", + "\n", + "print(f\"Total Products Ordered: {total_products}\")\n", + "print(f\"Percentage of Unique Products Ordered: {unique_percentage:.2f}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b207e40d-5cb2-4ce8-9042-046245b2c710", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " # Assume order_statistics is a tuple with two values: (total_products_ordered, percentage_of_unique_products_ordered)\n", + " total_products_ordered = order_statistics[0]\n", + " percentage_of_unique_products_ordered = order_statistics[1]\n", + "\n", + " # Print the statistics in a readable format\n", + " print(f\"Total Products Ordered: {total_products_ordered}\")\n", + " print(f\"Percentage of Unique Products Ordered: {percentage_of_unique_products_ordered:.2f}%\")\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}