From 7cdf8994e79aefbcb22792728748b953d79d2f85 Mon Sep 17 00:00:00 2001 From: Maisa Mohamed Date: Fri, 18 Sep 2026 09:46:17 +0200 Subject: [PATCH] maisa firts lab --- lab-python-data-structures.ipynb | 227 +++++++++++++++++++++++++------ 1 file changed, 184 insertions(+), 43 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..b60380a3 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,55 +1,196 @@ { "cells": [ { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, + "cell_type": "code", + "execution_count": 230, + "id": "f52f71ae-9843-4621-a12a-b8716bd1f460", + "metadata": {}, + "outputs": [], "source": [ - "# Lab | Data Structures " + "products =[ \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 231, + "id": "7cf471a0-b707-4467-9028-840c86c3377b", "metadata": {}, + "outputs": [], + "source": [ + "inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "466b1cb7-52bb-4821-8e66-e85c81a7bd19", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 232, + "id": "b8b0c8a6-8d5a-4956-8eea-d496a6b4fbb8", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 9\n", + "Enter the quantity for mug: 8\n", + "Enter the quantity for hat: 7\n", + "Enter the quantity for book: 6\n", + "Enter the quantity for keychain: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 9, 'mug': 8, 'hat': 7, 'book': 6, 'keychain': 5}\n" + ] + } + ], "source": [ - "## Exercise: Managing Customer Orders\n", - "\n", - "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", - "\n", - "2. Create an empty dictionary called `inventory`.\n", - "\n", - "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", - "\n", - "4. Create an empty set called `customer_orders`.\n", - "\n", - "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", - "\n", - "6. Print the products in the `customer_orders` set.\n", - "\n", - "7. Calculate the following order statistics:\n", - " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", - " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", - " \n", - " Store these statistics in a tuple called `order_status`.\n", - "\n", - "8. Print the order statistics using the following format:\n", - " ```\n", - " Order Statistics:\n", - " Total Products Ordered: \n", - " Percentage of Products Ordered: % \n", - " ```\n", - "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", - "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + "for product in products:\n", + " quantity = int(input(\"Enter the quantity for {}:\".format(product)))\n", + " inventory[product] = quantity\n", + "print(inventory)" ] + }, + { + "cell_type": "code", + "execution_count": 234, + "id": "5834d5b1-2215-44c2-8ef5-dc1ae2e26133", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "please enter product 1 from these values \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" hat\n", + "please enter product 2 from these values \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" k\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "error\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "please enter product 2 from these values \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" book\n", + "please enter product 3 from these values \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "done\n", + "{'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "customer_orders=set()\n", + "product_sum=0\n", + "while product_sum<3:\n", + " product = input('please enter product {} from these values \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\"'.format(product_sum+1 ))\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " product_sum+=1\n", + " else :\n", + " print(\"error\")\n", + " \n", + " \n", + "print(\"done\") \n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 227, + "id": "025613d0-c3fa-49eb-ad31-4810404555eb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "35\n" + ] + } + ], + "source": [ + "Total_Products_Ordered=len(customer_orders)\n", + "print(Total_Products_Ordered)\n", + "quantity_of_products=sum(inventory.values())\n", + "print(quantity_of_products)" + ] + }, + { + "cell_type": "code", + "execution_count": 228, + "id": "1e2f3ba4-c5c4-441d-b678-ef87af10f9dc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1166.6666666666665\n" + ] + } + ], + "source": [ + "percentage_ordered=(quantity_of_products/Total_Products_Ordered)*100\n", + "print(percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 235, + "id": "5a1f9b83-c6ac-4a8c-9097-c326236745e7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "7\n", + "6\n", + "5\n", + "4\n", + "update inventory= {'t-shirt': 8, 'mug': 7, 'hat': 6, 'book': 5, 'keychain': 4}\n" + ] + } + ], + "source": [ + "for key in inventory:\n", + " inventory[key]=inventory[key]-1\n", + " print(inventory[key]) \n", + "print( \"update inventory= \",inventory) \n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f89e87f9-6ab4-4fba-9c5d-91fc3967ebae", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,9 +209,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 }