diff --git a/Lab_2_Flow_Control.ipynb b/Lab_2_Flow_Control.ipynb new file mode 100644 index 0000000..75a0edf --- /dev/null +++ b/Lab_2_Flow_Control.ipynb @@ -0,0 +1,105 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "source": [ + "#1 List\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "#2 Empty dict\n", + "inventory = {}\n", + "\n", + "#3 User input\n", + "for i in products:\n", + " quantity = int(input(f\"Enter the quantity available for {i}: \"))\n", + " inventory[i] = quantity\n", + "\n", + "#4 Empty set\n", + "customer_orders = set()\n", + "\n", + "#5 User input\n", + "while True:\n", + " order = input(\"What would you like to order: \")\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print('This is not in stock')\n", + " more_order = input('Do you want to add anything else to your order?').lower()\n", + " if more_order != 'yes':\n", + " break\n", + "\n", + "#6 Print\n", + "print(customer_orders)\n", + "\n", + "\n", + "#7 Calculate & statistics code & tuple\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "#8 Print number 7\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n", + "\n", + "#9 Update the inventory\n", + "for i in customer_orders:\n", + " inventory[i] -= 1\n", + "\n", + " print(inventory)\n", + "\n", + "#10 Print final code\n", + "for i, e in inventory.items():\n", + " print(i, ':', e)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "Sr7IbEKgeji7", + "outputId": "aff13df1-69ca-4e98-b488-cf46171b6e63" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter the quantity available for t-shirt: 2\n", + "Enter the quantity available for mug: 2\n", + "Enter the quantity available for hat: 2\n", + "Enter the quantity available for book: 2\n", + "Enter the quantity available for keychain: 2\n", + "What would you like to order: hat\n", + "Do you want to add anything else to your order?yes\n", + "What would you like to order: book\n", + "Do you want to add anything else to your order?no\n", + "{'hat', 'book'}\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40.0 %\n", + "{'t-shirt': 2, 'mug': 2, 'hat': 1, 'book': 2, 'keychain': 2}\n", + "{'t-shirt': 2, 'mug': 2, 'hat': 1, 'book': 1, 'keychain': 2}\n", + "t-shirt : 2\n", + "mug : 2\n", + "hat : 1\n", + "book : 1\n", + "keychain : 2\n" + ] + } + ] + } + ] +} \ No newline at end of file