jueves, 27 de agosto de 2026
RABBIT EXCERCISE
from matplotlib import pyplot as plt
x=range(1,21)
#Weight in kg
rabbit_1 = [
1.85, 1.82, 1.84, 1.78, 1.75, 1.77, 1.70, 1.66, 1.68, 1.61,
1.58, 1.60, 1.52, 1.48, 1.43, 1.45, 1.38, 1.32, 1.27, 1.21
]
rabbit_2 = [
2.50, 2.46, 2.48, 2.40, 2.33, 2.25, 2.21, 2.23, 2.15, 2.08,
2.05, 2.10, 2.15, 2.22, 2.20, 2.31, 2.40, 2.48, 2.57, 2.66
]
rabbit_3 = [
1.20, 1.23, 1.21, 1.28, 1.34, 1.32, 1.40, 1.47, 1.45, 1.53,
1.61, 1.68, 1.66, 1.75, 1.84, 1.82, 1.93, 2.05, 2.18, 2.30
]
rabbit_4 = [
3.25, 3.21, 3.23, 3.18, 3.12, 3.14, 3.05, 2.98, 3.01, 2.92,
2.87, 2.89, 2.80, 2.74, 2.68, 2.71, 2.60, 2.52, 2.45, 2.38
]
plt.plot(x,rabbit_1,label="Rabbit 1")
plt.legend() #Shows labels
plt.show()
EXAMPLE
from matplotlib import pyplot as plt
x=[1,2,3,4]
y=[1,4,9,16]
plt.plot(x,y)
plt.show()
plt.savefig("plot.png")
miércoles, 19 de agosto de 2026
EXCERCISE SOLUTION
1. Importar la librería de gráficas
from matplotlib import pyplot as plt
from matplotlib: Le dice a Python que busque dentro de una librería llamadamatplotlib(que sirve para hacer gráficos). import pyplot as plt: Importa la herramienta de dibujo (pyplot) y le da el apodo cortopltpara no tener que escribir su nombre largo cada vez que la usemos.
2. Definir los valores del eje X
x = [-4, -3.5, -3, -2.5, -2, -1.5, -1]
x = [...]: Crea una lista con los números que van sobre la línea horizontal (eje X). El rango: Tu ejercicio te pide que esté entre -4 y -1
. Incluimos números decimales intermediarios (como -3.5o-2.5) para que la curva de la gráfica quede suave y bien definida.
3. Calcular los valores del eje Y (La fórmula)
y = [i**2 + 5*i + 6 for i in x]
Esta estructura se llama comprensión de listas y actúa como una máquina que calcula el resultado de la función para cada punto
for i in x: Toma cada número de la listaxuno por uno y lo llama temporalmentei. i**2: Eleva el número al cuadrado . Recuerda que en Python**significa potencia. + 5*i: Multiplica el número por 5 (5x). Recuerda usar*para multiplicar. + 6: Le suma 6.
y = [...]: Guarda todos los resultados calculados en una nueva lista llamaday.
Por ejemplo: Cuando x = -4, el cálculo es (-4)^2 + 5(-4) + 6 = 16 - 20 + 6 = 2
4. Crear y mostrar la gráfica
plt.plot(x, y)
plt.plot(x, y): Recibe los puntos del eje X y del eje Y, los ubica en un plano cartesiano y dibuja una línea que los une.
plt.show()
plt.show(): Renderiza y abre la ventana donde se visualiza la gráfica terminada.
SINTAX PYTHON TABLE
Python Symbols and Keywords Table (English)
| Category | Symbol / Keyword | Code Example | Description & Meaning |
| Control Flow | if | if dist_1 < dist_2: | Runs a block of code only if the specified condition evaluates to |
| Control Flow | else | else: | Runs an alternative block of code when the preceding |
| Control Flow | for | for i in x: | Iterates over a sequence (such as a list or range) a specific number of times |
| Control Flow | while | while True: | Repeats a block of code continuously as long as the given condition remains |
| Control Flow | def | def my_function(x): | Used to declare and define a new custom function |
| Control Flow | return | return result | Exits a function and returns a result or value back to the caller |
| Data Structures | [ ] | x = [-1.5, 0, 1.5] | Square brackets: Creates a List (an ordered collection of items) |
| Data Structures | { } | s = {1, 2, 3} | Curly braces: Creates a Set (an unordered collection of unique items) |
| Data Structures | ( ) | print("Hello") | Parentheses: Used to call functions, pass arguments, or group expressions |
| Operators | ** | y = i**2 | Exponentiation / Power operator (e.g., $i^2$ or $i$ raised to a power) |
| Operators | * | y = 5 * x | Multiplication operator |
| Operators | < / > | if a < b: | Comparison operators for "less than" ( |
| Operators | = | a = 3 | Assignment operator (stores a value or object inside a variable) |
| Syntax & Comments | # | # Single line comment | Single-line comment. Python ignores any text written after this symbol on the same line |
| Syntax & Comments | """ | """ Multi-line comment """ | Triple quotes: Used for multi-line comments or docstrings |
| Syntax & Comments | : | if x > 0: | Colon: Marks the beginning of an indented block of code (used after |