Logic: AND, OR, NOT · Lógica: AND, OR, NOT
A club that checks your age
- A coding club takes members only from age 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE.- Write the variable on each side:
Age >= 11 AND Age <= 16.
Un club que verifica tu edad
- Un club de programación acepta miembros únicamente entre las edades de 11 y 16. Una sola prueba no puede verificar ambos extremos.
AND(Y) esTRUE(VERDADERO) solo cuando ambas pruebas sonTRUE(VERDADERAS).- Escribe la variable en cada lado:
Age >= 11 AND Age <= 16.
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16
THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
OR: either test is enough
- A bus fare is free for a child or a senior: under 5, or 65 and over.
ORisTRUEwhen at least one test isTRUE.
OR: basta con una prueba
- El pasaje de autobús es gratuito para un niño o para una persona mayor: menor de 5 años, o 65 años y más.
OR(O) esTRUE(VERDADERO) cuando al menos una de las pruebas esTRUE(VERDADERA).
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65
THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
NOT flips a Boolean
NOTturnsTRUEintoFALSE, andFALSEintoTRUE.- A search that has not found the target yet is
NOT Found.
NOT invierte un booleano
NOT(NO) convierteTRUE(VERDADERO) enFALSE(FALSO), yFALSE(FALSO) enTRUE(VERDADERO).- Una búsqueda que aún no ha encontrado el objetivo es
NOT Found(No encontrado).
DECLARE Found : BOOLEAN
Found ← FALSE
IF NOT Found
THEN
OUTPUT "missing"
ENDIF
Watch out
Mark >= 0 AND <= 100is not a test. The second half has nothing to compare.- Parentheses make a mix obvious:
NOT (Age < 11 OR Age > 16).
Cuidado
Mark >= 0 AND <= 100no es una prueba válida. La segunda parte no tiene nada a qué comparar.- Los paréntesis hacen evidente una mezcla de condiciones:
NOT (Age < 11 OR Age > 16).
Common mistakes
AND,ORandNOTare keywords. Their operands areBOOLEAN, usually from a relational test.9618putsTHENon theIFline. This course keepsTHENon the next line.
Errores comunes
AND,ORyNOTson palabras clave. Sus operandos sonBOOLEAN, generalmente provenientes de una prueba relacional.- En
9618,THENaparece en la misma línea queIF. Este curso mantieneTHENen la línea siguiente.
Now you try
- Each task is one decision. Write both sides of
ANDand ofOR. - Press Check answer to test it.
Ahora te toca a ti
- Cada tarea es una decisión. Escribe ambos lados de
ANDy deOR. - Pulsa Check answer (Comprobar respuesta) para probarla.
Read an INTEGER Age. Output accepted when it is from 11 to · hasta 16 inclusive, using AND. Otherwise output no. · Lee un INTEGER Age. Escribe accepted si está entre 11 y 16 inclusive, usando AND. De lo contrario, escribe no.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · Lee un INTEGER Age. Escribe free si Age es menor que 5 o al menos 65, usando OR. De lo contrario, escribe pay.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Found is a BOOLEAN set to FALSE. If NOT Found, output missing. · Found es un BOOLEAN configurado en FALSE. Si NOT Found, escribe missing.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.