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
229 changes: 213 additions & 16 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Imagine you are building a program for a teacher who wants to track the progress of their students throughout the semester. The teacher wants to input the grades of each student one by one, and get a summary of their performance. There are in total 5 students. You are tasked with building the program that will allow the teacher to do this easily.\n",
"\n",
Expand All @@ -26,8 +28,10 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"*Hint:*\n",
"- You can use the input() function to ask the user to enter their information.\n",
Expand Down Expand Up @@ -57,11 +61,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"# Your code here\n",
"calificaciones = []"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Suma total de las calificaciones: 28.0\n"
]
}
],
"source": [
"for i in range(5):\n",
" calificacion = float(input(f\"Ingrese la calificación del estudiante {i + 1}: \"))\n",
" calificaciones.append(calificacion)\n",
"\n",
"suma_total = sum(calificaciones)\n",
"print(f\"Suma total de las calificaciones: {suma_total}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Calificaciones seleccionadas y ordenadas: [5.0, 6.0, 6.0]\n",
"Longitud de la lista seleccionada: 3\n",
"Número de veces que aparece la puntuación 5: 1\n"
]
}
],
"source": [
"calificaciones_seleccionadas = [calificaciones[0], calificaciones[2], calificaciones[4]]\n",
"\n",
"\n",
"calificaciones_seleccionadas.sort()\n",
"\n",
"\n",
"print(f\"Calificaciones seleccionadas y ordenadas: {calificaciones_seleccionadas}\")\n",
"print(f\"Longitud de la lista seleccionada: {len(calificaciones_seleccionadas)}\")\n",
"print(f\"Número de veces que aparece la puntuación 5: {calificaciones_seleccionadas.count(5)}\")"
]
},
{
Expand All @@ -72,8 +126,10 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Imagine you're running a fruit stand and want to keep track of your inventory. Write a Python program that does the following:\n",
"\n",
Expand All @@ -93,15 +149,45 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'manzana'"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Tupla_de_frutas=(\"manzana\",\"melocotón\",\"fresa\",\"plátano\",\"uvas\",\"piña\")\n",
"Tupla_de_frutas.len()\n",
"Tupla_de_frutas[0]\n",
"Tupla_de_frutas[5]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"#las tuplas no pueden modifcarse\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -110,8 +196,10 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Imagine you are a data analyst working for a literature museum. Your manager has given you two poems to analyze, and she wants you to write a Python program to extract useful information from them.\n",
"\n",
Expand All @@ -136,7 +224,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -163,11 +251,78 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"# Your code here\n",
"poem1=set(poem)\n",
"poem2=set(new_poem)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'’', 'p', 'c', 'A'}\n"
]
}
],
"source": [
"diferencia=poem1-poem2\n",
"print(diferencia)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'i', 'B', 'g', 'l', 'v', 'y', 'r', '\\n', 'I', 'S', 'w', 'h', 'F', 't', 'd', 'k', 'u', 'a', 'f', '.', ',', 'e', ' ', 'o', 'm', 'n', 's', 'T'}\n"
]
}
],
"source": [
"interseccion=poem1.intersection(poem2)\n",
"print(interseccion)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"poema_largo=poem1.union(poem2)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"35"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(poema_largo)"
]
},
{
Expand All @@ -178,8 +333,10 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Consider the following dictionary of students with their scores in different subjects. One of the students, Bob, has complained about his score in Philosophy and, after reviewing it, the teacher has decided to update his score to 100. Write a Python program that updates Bob's score in Philosophy to 100 in the dictionary."
]
Expand All @@ -193,7 +350,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -202,11 +359,51 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grades[\"Bob\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"grades[\"Bob\"][\"Philosophy\"]=100"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100, 3: 100}"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grades[\"Bob\"]"
]
},
{
Expand Down Expand Up @@ -285,7 +482,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -299,7 +496,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down