Input, processing, and output
Many programs do three things: receive information, do something with it, and show a result. These parts are called input, processing, and output.
Input can come from a question, a key press, a saved value, or a sensor. Output can be a message, a picture, or a sound. A program does not always need a person to type something.
A smoothie machine
Fruit goes into a blender, the blender mixes it, and a smoothie comes out. In a greeting program, a nickname goes in, some words are joined together, and a greeting comes out.
Unlike the blender, the program can keep the original input while making its result. Creating a greeting does not erase the nickname.
Follow the information
Run this with an input-capable host, such as the Pliro IDE. Use the pretend nickname Nova; you do not need to enter your real name.
# language: en
let nickname = ask("Choose a pretend nickname:")
let greeting = "Hello, " + nickname + "!"
say greeting
ask supplies the input as text. The + signs join pieces of text: that is the processing. say displays the result: that is the output. The variable greeting remembers the joined text.
Predict, then run
Which message should appear after you enter Nova?
Hello, Nova!
The space after the comma comes from "Hello, ". Pliro does not guess where a sentence needs spaces.
Your challenge
Make the program say goodbye using the same nickname. You do not need to ask twice. Then decide what greeting you want when somebody submits an empty answer.
A common mistake
A reply to ask is text, even if somebody types digits. The text "12" and the number 12 are different kinds of value. For a question that requires a number, use askNumber with suitable limits.
If the program waits for a reply, it has not necessarily crashed. Look for its question and answer it, or use Stop if you want to end the run.
Where next?
Questions and keyboard input · Unusual inputs · Sharing safely
