Skip to content

Lab done #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
173 changes: 170 additions & 3 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"\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",
"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",
Expand Down Expand Up @@ -50,11 +50,178 @@
"\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": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory: {'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 5, 'keychain': 2}\n",
"You added following products: {'mug', 'hat', 'book'}\n",
"Order Statistics: Total Products Ordered: 3,Percentage of Products Ordered: 60.0\n",
"Updated inventory: {'t-shirt': 2, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 2}\n"
]
}
],
"source": [
"products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n",
"\n",
"inventory = {} \n",
"\n",
"\n",
" \n",
"inventory['t-shirt'] = int(input('How many t-shirts do you have? '))\n",
"\n",
"\n",
"inventory['mug'] = int(input('How many mugs do you have? '))\n",
"\n",
"\n",
"inventory['hat'] = int(input('How many hats do you have? '))\n",
"\n",
"\n",
"inventory['book'] = int(input('How many books do you have? '))\n",
"\n",
"\n",
"inventory['keychain'] = int(input('How many keychains do you have? '))\n",
"\n",
"print (f'Inventory: {inventory}')\n",
"\n",
"#2\n",
"customer_orders = set()\n",
"orders1 = input(f'Please add your 1 product you want to order from those in the products list(t-shirt, mug, hat, book, keychain):')\n",
"customer_orders.add(orders1)\n",
"orders2 = input(f'Please add your 2 product you want to order from those in the products list(t-shirt, mug, hat, book, keychain):')\n",
"customer_orders.add(orders2)\n",
"orders3 = input(f'Please add your 3 product you want to order from those in the products list(t-shirt, mug, hat, book, keychain):')\n",
"customer_orders.add(orders3)\n",
"\n",
"print (f'You added following products: {customer_orders}')\n",
"\n",
"#3\n",
"total = len(customer_orders)\n",
"percentage = (total / len(products)) * 100\n",
"\n",
"order_status = (total, percentage)\n",
"\n",
"\n",
"print (f'Order Statistics: Total Products Ordered: {order_status[0]},Percentage of Products Ordered: {order_status[1]}') \n",
"\n",
"product_one = list(customer_orders)[0]\n",
"inventory[product_one] -= 1\n",
"product_two = list(customer_orders)[1]\n",
"inventory[product_two] -= 1\n",
"product_three = list(customer_orders)[2]\n",
"inventory[product_three] -= 1\n",
"\n",
"\n",
"\n",
"#for product in inventory\n",
"\n",
"#inventory['t-shirt'] = inventory['t-shirt'] -1\n",
"#inventory['mug'] = inventory['mug'] -1\n",
"#inventory['book'] = inventory['book'] -1\n",
"#inventory['keychain'] = inventory['keychain'] -1\n",
"\n",
"\n",
"\n",
"print ('Updated inventory:', inventory)\n",
"\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory: {'t-shirt': 4, 'mug': 5, 'hat': 3, 'book': 4, 'keychain': 5}\n",
"You added following products: ['hat', 'mug', 'book']\n",
"Order Statistics: Total Products Ordered: 3,Percentage of Products Ordered: 60.0\n",
"Updated inventory: {'t-shirt': 3, 'mug': 4, 'hat': 3, 'book': 3, 'keychain': 4}\n"
]
}
],
"source": [
"products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n",
"\n",
"inventory = {} \n",
"\n",
"\n",
" \n",
"inventory['t-shirt'] = int(input('How many t-shirts do you have? '))\n",
"\n",
"\n",
"inventory['mug'] = int(input('How many mugs do you have? '))\n",
"\n",
"\n",
"inventory['hat'] = int(input('How many hats do you have? '))\n",
"\n",
"\n",
"inventory['book'] = int(input('How many books do you have? '))\n",
"\n",
"\n",
"inventory['keychain'] = int(input('How many keychains do you have? '))\n",
"\n",
"print (f'Inventory: {inventory}')\n",
"\n",
"#2\n",
"customer_orders = []\n",
"orders1 = input(f'Please add your 1 product you want to order from those in the products list(t-shirt, mug, hat, book, keychain):')\n",
"customer_orders.append(orders1)\n",
"orders2 = input(f'Please add your 2 product you want to order from those in the products list(t-shirt, mug, hat, book, keychain):')\n",
"customer_orders.append(orders2)\n",
"orders3 = input(f'Please add your 3 product you want to order from those in the products list(t-shirt, mug, hat, book, keychain):')\n",
"customer_orders.append(orders3)\n",
"\n",
"print (f'You added following products: {customer_orders}')\n",
"\n",
"#3\n",
"total = len(customer_orders)\n",
"percentage = (total / len(products)) * 100\n",
"\n",
"order_status = (total, percentage)\n",
"\n",
"\n",
"print (f'Order Statistics: Total Products Ordered: {order_status[0]},Percentage of Products Ordered: {order_status[1]}') \n",
"\n",
"inventory['t-shirt'] = inventory['t-shirt'] -1\n",
"inventory['mug'] = inventory['mug'] -1\n",
"inventory['book'] = inventory['book'] -1\n",
"inventory['keychain'] = inventory['keychain'] -1\n",
"\n",
"#the last one was not ordered, but it still functions?\n",
"\n",
"print ('Updated inventory:', inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +235,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down