Core programming fundamentals · Lesson 7 of 60 · Code lesson, JavaScript or Python · Optional
Input and output
Output is what a program shows, and input is what it receives, such as text typed by a person.
Programs read input as text, so what arrives is always a string.
Printing the result is how a program answers.
Worked example
In JavaScript, require("fs").readFileSync(0, "utf8") reads everything that was typed, and .trim() removes the extra line break.
const name = require("fs").readFileSync(0, "utf8").trim();
console.log("Hello, " + name + "!");Input:
Sam
Output: Hello, Sam!
In Python, input() reads one line of typed text.
name = input()
print("Hello, " + name + "!")Input:
Sam
Output: Hello, Sam!
Your turn
The program reads a name. Make it print Hello, then the name, then an exclamation mark, such as Hello, Ada!
Your program is checked with these 2 inputs:
Input:
Ada
Expected output:
Hello, Ada!
Input:
Mia
Expected output:
Hello, Mia!
Loading your practice…
Preparing your workspace…