BS Input / Output
Learn how to read input with `inputNao` and print output with `lekho` in BornomalaScript.
Input and Output
Input and output are two of the most important ideas in programming.
- Input means data comes into your program from the user
- Output means your program shows a result on the screen
In BornomalaScript, inputNao is used to read input and lekho is used to print output.
Basic Example
The following example asks the user for a name and an age, then prints both values back to the screen:
dhoro x = inputNao("Tomar Nam ki?: ")
dhoro y = inputNao("Tomar boyosh koto?: ")
lekho("Tomar nam ${x}") // This is interpolation: ${variableName}
lekho("Tomar boyosh " + y) // You can also use + for concatenation
This is a very useful lesson because it shows how BornomalaScript can interact with the person using the program instead of only printing fixed text.
How It Works
The example has two separate jobs:
- Ask the user a question
- Print the answer back in a message
The first two lines use inputNao:
dhoro x = inputNao("Tomar Nam ki?: ")dhoro y = inputNao("Tomar boyosh koto?: ")
Those lines store the user’s answers in variables named x and y.
The next two lines use lekho to show output:
lekho("Tomar nam ${x}")lekho("Tomar boyosh " + y)
That means input collects data, and output displays it.
Step-by-Step Walkthrough
If this is your first time working with input and output, read the example line by line:
- The program asks for a name
- The user types a response and presses Enter
- The program stores that response in
x - The program asks for an age
- The user types a response and presses Enter
- The program stores that response in
y - The program prints a message using both values
This is the beginning of interactive programming.
Save and Run the File
Create a file named io.bs, paste the code into it, and save it.
Then run:
bs run io.bs
When the program starts, it should wait for your input in the terminal.
After you type your answers and press Enter, the program should print the final messages.
Input Examples
Here are a few more ways to use input and output together:
dhoro city = inputNao("Tomar shohor ki?: ")
lekho("Tumi " + city + " theke ashcho")
dhoro subject = inputNao("Pochondo subject ki?: ")
lekho("Tomar favorite subject holo ${subject}")
dhoro name = inputNao("Tomar nam ki?: ")
lekho("Shagotom, " + name)
These variations help you see that input values can be reused in different output messages.
Interpolation and Concatenation
The example page shows two common ways to build output:
- Interpolation:
"Tomar nam ${x}" - Concatenation:
"Tomar boyosh " + y
Interpolation places the variable directly inside the string.
Concatenation joins two pieces together.
Both approaches are useful, and beginners should try both to understand how text is built in BornomalaScript.
Text and Numbers
This example uses a name and an age because it shows two different kinds of user input.
Depending on how your compiler handles input, values may be treated as text first. If your project later needs numeric calculations, you may need to confirm how number conversion works in your version of BornomalaScript.
For now, the important lesson is that input values can be stored and shown back to the user.
Why This Lesson Matters
Programs become much more useful when they can respond to the user.
With input and output, you can build:
- greeting programs
- simple questionnaires
- calculators
- menu-driven tools
- beginner practice exercises
This is one of the first steps toward writing interactive software.
Common Mistakes
Beginners often make a few common mistakes in input and output programs:
- Forgetting to save the file before running it
- Typing the variable name differently in the output line
- Removing quotation marks around prompt text
- Forgetting to press Enter after typing the input
- Using a file name in the run command that does not match the saved file
If the program looks stuck, remember that inputNao is waiting for your response in the terminal.
Try These Variations
Once the basic example works, try these changes:
dhoro nam = inputNao("Tomar naam ki?: ")
lekho("Shagotom, " + nam)
dhoro school = inputNao("Tomar school er nam ki?: ")
lekho("Tumi " + school + " e poro")
dhoro favoriteColor = inputNao("Tomar pochondo rong ki?: ")
lekho("Tomar pochondo rong holo ${favoriteColor}")
If you change the prompt text, you can see how the same input function works in different situations.
Practice Task
Try writing your own interactive programs:
- Ask for the user’s name and print a greeting
- Ask for the user’s city and print a sentence about it
- Ask for a favorite subject and repeat it in output
- Ask for two values and print both back together
Example:
dhoro name = inputNao("Tomar nam ki?: ")
lekho("Amar notun bondhu holo ${name}")
What to Check If It Does Not Work
If the example does not behave as expected, check these things:
- The file is saved correctly
- The code matches the example syntax
- The terminal is waiting for input
- You entered a response and pressed Enter
- The compiler is installed correctly
Sometimes the program is not broken; it is simply waiting for the next input line.
Quick Checklist
Before moving on, make sure you can answer yes to these questions:
- Can you ask the user for input with
inputNao? - Can you store the input in a variable?
- Can you print the stored value with
lekho? - Can you use both interpolation and concatenation?
- Can you run the file with
bs run io.bs?
If yes, you understand the core idea of input and output.
Next Step
After input and output, a good next lesson is conditions. That will show you how to make decisions based on the values the user enters.