Logical operators Y, O, NO in PSeInt: examples
10 examples
How it works
Logical operators combine conditions. Y (and) is true only if both conditions are; O (or) if at least one is; NO (not) flips the result. They can also be written as &&, || and ~.
Y checks ranges: edad >= 13 Y edad <= 19. O accepts several answers: letra = "y" O letra = "Y". Use parentheses to make clear what is evaluated first.
A Logico variable holds true or false directly, like encontrado (found) or terminado (done). Mientras NO encontrado Hacer then reads almost like a sentence.
Short example
The least you need to see it work. Copy it or open it in the editor.
Algoritmo CanEnter Definir edad Como Entero Definir conAdulto Como Logico edad <- 15 conAdulto <- Verdadero Si edad >= 18 O conAdulto Entonces Escribir "Can come in" SiNo Escribir "Cannot come in" FinSiFinAlgoritmoWhat it prints:
Can come inOpens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
Name Initials
Gets the initials of a full name.
BeginnerGuess the Number
Guess a secret number from 1 to 100 in seven tries.
IntermediateBubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
IntermediateInsertion Sort
Inserts each number among the sorted ones, like arranging cards in your hand.
IntermediateReusable Validation
Validates the email and age on a sign-up form.
IntermediateShell Sort
Insertion sort between far-apart elements, with a gap that shrinks every pass.
AdvancedHeap Sort
Arranges the array as a heap, then takes the largest out again and again.
AdvancedTic-Tac-Toe
The classic three-in-a-row game for two players.
AdvancedATM
Checks your PIN and lets you check, deposit and withdraw money.
AdvancedHangman
Guess a secret word letter by letter, with six mistakes allowed.
Advanced
In the language reference
The instructions involved, explained one by one.
Other concepts
Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.