{"course":{"slug":"python-for-ai","title":"Python, from Zero, for AI","url":"https://addaly.com/learn/python-for-ai","level":"beginner","track":"build"},"lesson":{"slug":"first-line","title":"What a program is, and running your first line","url":"https://addaly.com/learn/python-for-ai/first-line","position":2,"of":89,"minutes":6,"answer":"A program does exactly what is written, in order, and shows you only what you ask it to show.","keyIdea":"A program does exactly what is written, in order, and shows you only what you ask it to show."},"body":{"format":"markdown","text":"## A program is a list of instructions with no gaps\n\nA program is a list of instructions written so a machine can follow them without asking you anything. That last part is the whole difficulty.\n\nIf you tell a person \"add up the prices and tell me the total\", they fill in what you left out. They know prices are numbers. They know to skip the blank line. They know what to do if one price is missing. A computer fills in nothing. It does exactly what is written, in the order it is written, and stops the moment something does not make sense.\n\nPython is one way of writing those instructions. It was designed to look close to English, which helps you read it, and occasionally fools you into thinking it will guess what you meant. It will not.\n\n## Two places to type Python\n\n**The interactive prompt.** Open a terminal and type `python3` (on Windows, usually `python`). You get a prompt like this:\n\n```\nPython 3.12.3\n>>>\n```\n\nEverything you type after `>>>` runs the instant you press Enter. This is for trying things.\n\n**A file.** Put your instructions in a file called `hello.py`, then run it:\n\n```bash\npython3 hello.py\n```\n\nThis is for programs you want to keep. Both run the same Python.\n\nIf `python3` is not found, install Python from python.org, or with your system's package manager.\n\n## Your first line\n\nType this into a file and run it:\n\n```python\nprint(\"Hello from Lagos\")\n```\n\nOutput:\n\n```\nHello from Lagos\n```\n\n`print` is an instruction that puts something on the screen. The round brackets hold what you want printed. The quote marks say \"this is text, not a command\". Without the quotes, Python would look for something named `Hello` and fail.\n\n## Lines run top to bottom, one at a time\n\n```python\nprint(\"first\")\nprint(\"second\")\nprint(2 + 2)\n```\n\nOutput:\n\n```\nfirst\nsecond\n4\n```\n\nPython read line one, did it, then line two, then line three. It does not look ahead. It does not reorder. This sounds obvious now and will save you an hour later.\n\nNotice the third line: `2 + 2` was worked out to `4`, and `print` put that on the screen. Python does arithmetic with `+ - * /`. Try `print(7 / 2)` and you get `3.5`, not `3`.\n\n## The difference that catches everyone once\n\nAt the interactive prompt, typing an expression shows you its answer:\n\n```\n>>> 2 + 2\n4\n```\n\nIn a file, it does not. Put a file containing only this line:\n\n```python\n2 + 2\n```\n\nRun it. Nothing appears. The file is not broken. Python did the addition, produced `4`, and threw it away, because nothing asked for it to be shown. The interactive prompt prints results as a convenience to you while you experiment. A running program has nobody to be convenient for.\n\nSo in files: if you want to see it, `print` it.\n\n## Notes to yourself\n\nA `#` means the rest of the line is for humans and Python ignores it:\n\n```python\n# prices are in naira\nprint(2500 * 3)\n```\n\n## Try this now\n\nMake a file, put four `print` lines in it, and deliberately break one: remove a closing bracket. Run it. Read what Python says. You are going to see a lot of those messages, and lesson seven is entirely about reading them."},"check":{"question":"A student writes a file containing exactly one line, `2 + 2`, and runs it with `python3 sums.py`. The terminal prints nothing at all and gives no error. What happened?","options":[{"text":"Python worked out the answer 4 and discarded it, because nothing in the file asked for it to be displayed.","correct":true},{"text":"Python skipped the line, because a value that is not stored in a variable is never actually calculated.","correct":false,"tempting":"It feels wasteful for a computer to compute something it throws away, so it seems the calculation must have been skipped entirely."},{"text":"The file failed silently, because arithmetic has to be inside a function before Python will run it.","correct":false,"tempting":"Most code you see in examples sits inside something, so a bare line at the top of a file looks like it is missing a container."},{"text":"Nothing printed because 4 is a number, and print-style output only ever shows text in quotes.","correct":false,"tempting":"Every printing example so far had quote marks in it, which makes quotes look like the thing that causes output."}]},"prev":{"slug":"installing-python","title":"Getting Python onto the machine you actually have","url":"https://addaly.com/learn/python-for-ai/installing-python"},"next":{"slug":"shell-and-script","title":"The interactive shell and the saved file, and when to use each","url":"https://addaly.com/learn/python-for-ai/shell-and-script"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Exam keys checked blind by a second model: 3,665 of 3,666 agreed. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'What a program is, and running your first line', in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/first-line (Accessed: 31 October 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"What a program is, and running your first line","courseTitle":"Python, from Zero, for AI","module":{"index":1,"slug":"getting-python-running","title":"Getting Python running, and your first working code"},"answer":null,"keyIdea":"A program does exactly what is written, in order, and shows you only what you ask it to show.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"a-program-is-a-list-of-instructions-with-no-gaps","runs":[{"text":"A program is a list of instructions with no gaps"}]},{"t":"p","runs":[{"text":"A program is a list of instructions written so a machine can follow them without asking you anything. That last part is the whole difficulty."}]},{"t":"p","runs":[{"text":"If you tell a person “add up the prices and tell me the total”, they fill in what you left out. They know prices are numbers. They know to skip the blank line. They know what to do if one price is missing. A computer fills in nothing. It does exactly what is written, in the order it is written, and stops the moment something does not make sense."}]},{"t":"p","runs":[{"text":"Python is one way of writing those instructions. It was designed to look close to English, which helps you read it, and occasionally fools you into thinking it will guess what you meant. It will not."}]},{"t":"h2","id":"two-places-to-type-python","runs":[{"text":"Two places to type Python"}]},{"t":"p","runs":[{"text":"The interactive prompt.","b":true},{"text":" Open a terminal and type "},{"text":"python3","code":true},{"text":" (on Windows, usually "},{"text":"python","code":true},{"text":"). You get a prompt like this:"}]},{"t":"code","lang":"","label":"Text","text":"Python 3.12.3\n>>>"},{"t":"p","runs":[{"text":"Everything you type after "},{"text":">>>","code":true},{"text":" runs the instant you press Enter. This is for trying things."}]},{"t":"p","runs":[{"text":"A file.","b":true},{"text":" Put your instructions in a file called "},{"text":"hello.py","code":true},{"text":", then run it:"}]},{"t":"code","lang":"bash","label":"Bash","text":"python3 hello.py"},{"t":"p","runs":[{"text":"This is for programs you want to keep. Both run the same Python."}]},{"t":"p","runs":[{"text":"If "},{"text":"python3","code":true},{"text":" is not found, install Python from python.org, or with your system’s package manager."}]},{"t":"h2","id":"your-first-line","runs":[{"text":"Your first line"}]},{"t":"p","runs":[{"text":"Type this into a file and run it:"}]},{"t":"code","lang":"python","label":"Python","text":"print(\"Hello from Lagos\")"},{"t":"p","runs":[{"text":"Output:"}]},{"t":"code","lang":"","label":"Text","text":"Hello from Lagos"},{"t":"p","runs":[{"text":"print","code":true},{"text":" is an instruction that puts something on the screen. The round brackets hold what you want printed. The quote marks say “this is text, not a command”. Without the quotes, Python would look for something named "},{"text":"Hello","code":true},{"text":" and fail."}]},{"t":"h2","id":"lines-run-top-to-bottom-one-at-a-time","runs":[{"text":"Lines run top to bottom, one at a time"}]},{"t":"code","lang":"python","label":"Python","text":"print(\"first\")\nprint(\"second\")\nprint(2 + 2)"},{"t":"p","runs":[{"text":"Output:"}]},{"t":"code","lang":"","label":"Text","text":"first\nsecond\n4"},{"t":"p","runs":[{"text":"Python read line one, did it, then line two, then line three. It does not look ahead. It does not reorder. This sounds obvious now and will save you an hour later."}]},{"t":"p","runs":[{"text":"Notice the third line: "},{"text":"2 + 2","code":true},{"text":" was worked out to "},{"text":"4","code":true},{"text":", and "},{"text":"print","code":true},{"text":" put that on the screen. Python does arithmetic with "},{"text":"+ - * /","code":true},{"text":". Try "},{"text":"print(7 / 2)","code":true},{"text":" and you get "},{"text":"3.5","code":true},{"text":", not "},{"text":"3","code":true},{"text":"."}]},{"t":"h2","id":"the-difference-that-catches-everyone-once","runs":[{"text":"The difference that catches everyone once"}]},{"t":"p","runs":[{"text":"At the interactive prompt, typing an expression shows you its answer:"}]},{"t":"code","lang":"","label":"Text","text":">>> 2 + 2\n4"},{"t":"p","runs":[{"text":"In a file, it does not. Put a file containing only this line:"}]},{"t":"code","lang":"python","label":"Python","text":"2 + 2"},{"t":"p","runs":[{"text":"Run it. Nothing appears. The file is not broken. Python did the addition, produced "},{"text":"4","code":true},{"text":", and threw it away, because nothing asked for it to be shown. The interactive prompt prints results as a convenience to you while you experiment. A running program has nobody to be convenient for."}]},{"t":"p","runs":[{"text":"So in files: if you want to see it, "},{"text":"print","code":true},{"text":" it."}]},{"t":"h2","id":"notes-to-yourself","runs":[{"text":"Notes to yourself"}]},{"t":"p","runs":[{"text":"A "},{"text":"#","code":true},{"text":" means the rest of the line is for humans and Python ignores it:"}]},{"t":"code","lang":"python","label":"Python","text":"# prices are in naira\nprint(2500 * 3)"},{"t":"h2","id":"try-this-now","runs":[{"text":"Try this now"}],"role":"try"},{"t":"p","runs":[{"text":"Make a file, put four "},{"text":"print","code":true},{"text":" lines in it, and deliberately break one: remove a closing bracket. Run it. Read what Python says. You are going to see a lot of those messages, and lesson seven is entirely about reading them."}]}],"check":{"question":[{"text":"A student writes a file containing exactly one line, "},{"text":"2 + 2","code":true},{"text":", and runs it with "},{"text":"python3 sums.py","code":true},{"text":". The terminal prints nothing at all and gives no error. What happened?"}],"options":[{"text":[{"text":"Python worked out the answer 4 and discarded it, because nothing in the file asked for it to be displayed."}],"correct":true,"tempting":null},{"text":[{"text":"Python skipped the line, because a value that is not stored in a variable is never actually calculated."}],"correct":false,"tempting":[{"text":"It feels wasteful for a computer to compute something it throws away, so it seems the calculation must have been skipped entirely."}]},{"text":[{"text":"The file failed silently, because arithmetic has to be inside a function before Python will run it."}],"correct":false,"tempting":[{"text":"Most code you see in examples sits inside something, so a bare line at the top of a file looks like it is missing a container."}]},{"text":[{"text":"Nothing printed because 4 is a number, and print-style output only ever shows text in quotes."}],"correct":false,"tempting":[{"text":"Every printing example so far had quote marks in it, which makes quotes look like the thing that causes output."}]}],"order":[1,3,2,0],"why":null},"prev":{"slug":"installing-python","title":"Getting Python onto the machine you actually have","minutes":9},"next":{"slug":"shell-and-script","title":"The interactive shell and the saved file, and when to use each","minutes":7}}}