diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..2b1a50a2 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,241 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "print(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n" + ] + } + ], + "source": [ + "inventory = {}\n", + "print(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 7, 'hat': 3, 'book': 8, 'keychain': 9}\n" + ] + } + ], + "source": [ + "inventory['t-shirt'] = int(input('Enter the quantity available for t-shirt: '))\n", + "inventory['mug'] = int(input('Enter the quantity available for mug: '))\n", + "inventory['hat'] = int(input('Enter the quantity available for hat: '))\n", + "inventory['book'] = int(input('Enter the quantity available for book: '))\n", + "inventory['keychain'] = int(input('Enter the quantity available for keychain: '))\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "book mug hat\n" + ] + } + ], + "source": [ + "product_1 = input('Enter the product 1: ')\n", + "product_2 = input('Enter the product 2: ')\n", + "product_3 = input('Enter the product 3:')\n", + "print(product_1, product_2, product_3)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'hat', 'mug'}\n" + ] + } + ], + "source": [ + "customer_orders.add(product_1)\n", + "customer_orders.add(product_2)\n", + "customer_orders.add(product_3)\n", + "print(customer_orders)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "percentage_of_products_ordered = (total_products_ordered / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_ordered, percentage_of_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 60.0 %\n" + ] + } + ], + "source": [ + "print('Order Statistics:')\n", + "print('Total products ordered:', order_status[0])\n", + "print('Percentage of products ordered:', order_status[1], '%')" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "inventory['t-shirt'] = inventory['t-shirt'] - 1\n", + "inventory['mug'] = inventory['mug'] - 1\n", + "inventory['hat'] = inventory['hat'] - 1\n", + "inventory['book'] = inventory['book'] - 1\n", + "inventory['keychain'] = inventory['keychain'] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 4, 'mug': 6, 'hat': 2, 'book': 7, 'keychain': 8}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 4\n", + "mug: 6\n", + "hat: 2\n", + "book: 7\n", + "keychain: 8\n" + ] + } + ], + "source": [ + "print('t-shirt' + ':', inventory['t-shirt'])\n", + "print('mug' + ':', inventory['mug'])\n", + "print('hat' + ':', inventory['hat'])\n", + "print('book' + ':', inventory['book'])\n", + "print('keychain' + ':', inventory['keychain'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +298,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4,