Skip to content
EspañolWorkspace →

Input and output in PSeInt: Leer and Escribir exercises

51 examples

How it works

Almost every algorithm does three things: it takes data in, processes it and shows a result. In PSeInt, data comes in with Leer and results go out with Escribir.

Leer pauses the program until the person types something and presses Enter; what they typed is stored in the variable. That's why you show a question with Escribir first: otherwise the console just waits without saying what it wants.

Escribir takes several things separated by commas and shows them together: text in quotes, variables and even calculations. Add Sin Saltar and whatever comes next stays on the same line.

Short example

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

input-and-output.psc · 6 lines
Algoritmo Greeting    Definir nombre Como Caracter    Escribir "What is your name?"    Leer nombre    Escribir "Hi, ", nombre, ". Welcome!"FinAlgoritmo

What it prints:

What is your name?User answer: SofiaHi, Sofia. Welcome!
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.

  • Hello World

    Your first algorithm: print a couple of messages on screen.

    Beginner
  • Personal Greeting

    Asks for your name and age, and answers with both.

    Beginner
  • Temperature Converter

    Converts degrees Celsius to Fahrenheit and Kelvin.

    Beginner
  • Tip Calculator

    Splits a restaurant bill, tip included.

    Beginner
  • 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
  • Times Table

    Prints the multiplication table for the number you choose.

    Beginner
  • Password Check

    Keeps asking for a password until it has at least 8 characters.

    Beginner
  • Sum Until Zero

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

    Beginner
  • Grade Average

    Stores five grades in an array and finds the average and the highest.

    Beginner
  • Name Initials

    Gets the initials of a full name.

    Beginner
  • Fibonacci Sequence

    Prints the first terms of the Fibonacci sequence.

    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
  • Drawing Shapes

    Draws a square and a triangle with asterisks.

    Intermediate
  • Linear Search

    Finds a name in a list, ignoring upper and lower case.

    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
  • Counting Sort

    Counts how many times each value appears, without comparing numbers.

    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
  • Count Vowels

    Counts the vowels, spaces and other characters in a text.

    Intermediate
  • Data Formatting

    Fixes upper and lower case, and converts between text and numbers.

    Intermediate
  • Factorial and Power

    Functions that compute a factorial and a power.

    Intermediate
  • By Reference and by Value

    Sorts three numbers by swapping them in subprocesses.

    Intermediate
  • Reusable Validation

    Validates the email and age on a sign-up form.

    Intermediate
  • Modular Menu

    A unit converter with a menu that keeps coming back.

    Intermediate
  • Prime Numbers

    Finds every prime number up to a limit.

    Intermediate
  • GCD and LCM

    Computes the greatest common divisor and the least common multiple.

    Intermediate
  • Quadratic Equation

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

    Intermediate
  • Geometry

    Finds a circle's area and solves a right triangle.

    Intermediate
  • Compound Interest

    Watch your savings grow year by year.

    Intermediate
  • Shopping List

    Adds items to a list that grows until you type FIN.

    Advanced
  • 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
  • Caesar Cipher

    Encrypts a message by shifting each letter of the alphabet.

    Advanced
  • Towers of Hanoi

    Solves the classic tower puzzle step by step.

    Advanced
  • Roman Numerals

    Converts a number from 1 to 3999 into Roman numerals.

    Advanced
  • Base Conversion

    Writes a number in binary and hexadecimal.

    Advanced
  • Tic-Tac-Toe

    The classic three-in-a-row game for two players.

    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
  • Hangman

    Guess a secret word letter by letter, with six mistakes allowed.

    Advanced
  • Contact Book

    Add, list and search contacts in a book that grows.

    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.