Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 240 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,245 @@
"\n",
"3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")."
]
},
{
"cell_type": "markdown",
"id": "80adf3d6-6511-4311-b2cd-436b632e9087",
"metadata": {},
"source": [
"#1\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"#inventory\n",
"inventory={}\n",
"for product in products:\n",
" quantity=int(input(f\"quantity of {product}:\"))\n",
" inventory[product]=quantity\n",
"\n",
"print(inventory)\n",
"\n",
"#\n",
"customer_orders=set()\n",
"\n",
"#Customer order list\n",
"customer_orders.clear()\n",
"while len(customer_orders)<3:\n",
" customer_product=input(f\"available products are {products}:\")\n",
" if customer_product not in products or customer_product in customer_orders:\n",
" customer_product2=input(f\"product not available or already selected, please select a product out of {products}:\")\n",
" if customer_product2 in products and customer_product2 not in customer_orders:\n",
" customer_orders.add(customer_product2)\n",
" else:\n",
" customer_orders.add(customer_product)\n",
"\n",
"print(customer_orders)\n",
"\n",
"#Total Products Ordered: The total number of products in the customer_orders set.\n",
"number_orders=len(customer_orders)\n",
"ordered_products=f\"{int((number_orders/len(products))*100)}%\"\n",
"order_status=(number_orders, ordered_products)\n",
"print(order_status)\n",
"\n",
"print(f\"Order Statistics:\\nTotal Products Ordered: {number_orders}\\nPercentage of Products Ordered: {ordered_products}\")\n",
"\n",
"#inventory update\n",
"for order in customer_orders:\n",
" inventory[order]=inventory[order]-1\n",
"\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "bc405c2b-0bc9-4759-9300-e250d0a57375",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of t-shirt: 10\n",
"quantity of mug: 9\n",
"quantity of hat: 8\n",
"quantity of book: 7\n",
"quantity of keychain: 6\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 10, 'mug': 9, 'hat': 8, 'book': 7, 'keychain': 6}\n"
]
}
],
"source": [
"#2\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"#inventory\n",
"inventory={}\n",
"for product in products:\n",
" quantity=int(input(f\"quantity of {product}:\"))\n",
" inventory[product]=quantity\n",
"\n",
"print(inventory)\n",
"\n",
"#\n",
"customer_orders=set()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "bfc0fd32-c7f9-4b67-80c7-4af0793d5101",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: book\n",
"would you like to add more products to your basket? (yes/no) yes\n",
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: keychain\n",
"would you like to add more products to your basket? (yes/no) yes\n",
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: mug\n",
"would you like to add more products to your basket? (yes/no) no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'mug', 'keychain'}\n"
]
}
],
"source": [
"#Customer order list\n",
"#2.a-b\n",
"customer_orders.clear()\n",
"customer_product=input(f\"available products are {products}:\")\n",
"if customer_product not in products:\n",
" customer_product2=input(f\"product not available please select a product out of {products}:\")\n",
" if customer_product2 in products:\n",
" customer_orders.add(customer_product2)\n",
"else:\n",
" customer_orders.add(customer_product)\n",
"\n",
"#2.c-d\n",
"add_product=str(input(f\"would you like to add more products to your basket? (yes/no)\"))\n",
"add_product=add_product.lower().strip()\n",
"while add_product==\"yes\":\n",
" customer_product=input(f\"available products are {products}:\")\n",
" if customer_product not in products:\n",
" customer_product2=input(f\"product not available please select a product out of {products}:\")\n",
" if customer_product2 in products:\n",
" customer_orders.add(customer_product2)\n",
" else:\n",
" customer_orders.add(customer_product)\n",
" add_product=input(f\"would you like to add more products to your basket? (yes/no)\")\n",
" add_product=add_product.lower().strip()\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "05ca136b-61c0-426f-aec9-8dd9d9b32996",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3, '60%')\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60%\n",
"{'t-shirt': 10, 'mug': 8, 'hat': 8, 'book': 5, 'keychain': 5}\n"
]
}
],
"source": [
"#Total Products Ordered: The total number of products in the customer_orders set.\n",
"number_orders=len(customer_orders)\n",
"ordered_products=f\"{int((number_orders/len(products))*100)}%\"\n",
"order_status=(number_orders, ordered_products)\n",
"print(order_status)\n",
"\n",
"print(f\"Order Statistics:\\nTotal Products Ordered: {number_orders}\\nPercentage of Products Ordered: {ordered_products}\")\n",
"\n",
"#inventory update\n",
"CustOrderList=list(customer_orders)\n",
"for order in CustOrderList:\n",
" inventory[order]=inventory[order]-CustOrderList.count(order)\n",
"\n",
"print(inventory)"
]
},
{
"cell_type": "markdown",
"id": "6fa680a3-db72-4fa4-91de-4da541ca7d07",
"metadata": {},
"source": [
"#1\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={}\n",
"\n",
"#\n",
"for product in products:\n",
" quantity=int(input(f\"quantity of {product}:\"))\n",
" inventory[product]=quantity\n",
"##print(inventory)\n",
"\n",
"#\n",
"customer_orders=set()\n",
"\n",
"#\n",
"customer_orders.clear()\n",
"while len(customer_orders)<3:\n",
" customer_product=input(f\"available products are {products}:\")\n",
" if customer_product not in products or customer_product in customer_orders:\n",
" customer_product2=input(f\"product not available or already selected, please select a product out of {products}:\")\n",
" if customer_product2 in products and customer_product2 not in customer_orders:\n",
" customer_orders.add(customer_product2)\n",
" else:\n",
" customer_orders.add(customer_product)\n",
"print(customer_orders)\n",
"\n",
"#\n",
"print(customer_orders)\n",
"\n",
"#\n",
"#Total Products Ordered: The total number of products in the customer_orders set.\n",
"number_orders=len(customer_orders)\n",
"ordered_products=f\"{int((number_orders/len(products))*100)}%\"\n",
"order_status=(number_orders, ordered_products)\n",
"print(order_status)\n",
"\n",
"#\n",
"print(f\"Order Statistics:\\nTotal Products Ordered: {number_orders}\\nPercentage of Products Ordered: {ordered_products}\")\n",
"\n",
"print(inventory)\n",
"\n",
"#\n",
"for order in customer_orders:\n",
" inventory[order]=inventory[order]-1\n",
"#print(inventory)\n",
"\n",
"#10\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba34278d-6059-4786-a4ff-2938f74ab16f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -55,7 +294,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down