Running code, with input
Run bash, python and javascript blocks where they are written, and keep the output in the note.
Running a block
- Type
/codeand pick the language from the dropdown on the block. - Press Run. The output is written into an
outputblock underneath, stamped with when it ran. Running again replaces it.
Programs that ask for input
A program that reads input — input() in Python, read in a shell, process.stdin or readline in JavaScript — needs its answers before it runs, because nobody is at a keyboard inside the machine it runs on.
in your note
```python
name = input("What is your name? ")
age = int(input("How old are you? "))
print(f"Hello {name}, next year you will be {age + 1}")
```- Press Run. ForkLeaf sees the program reads input and opens Program input instead of running it.
- Type the answers, one per line — here
Ada, then36. - Press Run again. Each line is what the program reads the next time it asks.
- Input in the block’s header opens or closes the box at any time. It shows Input ✓ when there is something in it.
- If a program stops because it ran out of input, the box opens and says so. Add the missing lines and run again.
- The input is not saved in the note — only the output is.
Where the code runs
In a throwaway virtual machine made for the one run and destroyed afterwards — never on your computer. It has internet access, and a run can take up to 30 seconds.