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
130 changes: 128 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,137 @@
"\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": [
"{'t-shirt': 1, 'mug': 1, 'hat': 2, 'book': 1, 'keychain': 1}\n"
]
}
],
"source": [
"#Paso 1\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"hat+\", \"book\", \"keychain\"]\n",
"\n",
"#Paso 2\n",
"inventory={}\n",
"\n",
"#Paso 3\n",
"for product in products: \n",
" if product in inventory:\n",
" inventory [product] += 1\n",
" else: inventory [product] = 1\n",
"print(inventory)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"#Paso 4\n",
"customer_order = {}\n",
"customer_order.update({\"t-shirt\": 1, \"mug\": 1, \"hat\": 2})\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug': 2}\n"
]
}
],
"source": [
"#Paso 5\n",
"customer_order = {}\n",
"product = input(\"What do you want to buy?\") \n",
"quantity = int(input(\"How many do you want to buy?\"))\n",
"customer_order.update({product: quantity})\n",
"#Paso 6\n",
"print(customer_order)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug': 10}\n"
]
}
],
"source": [
"#Paso 7\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug': 2}\n",
"Total cost: 200.0\n"
]
},
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for /: 'str' and 'str'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mTypeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[33]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 2\u001b[39m print(total_order)\n\u001b[32m 3\u001b[39m \n\u001b[32m 4\u001b[39m total_cost = float(input(\u001b[33m\"How much does it cost?\"\u001b[39m)) * quantity\n\u001b[32m 5\u001b[39m print(f\"Total cost: {total_cost}\")\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m porcentaje= (input(\u001b[33m\"10% para 10\"\u001b[39m))/\u001b[33m\"100\"\u001b[39m\n\u001b[32m 7\u001b[39m print(f\"Total cost with 10%: {total_cost + (total_cost * porcentaje)}\")\n",
"\u001b[31mTypeError\u001b[39m: unsupported operand type(s) for /: 'str' and 'str'"
]
}
],
"source": [
"total_order= {product: quantity}\n",
"print(total_order)\n",
"\n",
"total_cost = float(input(\"How much does it cost?\")) * quantity \n",
"print(f\"Total cost: {total_cost}\")\n",
"porcentaje= (input(\"10% para 10\"))/\"100\"\n",
"print(f\"Total cost with 10%: {total_cost + (total_cost * porcentaje)}\")"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"inventory = {\"t-shirt\": 1, \"mug\": 1, \"hat\": 2, \"hat+\": 1, \"book\": 1, \"keychain\": 1}\n",
"update_inventory = {\"t-shirt\": 1, \"mug\": 1, \"hat\": 2}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +194,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down