diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..4d39c6e6 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,239 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory={}\n", + "user_input_t_shirt=int(input(\"Enter quantity of t-shirts: \"))\n", + "user_input_mug=int(input(\"Enter quantity of mug: \"))\n", + "user_input_hat=int(input(\"Enter quantity of hat: \"))\n", + "user_input_book=int(input(\"Enter quantity of book: \"))\n", + "user_input_keychain=int(input(\"Enter quantity of keychain: \"))\n", + "inventory={\"t-shirt\":user_input_t_shirt, \"mug\":user_input_mug, \"hat\":user_input_hat, \"book\":user_input_book, \"keychain\":user_input_keychain}\n", + "inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter your preference from the product list: hat\n", + "Enter your preference from the product list: book\n", + "Enter your preference from the product list: mug\n" + ] + }, + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders={}\n", + "customer_preference_1=input(\"Enter your preference from the product list: \")\n", + "customer_preference_2=input(\"Enter your preference from the product list: \")\n", + "customer_preference_3=input(\"Enter your preference from the product list: \")\n", + "customer_orders={customer_preference_1, customer_preference_2, customer_preference_3}\n", + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_products_ordered=len(customer_orders)\n", + "total_products_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'inventory' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m total_products_available\u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlen\u001b[39m(inventory)\n\u001b[0;32m 2\u001b[0m percentage_ordered\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mround\u001b[39m((total_products_ordered\u001b[38;5;241m/\u001b[39mtotal_products_available)\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m100\u001b[39m)\n\u001b[0;32m 3\u001b[0m percentage_ordered\n", + "\u001b[1;31mNameError\u001b[0m: name 'inventory' is not defined" + ] + } + ], + "source": [ + "total_products_available= len(inventory)\n", + "percentage_ordered=round((total_products_ordered/total_products_available)*100)\n", + "percentage_ordered\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics: Total products ordered:3 Percentage of products ordered:15%\n" + ] + } + ], + "source": [ + "print(f\"Order Statistics: Total products ordered:{total_products_ordered} Percentage of products ordered:{percentage_ordered}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "quantity_subtracted = 1\n", + "inventory[\"t-shirt\"]-=1\n", + "inventory[\"mug\"]-=1\n", + "inventory[\"hat\"]-=1\n", + "inventory[\"book\"]-=1\n", + "inventory[\"keychain\"]-=1" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory[\"t-shirt\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory[\"mug\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory[\"hat\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory[\"book\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory[\"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +301,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,