Skip to content
HackoryWEB SECURITY ACADEMYProgramming

Unit 06 · Condiciones: if, elif y else · Lesson 06

Combinar condiciones: and, or y not

and, or y not combinan condiciones.

Lesson content is in Spanish.

Python in your browser

The first time, Python downloads about 5 MB (only once; then it stays saved). If you can, use Wi-Fi.

Python is already saved in this browser: it will not download again.

Python downloads when you start reading.
  1. 01Understand
  2. 02Try
  3. 03Explain

The situation

El envío gratis de una tienda tiene dos requisitos: la compra tiene que ser de 100 o más y el domicilio tiene que estar en la zona centro. Hace falta combinar dos preguntas en una.

Understand each piece

  • and

    Da True solo si las dos condiciones son True. total >= 100 and zona == "centro".

  • or

    Da True si al menos una de las condiciones es True. zona == "centro" or zona == "norte".

  • not

    Da vuelta una condición: not True es False. not (zona == "sur") es lo mismo que zona != "sur".

Example

total = 120
zona = "centro"
print(total >= 100 and zona == "centro")
print(total < 50 or zona == "norte")

La primera línea da True: se cumplen las dos condiciones. La segunda da False: ninguna de las dos se cumple.

Before moving on: what will happen?

¿Qué va a mostrar este programa?
total = 80
zona = "centro"
if total >= 100 and zona == "centro":
    print("Envío gratis")
else:
    print("Envío con cargo")

Your mission

Calculá el envío según zona y monto

La prueba crea total (entero) y zona (texto en minúsculas). Mostrá un mensaje según estas reglas, en este orden: 1. Si el total es de 100 o más y la zona es centro: Envío gratis. 2. Si no, si la zona es centro o norte: Envío: $8. 3. En cualquier otro caso: Envío: $15.

  1. if total >= 100 and zona == "centro":
  2. elif zona == "centro" or zona == "norte":. Cada comparación se escribe completa.
  3. else: para el resto.

If you get stuck

One hint at a time: the first points the way and the last almost solves it.

The key idea

and pide que se cumplan todas las condiciones, or pide que se cumpla al menos una y not da vuelta el resultado.

Solve with help

If you have already tried, you can see a reference solution. The lesson is marked as solved with help and adds no XP.