diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..5ea1246 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,13 +43,210 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "bc83c382-69fd-4127-90ae-acac2340992c", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "7e2a1b8e-7104-4039-ab93-1c3e2c50db6b", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter quantity available for: t-shirt 3\n", + "Enter quantity available for: mug 4\n", + "Enter quantity available for: hat 5\n", + "Enter quantity available for: book 6\n", + "Enter quantity available for: keychain 7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 3, 'mug': 4, 'hat': 5, 'book': 6, 'keychain': 7}\n" + ] + } + ], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(input(f\"Enter quantity available for: {product}\"))\n", + " inventory[product] = quantity \n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "bd673586-0367-4aa9-b958-6b8d93067487", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " order = input(\"Enter a product: \")\n", + " customer_orders.add(order)\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \")\n", + " if another != \"yes\":\n", + " break\n", + "\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "0a583cd6-c774-4c80-ac40-6009cf812385", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1\n", + " \n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "ea37dc2d-896c-4bb3-8884-8b32346f13f3", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products): \n", + " total_orders = len(customer_orders)\n", + " percentage_of_orders = len(customer_orders)/len(products)\n", + "\n", + " return total_orders, percentage_of_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "ad73879f-5acc-4d11-903f-fe4c96b272aa", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics): \n", + " print(\"Order statistics:\")\n", + " print(f\"Total products ordered: {total_orders}\")\n", + " print(f\"Percentage of unique products: {percentage_of_orders}\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "25a8197b-e9de-4f09-ad51-457946f6b1cc", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter quantity available for: t-shirt 4\n", + "Enter quantity available for: mug 4\n", + "Enter quantity available for: hat 4\n", + "Enter quantity available for: book 4\n", + "Enter quantity available for: keychain 4\n" + ] + }, + { + "data": { + "text/plain": [ + "{'t-shirt': 4, 'mug': 4, 'hat': 4, 'book': 4, 'keychain': 4}" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "001ed7df-b37c-4c47-b8d2-5d02d74ab101", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product: mug\n", + "Do you want to add another product? (yes/no): yes\n", + "Enter a product: hat\n", + "Do you want to add another product? (yes/no): no\n" + ] + }, + { + "data": { + "text/plain": [ + "{'hat', 'mug'}" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "590f6518-504b-4a4f-81b0-9a934261ce36", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n" + ] + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6acd0200-b879-443e-9f93-59322d62340e", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -61,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,