Most modern computer programs use a Graphical User Interface (GUI) to communicate with the user. But for simpler programs, especially when you are first learning, it is easier to use a console interface.
A console interface is a simple window where you can type commands or information in, and the computer program can display text information in response.
Examples of console windows are the Windows Command Prompt, the Linux Terminal window, or the Python Shell that comes with IDLE (the default Python environment). The Python Shell window is shown here:
When a program runs in a console, it can use the PRINT function to display text in the console window, and INPUT function to accept data typed in by the user.
Here is how you might print "Hello World!"
PRINT("Hello World!")
{{% purple-note %}} In most languages, the functions which output text to the console window are called print functions. This is because, in the early days, computers didn't have screens. The main way a computer would output results would be via a printer. The name is still used out of tradition. {{% /purple-note %}}
Sometimes you will need to format the data before you print it. You can do that using placeholders:
PRINT("It's the %s of %s, %s", "2nd", "Feb", 2017);
Which prints:
It's the 2nd of Feb, 2017
The first string passed to the PRINT function is called the format string. It contains 3 placeholders - {}. The remaining parameters are used to replace the placeholders in the final output string:
The INPUT function allows the user to type some information into the console window.
You will usually want to use a PRINT function to ask the user for some information (so that they know what to type in). Then use an INPUT function so they can the information in. And then perhaps PRINT some kind of acknowledgement. A bit like a conversation.
Here is an example Python program that asks you your name, and says hello:
STRING name PRINT("What is your name?") name = INPUT() PRINT("Hello %s", name)
Copyright (c) Axlesoft Ltd 2021