Conditionals and loops in Python: if, for and while

if / elif / else, for with range and over lists, while, break and continue, with step-by-step visualisers.

En Python los bloques se marcan con indentación (4 espacios), no con llaves. Cada if, for o while termina en : y lo de dentro va sangrado.

if / elif / else

nota = 75
if nota >= 90:
    print("Sobresaliente")
elif nota >= 70:
    print("Notable")
elif nota >= 50:
    print("Aprobado")
else:
    print("Suspenso")

for with range()

range(fin) va de 0 a fin-1. range(inicio, fin, paso) para más control.

for over a list

Lo más pythónico: recorrer directamente los elementos, sin índices.

while, break and continue

Check what you've learned