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.
Algoritmo Greeting Definir nombre Como Caracter Escribir "What is your name?" Leer nombre Escribir "Hi, ", nombre, ". Welcome!"FinAlgoritmoWhat it prints:
What is your name?User answer: SofiaHi, Sofia. Welcome!
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.
BeginnerPersonal Greeting
Asks for your name and age, and answers with both.
BeginnerTemperature Converter
Converts degrees Celsius to Fahrenheit and Kelvin.
BeginnerTip Calculator
Splits a restaurant bill, tip included.
BeginnerCan I Vote?
Tells you whether you can vote or how many years you have left.
BeginnerCoffee Shop Menu
Pick a drink from the menu and get the total to pay.
BeginnerTimes Table
Prints the multiplication table for the number you choose.
BeginnerPassword Check
Keeps asking for a password until it has at least 8 characters.
BeginnerSum Until Zero
Adds up the numbers you type until you enter a 0.
BeginnerGrade Average
Stores five grades in an array and finds the average and the highest.
BeginnerName Initials
Gets the initials of a full name.
BeginnerFibonacci Sequence
Prints the first terms of the Fibonacci sequence.
BeginnerBody Mass Index
Computes your BMI and classifies it as underweight, normal and so on.
IntermediateParking Fee
Charges every started hour, with a daily maximum.
IntermediateLeap Year
Applies the calendar rules to tell whether a year is a leap year.
IntermediateGuess the Number
Guess a secret number from 1 to 100 in seven tries.
IntermediateDrawing Shapes
Draws a square and a triangle with asterisks.
IntermediateLinear Search
Finds a name in a list, ignoring upper and lower case.
IntermediateStore Inventory
Records the stock of each product and flags what to restock.
IntermediateBubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
IntermediateSelection Sort
Finds the smallest of the remaining numbers and puts it in its place.
IntermediateInsertion Sort
Inserts each number among the sorted ones, like arranging cards in your hand.
IntermediateCounting Sort
Counts how many times each value appears, without comparing numbers.
IntermediateBinary Search
Finds a value in a sorted array by halving the range every step.
IntermediateLinear vs. Binary Search
Counts the comparisons each search needs on the same sorted list.
IntermediatePalindromes
Checks whether a phrase reads the same forwards and backwards.
IntermediateCount Vowels
Counts the vowels, spaces and other characters in a text.
IntermediateData Formatting
Fixes upper and lower case, and converts between text and numbers.
IntermediateFactorial and Power
Functions that compute a factorial and a power.
IntermediateBy Reference and by Value
Sorts three numbers by swapping them in subprocesses.
IntermediateReusable Validation
Validates the email and age on a sign-up form.
IntermediateModular Menu
A unit converter with a menu that keeps coming back.
IntermediatePrime Numbers
Finds every prime number up to a limit.
IntermediateGCD and LCM
Computes the greatest common divisor and the least common multiple.
IntermediateQuadratic Equation
Solves ax² + bx + c = 0, with real or complex roots.
IntermediateGeometry
Finds a circle's area and solves a right triangle.
IntermediateCompound Interest
Watch your savings grow year by year.
IntermediateShopping List
Adds items to a list that grows until you type FIN.
AdvancedShell Sort
Insertion sort between far-apart elements, with a gap that shrinks every pass.
AdvancedMerge Sort
Splits the array in halves, sorts each one recursively and merges them.
AdvancedQuicksort
Picks a pivot, splits smaller from larger values and sorts each side recursively.
AdvancedHeap Sort
Arranges the array as a heap, then takes the largest out again and again.
AdvancedCaesar Cipher
Encrypts a message by shifting each letter of the alphabet.
AdvancedTowers of Hanoi
Solves the classic tower puzzle step by step.
AdvancedRoman Numerals
Converts a number from 1 to 3999 into Roman numerals.
AdvancedBase Conversion
Writes a number in binary and hexadecimal.
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.
AdvancedClass Grade Book
Records three grades per student and builds a class report.
AdvancedHangman
Guess a secret word letter by letter, with six mistakes allowed.
AdvancedContact 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.