Skip to content
EspañolWorkspace →

If statements in PSeInt: Si Entonces exercises

23 examples

How it works

A conditional lets the program do different things depending on the data. If the condition is true, one block runs; with SiNo (else) you say what to do when it's false. It all ends with FinSi.

The condition is a comparison that answers true or false: nota >= 60, edad < 18, respuesta = "yes". To require two things at once use Y (and); to accept one or the other, O (or).

When there are more than two cases (say, grades A, B, C or D) you put conditionals inside one another. If you always compare the same variable against fixed values, Segun is usually tidier.

Short example

The least you need to see it work. Copy it or open it in the editor.

if-statements-si.psc · 10 lines
Algoritmo EvenOrOdd    Definir n Como Entero    Escribir "Type a number:"    Leer n    Si n MOD 2 = 0 Entonces        Escribir n, " is even"    SiNo        Escribir n, " is odd"    FinSiFinAlgoritmo

What it prints:

Type a number:User answer: 77 is odd
Open it in Codoritmo

Opens in the browser editor, nothing to install.

Solved exercises

Each exercise comes with the full code, its flowchart and a sample run.

  • Can I Vote?

    Tells you whether you can vote or how many years you have left.

    Beginner
  • Coffee Shop Menu

    Pick a drink from the menu and get the total to pay.

    Beginner
  • Sum Until Zero

    Adds up the numbers you type until you enter a 0.

    Beginner
  • Body Mass Index

    Computes your BMI and classifies it as underweight, normal and so on.

    Intermediate
  • Parking Fee

    Charges every started hour, with a daily maximum.

    Intermediate
  • Leap Year

    Applies the calendar rules to tell whether a year is a leap year.

    Intermediate
  • Guess the Number

    Guess a secret number from 1 to 100 in seven tries.

    Intermediate
  • Store Inventory

    Records the stock of each product and flags what to restock.

    Intermediate
  • Bubble Sort

    Sorts random numbers by swapping neighbors, and stops as soon as they're in order.

    Intermediate
  • Selection Sort

    Finds the smallest of the remaining numbers and puts it in its place.

    Intermediate
  • Insertion Sort

    Inserts each number among the sorted ones, like arranging cards in your hand.

    Intermediate
  • Binary Search

    Finds a value in a sorted array by halving the range every step.

    Intermediate
  • Linear vs. Binary Search

    Counts the comparisons each search needs on the same sorted list.

    Intermediate
  • Palindromes

    Checks whether a phrase reads the same forwards and backwards.

    Intermediate
  • By Reference and by Value

    Sorts three numbers by swapping them in subprocesses.

    Intermediate
  • Quadratic Equation

    Solves ax² + bx + c = 0, with real or complex roots.

    Intermediate
  • Shell Sort

    Insertion sort between far-apart elements, with a gap that shrinks every pass.

    Advanced
  • Merge Sort

    Splits the array in halves, sorts each one recursively and merges them.

    Advanced
  • Quicksort

    Picks a pivot, splits smaller from larger values and sorts each side recursively.

    Advanced
  • Heap Sort

    Arranges the array as a heap, then takes the largest out again and again.

    Advanced
  • Towers of Hanoi

    Solves the classic tower puzzle step by step.

    Advanced
  • ATM

    Checks your PIN and lets you check, deposit and withdraw money.

    Advanced
  • Class Grade Book

    Records three grades per student and builds a class report.

    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.