In the previous examples, we used the built-in print and say functions to print something to the console (speaking more strictly, to the standard output attached to the program). In this section, you will learn how to perform basic reading from the standard input. This is basically how the program gets what you type onto the console.
To read the input, there are a few functions that you may use directly without loading any modules. They are listed in the following table:
Function | What it does |
get | This reads one line from the input and returns it |
lines | This returns the list of lines containing the data lines that came from the standard input |
slurp | This returns a string that contains the whole input |
The get and line functions may be used when you need to parse the input data line by line. For example, call get as many times as you need if you...