Chapter 01 · Section III · 22 min read
Your first program, run and understood
Tradition demands a hello world. We will write one with a Nepali greeting, and then spend ten minutes truly understanding every line of what we just typed.
Every programmer alive has written, in their first hour of writing code, a program that says “hello, world”. This is tradition, not law, and we will follow it — with one small twist. Our hello world will carry a Nepali greeting, and we will take the time to read it the way a teacher reads a sentence with a young child: slowly, out loud, every part understood.
The program
Open the setup-check.ipynb notebook from the previous section, or create a new one called hello.ipynb. In a fresh cell, type the following exactly:
greeting = "Namaste"
name = "Nischal"
print(greeting + ", " + name + "!")
Press Shift+Enter. You should see:
Namaste, Nischal!
Three lines of code. One line of output. That is enough material for the next ten minutes.
Reading line one
greeting = "Namaste"
This is an assignment. Read it from right to left, not left to right:
- The thing on the right —
"Namaste"— is a string. A string is a piece of text. In Python you mark a string by wrapping it in quote marks. The marks tell Python “everything between these is text, not code”. - The
=is not “equals” in the mathematical sense. It is “store this”. - The name on the left —
greeting— is the label you are storing the text under. You choose this name. You could have called itsalutation,hello_word, ornamaste_str. Python does not care.
The result: there is now a thing in memory called greeting, and if anyone asks for its value, Python will say "Namaste".
Reading line two
name = "Nischal"
Same pattern. The string "Nischal" is stored under the name name. Change "Nischal" to your own name before moving on. The point of programming is not to follow examples; it is to make them yours.
Reading line three
print(greeting + ", " + name + "!")
This line is doing four things in one go. Let us unpick them:
print(...)is a function call.printis a function — a small machine, built into Python, whose job is to write something to the screen. The parentheses say “call this function”. Whatever sits inside the parentheses is the argument the function receives.- The argument here is the expression
greeting + ", " + name + "!". Python evaluates the argument first, then hands the result toprint. - The
+between strings is concatenation — joining text end-to-end, not arithmetic addition. So"Namaste" + ", "gives"Namaste, ", and so on, until we have one combined string. - Finally,
printwrites that combined string to the screen.
You can see the staging by trying each piece on its own:
greeting + ", "
That cell will display 'Namaste, ' — the joined string, but not “printed” in the formal sense. (Notebooks show the value of the last expression in a cell automatically. That display is similar to, but not the same as, calling print. The difference matters more when we get to scripts, less for now.)
A first error, deliberately
Now let us break the program on purpose. In a new cell, type:
greeting = "Namaste
Run it. Python will throw an error that looks roughly like:
SyntaxError: EOL while scanning string literal
Translate it: “end of line while scanning string literal”. Python was reading along, saw the opening quote, started looking for the closing quote — and reached the end of the line without finding one. So it stopped and complained.
That is what an error message is: a polite explanation of why Python could not continue. The skill of debugging is not memorising error codes. It is the discipline of reading the message slowly and believing what it says.
A nicer way to write the same thing
The pattern greeting + ", " + name + "!" is fine but clumsy — once you have three or four pieces to combine, it becomes hard to read. Python has a tidier syntax called an f-string (the f is for “formatted”):
greeting = "Namaste"
name = "Nischal"
print(f"{greeting}, {name}!")
Same output. Easier to read. The f before the opening quote tells Python “this is a formatted string”; the {...} placeholders are filled in with the value of whatever expression is inside the braces.
From here on in the track, we will write strings this way. The + pattern still works — you will see it in older code — but f-strings are the standard now.
Make it yours
Before the quiz, three small modifications. Try each in a new cell:
- Change
greetingto"Sat Sri Akal"or"Tashi Delek"— Punjabi and Tibetan greetings you may also hear in Nepal. Run. The structure of the program does not change; only the data does. - Add a third variable:
time_of_day = "evening". Build a new print line:print(f"{greeting}, {name}! Hope your {time_of_day} is going well."). Run. - Change
printtoPrint(capital P). Run. Note the error:NameError: name 'Print' is not defined. Python is case-sensitive.printandPrintare two different names; only the lowercase one is a real function.
Each of these takes thirty seconds and teaches more than a paragraph of theory would.
Check your understanding
Quick check
—Look at this program: greeting = 'Namaste' name = 'Sita' print(greeting + ', ' + name) What will it print?
Quick check
—A friend writes the following program, runs it, and is surprised it does not work: name = 'Rita' Print(name) Which of these is the most accurate explanation?
What comes next
You have written, run, modified, and broken a real program. From the next chapter on, the programs get bigger — lists of values, loops, functions, and the small operations that turn a one-cell experiment into something that can read a NEPSE feed or process a folder of receipts. The pattern of type, run, read, modify you used in this section will be your pattern for the next four courses. Get comfortable with it now and the rest is unhurried.
Before you move on, one last thing. Go back to the homework from Section 1: the one real problem from your own life you wrote down. Look at it again. By the end of this course, you will have built a tiny prototype that addresses some piece of it. Keep that note somewhere you will see it.