From 6909ad8d987903d30e6cd012ad15cf9944ff4392 Mon Sep 17 00:00:00 2001 From: Fiona Date: Sat, 7 Mar 2026 16:00:14 +0000 Subject: [PATCH 1/3] Adding Lab 3 Data flow control notebook --- Lab_2_Flow_Control.ipynb | 105 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Lab_2_Flow_Control.ipynb 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 From e1ec222c5f62bd82ddb606dbc4f1d945100b5346 Mon Sep 17 00:00:00 2001 From: Fiona Date: Sat, 7 Mar 2026 16:04:21 +0000 Subject: [PATCH 2/3] Remove wrong notebook --- Lab_2_Flow_Control.ipynb | 105 --------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 Lab_2_Flow_Control.ipynb diff --git a/Lab_2_Flow_Control.ipynb b/Lab_2_Flow_Control.ipynb deleted file mode 100644 index 75a0edf..0000000 --- a/Lab_2_Flow_Control.ipynb +++ /dev/null @@ -1,105 +0,0 @@ -{ - "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 From a2357aab86fee4839d05de9fed792b701bc2016e Mon Sep 17 00:00:00 2001 From: Fiona Date: Sat, 7 Mar 2026 16:06:18 +0000 Subject: [PATCH 3/3] Add Lab 3 Functions notebook --- Lab_3Functions.ipynb | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Lab_3Functions.ipynb diff --git a/Lab_3Functions.ipynb b/Lab_3Functions.ipynb new file mode 100644 index 0000000..4ec6255 --- /dev/null +++ b/Lab_3Functions.ipynb @@ -0,0 +1,131 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "JFRTYcGshY5v", + "outputId": "bcd53eb0-1bc5-4d47-8eab-e5c9b77d40b3" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "What is the quanitity for t-shirt ?3\n", + "What is the quanitity for mug ?3\n", + "What is the quanitity for hat ?3\n", + "What is the quanitity for book ?3\n", + "What is the quanitity for keychain ?3\n", + "What do you want to order? bot\n", + "Do you want to order anything else? yes\n", + "What do you want to order? book\n", + "Do you want to order anything else? yes\n", + "What do you want to order? hat\n", + "Do you want to order anything else? yes\n", + "What do you want to order? hat\n", + "Do you want to order anything else? no\n", + "Okay, that is it \n", + "....Order Stats....\n", + "Total products ordered.... 3\n", + "Percentage of products ordered.... 60.0\n", + "New updated inventory....\n", + "\n", + "t-shirt : 3\n", + "mug : 3\n", + "hat : 2\n", + "book : 2\n", + "keychain : 3\n" + ] + } + ], + "source": [ + "#0 Products list from first two labs\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "\n", + "#1 Define function\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for i in products:\n", + " quantity = int(input(f\"What is the quanitity for {i} ?\"))\n", + " inventory[i] = quantity\n", + " return inventory\n", + "\n", + "\n", + "#2 Define function\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " while True:\n", + " product = input(\"What do you want to order? \")\n", + " customer_orders.add(product)\n", + " another_order = input(\"Do you want to order anything else? \").lower()\n", + " if another_order != 'yes':\n", + " print('Okay, that is it ')\n", + " break\n", + " return customer_orders\n", + "\n", + "#3 Define function\n", + "def update_inventory(customer_orders, inventory):\n", + " for i in customer_orders:\n", + " if i in inventory:\n", + " inventory[i] -= 1\n", + "\n", + "\n", + "#4 Define function\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + " return total_products_ordered, percentage_ordered\n", + "\n", + "#5 Define function\n", + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(\"....Order Stats....\")\n", + " print(\"Total products ordered....\", total)\n", + " print(\"Percentage of products ordered....\", percentage)\n", + "\n", + "#6 Define function\n", + "def print_updated_inventory(inventory):\n", + " print(\"New updated inventory....\")\n", + " print()\n", + " for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)\n", + "\n", + "#7 Calling functions\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "update_inventory(customer_orders, inventory)\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "print_order_statistics(order_statistics)\n", + "print_updated_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "kYRQrDtQm4Gt" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file