Standard Input
In the IDE, you write what the program will read in the Input tab before you run it. The program reads it one line at a time. (In the examples in this documentation, the contents of the “Input” block below each example are passed in.)
Reading a line (👂🏼)
🆕🔡▶️👂🏼❗️ reads one line from standard input as a string. The newline at the end of the line is not included.
🏁 🍇
🆕🔡▶️👂🏼❗️ ➡️ name
😀 🔤Hello, name!🔤❗️
🍉Emoji
Hello, Emoji!
Reading as a number
Turn the string you read into an integer with 🔢 … 10❗️. The result is an optional (🍬🔢), so unwrap it with ↪️ … ➡️ (Optionals).
🏁 🍇
🆕🔡▶️👂🏼❗️ ➡️ line
↪️ 🔢 line 10❗️ ➡️ n 🍇
😀 🔤Twice line is 🔡 n ✖️ 2❗️🔤❗️
🍉
🙅 🍇
😀 🔤Please enter a number🔤❗️
🍉
🍉21
Twice 21 is 42
Reading several numbers on one line
For numbers separated by spaces, split them with 🔫 and then convert them one by one.
🏁 🍇
🆕🔡▶️👂🏼❗️ ➡️ line
0 ➡️ 🖍🆕 sum
🔂 part 🔫 line 🔤 🔤❗️ 🍇
↪️ 🔢 part 10❗️ ➡️ n 🍇
sum ⬅️➕ n
🍉
🍉
😀 🔤Total 🔡 sum❗️🔤❗️
🍉3 1 4 1 5
Total 14
Reading many lines
A common format has the count on the first line and the data on the following lines.
🏁 🍇
🍺 🔢 🆕🔡▶️👂🏼❗️ 10❗️ ➡️ count
🔂 i 🆕⏩ 0 count❗️ 🍇
🆕🔡▶️👂🏼❗️ ➡️ name
😀 🔤🔡 i ➕ 1❗️: name🔤❗️
🍉
🍉3 Alice Bob Carol
1: Alice 2: Bob 3: Carol
We know the first line is always a number, so it is unwrapped with 🍺. If you pass a line that is not a number, the program stops there.