diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..99d961e6 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,183 @@ "\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": 146, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}" + ] + }, + "execution_count": 162, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory = {}\n", + "key1= [input(\"enter a product\")]\n", + "inventory[\"t-shirt\"]= int(input(\"enter a value\"))\n", + "key2= [input(\"enter a product\")]\n", + "inventory[\"mug\"]= int(input(\"enter a value\"))\n", + "key3= [input(\"enter a product\")]\n", + "inventory[\"hat\"]= int(input(\"enter a value\"))\n", + "key3= [input(\"enter a product\")]\n", + "inventory[\"book\"]= int(input(\"enter a value\"))\n", + "key3= [input(\"enter a product\")]\n", + "inventory[\"keychain\"]= int(input(\"enter a value\"))\n", + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders =set()\n", + "product1= (input(\"enter a product\"))\n", + "customer_orders.add(product1)\n", + "product2= (input(\"enter a product\"))\n", + "customer_orders.add(product2)\n", + "product3= (input(\"enter a product\"))\n", + "customer_orders.add(product3)\n", + "customer_orders\n" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "Total_products_ordered = len(customer_orders)\n", + "print(Total_products_ordered)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0 %\n" + ] + } + ], + "source": [ + "percentage_ordered = (len(customer_orders) /len(products))*100\n", + "print(percentage_ordered, \"%\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 60)\n" + ] + } + ], + "source": [ + "order_status = (3, 60)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 0, 'mug': 1, 'hat': 2, 'book': 3, 'keychain': 4}\n" + ] + } + ], + "source": [ + "inventory[\"t-shirt\"]-=1\n", + "inventory[\"mug\"]-=1\n", + "inventory[\"hat\"]-=1\n", + "inventory[\"book\"]-=1\n", + "inventory[\"keychain\"]-=1\n", + "print(inventory)\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "print(inventory[\"t-shirt\"])\n", + "print(inventory[\"mug\"])\n", + "print(inventory[\"hat\"])\n", + "print(inventory[\"book\"])\n", + "print(inventory[\"keychain\"])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +240,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,