What would you like to learn?

Try PowerShell, networks, XSS, or Step 138

Browse the full curriculum →

Python

Step 41. Setting Up Python and Your First Code — The Day You Build Your Workbench

Step 41Estimated practice · 3 hours

Level 1 — Programming and the Computer’s Inner Workings | Difficulty ★★☆☆☆ | Estimated time: 3 hours

Prerequisites: Level 0 complete. You know how to use the terminal (PowerShell) and a text editor.

  • What you need: an internet connection and administrator rights (only needed during installation).
  • Caution: today’s exercise is 100% safe. All we do is install Python and VSCode, then create and run files inside your own computer.

In Level 0, you learned conversations where the computer answers once for each one-line command. The limits of that approach are clear. Try to "rename a thousand files" with commands and your fingers won’t survive. So we need a language for writing out a work schedule for the computer in advance. That language is a programming language, and the de facto standard language of the security field is Python. A large share of hacking tools is written in Python, and solving CTF challenges often starts with a Python script and ends with a Python script. Today is the first step of that journey — the day of workbench setup. From Level 1 on, code is the protagonist, and today we build the workbench where that code will live.


1. Learning Objectives

By the end of this chapter, you will be able to:

  • Install Python and verify the PATH registration with python --version
  • Enter interactive mode (>>>), test things line by line, and exit with exit()
  • Install the Python extension in VSCode and create and run a .py file
  • Build a program with input and output using variables, input(), print(), and f-strings
  • Explain why input() always returns a string, and understand the need for int() conversion
  • Read an error message (Traceback) by splitting it into two boxes: "where / what"

2. Background Knowledge — Today’s Tools and Concepts

Today’s Tools at a Glance

Category Details
Language/environment Python 3.12 or later (install from python.org), PowerShell, VSCode + Microsoft Python extension
Today’s commands/grammar python --version (verify install), python (interactive mode), print(), input(), variable assignment (=), f-strings, int(), # comments
Concepts needed interpreted languages, PATH, IDE, variables, strings vs. numbers, reading error messages

2-1. Interpreted Languages — A Language with an Interpreter by Your Side

Computers actually only understand machine code made of 0s and 1s. There are two ways to turn human-written code into machine code.

  • Compilation: the entire code is translated at once into an executable file, which then runs. It’s like translating a whole book before publishing it; C is the classic example.
  • Interpretation: read one line, interpret one line, run it immediately. It’s like having a simultaneous interpreter sitting next to you; Python belongs here.

This is exactly why Python is great for beginners. With no translation-and-publishing process, you see results the moment you write, so the loop of "write → check → fix" spins fast. Learning goes better the faster the loop spins.

2-2. PATH and IDE — The Phone Book and the Workbench

The PATH you’ll meet during installation is "the list of folders the terminal looks through to find a command." Register Python on the PATH, and typing python from any folder will run it. It’s like registering a number in the phone book so you can call by name alone.

You can write code in Notepad, but developers use a workbench called an IDE (Integrated Development Environment). It colors your code, underlines mistakes, and even has a run button. In this book we use VSCode (Visual Studio Code) — free and the most widely used.

2-3. Variables and Input/Output — Name Tags and Dialogue Windows

Today’s code has three ingredients.

  • Variable: a name tag attached to a value. name = "Chris" attaches the tag name to the value "Chris".
  • input(): a function (a pre-built bundle of functionality) that shows the user a question and brings back the answer.
  • print(): a function that outputs a value to the screen.

With just these three, a program begins a conversation of "asking, remembering, and answering." Today’s final piece is a program that asks your name and age, then greets you back.


3. Follow Along

3-1. Installing Python — The Single Most Important Checkbox

Go to python.org in your browser and download the latest installer from the Downloads menu. At the very bottom of the installer’s first screen, there is one small checkbox.

☑ Add python.exe to PATH

You must check this box and then click Install Now. This check is the PATH registration that makes "python come running no matter where in the terminal you call it." Most of today’s walls come from this one box.

When installation finishes, verify it. Open PowerShell fresh (a window opened before installation doesn’t know the new PATH):

python --version
Python 3.12.14

(Verified on 2026-09-09. The verification environment was Python 3.12.14; if you install now, you may get a higher version (e.g., 3.13.x). Every piece of code in Level 1 of this book runs identically on 3.8 or later, regardless of version, so a different number is perfectly fine.)

If you see a version number, you’ve succeeded. If you get a "not recognized" error, you missed the checkbox — solve it at Wall 1.

3-2. Interactive Mode — Improvised Conversation with Python

Python has an interactive mode (interactive shell) where you test things line by line without a file. In PowerShell:

python
Python 3.12.14 (main, Sep  1 2026, 14:17:39) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

(Verified on 2026-09-09. The version and date will differ with your environment.)

The >>> symbol is the "go ahead, speak" sign. Try typing yourself.

>>> 1 + 2
3
>>> "Hello" + "World"
'HelloWorld'
>>> "10" + "5"
'105'
>>> exit()

(Verified on 2026-09-09.)

How to read it: it calculates, and it glues text together. exit() is the way out. The third line is the important one. "10" wrapped in quotes is not a number but text, so addition becomes concatenation and produces '105'. This fact returns in the trap of 3-5. From now on, anything that makes you wonder "would this work?" can be tested in this mode first.

3-3. Installing VSCode and Your First File

Download the installer from code.visualstudio.com and install it. After launching, click the extensions icon on the left (Ctrl+Shift+X), search for Python, and install Microsoft’s Python extension. This extension handles the coloring and the run button.

Create a working folder. Make a folder named py_practice on your Desktop, and open it via VSCode’s File menu → "Open Folder". Create a new file and name it hello.py. .py is the tail tag of a Python file.

print("Hello, Python!")

Save the file (Ctrl+S) and press the ▶ button at the top right. A terminal opens below and shows:

Hello, Python!

(Verified on 2026-09-09. Running the same code in the terminal with python filename.py gives the same result.)

How to read it: the one line you wrote in the file ran. The terminal that opened at the bottom of VSCode is the same terminal you used in Level 0. VSCode is simply a workbench that embraces a terminal.

3-4. Variables and Input — A Program That Converses

Now let’s build today’s piece. Erase the contents of hello.py and write this:

name = input("What's your name? ")
age = input("Your age? ")
print(f"Nice to meet you, {name}! You're {age}.")

Run it and answer the questions.

What's your name? Minsu
Your age? 17
Nice to meet you, Minsu! You're 17.

(Verified on 2026-09-09. This is the result of running with the inputs Minsu and 17.)

How to read it: let’s take it apart line by line.

  1. input("What's your name? ") — shows the question and waits for an answer. The answer goes into a variable with the name tag name.
  2. The age likewise goes into age.
  3. print(f"...{name}...") — the f before the quotes is a sign meaning "replace the {curly braces} inside with the variable’s value." This is called an f-string.

Input → store → process → output. These four steps are the skeleton of almost every program. Even a giant scanning tool is ultimately flesh added onto this skeleton.

3-5. The Number Trap — input Is Always Text

Time to experience an important trap. Change hello.py like this:

age = input("Your age? ")
next_year = age + 1
print(f"Next year you'll be {next_year}!")

Run it and enter 17, and you get an error (verified on 2026-09-09):

Traceback (most recent call last):
  File "...s41_typeerror.py", line 2, in <module>
    next_year = age + 1
                ~~~~^~~
TypeError: can only concatenate str (not "int") to str

(The file path will show yours. The diagnosis on the last line is what matters.)

How to read it: it means "you can’t add a number (int) to text (str)." Even when the user types 17, input() receives it not as the number 17 but as the text "17". Remember "10" + "5" = '105' from 3-2. Addition between texts is concatenation.

Fix: wrap it with int(), which converts text into a number.

age = int(input("Your age? "))
next_year = age + 1
print(f"Next year you'll be {next_year}!")
Your age? 17
Next year you'll be 18!

(Verified on 2026-09-09.)

This trap is a rite of passage for every Python beginner. It will follow you later whenever you calculate with values received from the web or read from files, so learn it firmly now.

3-6. How to Read Error Messages — Read in Two Boxes

Half of programming skill is reading error messages. Let’s cause an error on purpose. In hello.py:

print("hello"

Run it (verified on 2026-09-09):

  File "...s41_syntax.py", line 1
    print("hello"
         ^
SyntaxError: '(' was never closed

How to read it: top to bottom, you only need to look at two boxes.

  1. Where: File ..., line 1 — the file name and line number are the crime scene. The problem line below it and the ^ marker are the spot Python found.
  2. What: the last line SyntaxError: '(' was never closed — the diagnosis "a parenthesis was never closed."

Just reading these two boxes changes the speed at which you find answers. This time, let’s make a typo.

prnit("hello")
Traceback (most recent call last):
  File "...s41_nameerror.py", line 1, in <module>
    prnit("hello")
    ^^^^^
NameError: name 'prnit' is not defined. Did you mean: 'print'?

(Verified on 2026-09-09.)

How to read it: it means "I don’t know the name prnit." The "Did you mean: ‘print’?" at the end is a feature of recent Python (3.10 onward) that even suggests the correct answer to your typo. On older versions it may end without this phrase. Typing print as prnit is a mistake every beginner on Earth makes at least once.

3-7. Comments — Notes to Your Future Self

Code can contain lines the computer ignores: comments, which start with #.

# This program asks your name and says hello
# Written: today, Author: me
name = input("What's your name? ")  # input always returns text
print(f"Nice to meet you, {name}!")

How to read it: nothing after # affects execution. It’s a note only humans read, and it can be attached at the end of a line too. Today’s you must be kind to the you of three weeks from now. The habit of writing down reasons in preparation for the "why is it like this?" moment shines brighter as code grows.


4. Missions & Exercises

Mission — A Letter to My Future Self

Create a new file future.py and assemble the following requirements yourself.

  1. Receive a name as input.
  2. Receive the current age as input (convert it to a number).
  3. Print In 10 years, ○○ will be □□. The days of today build those ten years. (○○ is the name, □□ is the age 10 years later).
  4. On the last line, print — From me, on Day 1 of Level 1.

When done, grade yourself. Check that all four requirements appear, and that the age calculation didn’t end up as text concatenation.

Exercises

Question 1. If you don’t check "Add python.exe to PATH" during installation, what happens, and why?

Question 2. You received 20 via input() and stored it in the variable age. Why does adding 1 to this age cause an error, and how do you fix it?

Question 3. Look at the error message below and answer "where" and "what" respectively.

Traceback (most recent call last):
  File "score.py", line 3, in <module>
    print(toltal)
NameError: name 'toltal' is not defined. Did you mean: 'total'?

Question 4. In interactive mode, how do the results of "7" + "3" and int("7") + int("3") differ? Answer with the reason.


Answers & completion criteria · expand/collapse

5. Model Answers & Completion Criteria

Mission Model Answer

# A letter to my future self
name = input("Name: ")
age = int(input("Current age: "))   # input returns text, so convert with int
future = age + 10
print(f"In 10 years, {name} will be {future}. The days of today build those ten years.")
print("— From me, on Day 1 of Level 1")

Example run:

Name: Minsu
Current age: 17
In 10 years, Minsu will be 27. The days of today build those ten years.
— From me, on Day 1 of Level 1

How to verify: ① Check that all four requirements are in the output. ② Check that the age is a number with 10 added — if it concatenates like 1710, you skipped the int() conversion. ③ If you get an error, read from the last line (TypeError, SyntaxError, etc.) and apply the two-box reading from 3-6.

Exercise Answers

Answer 1. The terminal can’t find the python command and gives a "not recognized" error. PATH is the list of folders the terminal looks through for commands, and Python’s install folder isn’t on that list. Rerunning the installer and turning on the PATH option via Modify, or reinstalling, solves it.

Answer 2. Since input()‘s return value is always a string (str), age + 1 becomes "adding a number to text" and raises TypeError: can only concatenate str (not "int") to str (message verified on 2026-09-09). Wrap it with int() like age = int(input(...)) to convert it to a number.

Answer 3. "Where": line 3 of the file score.py, print(toltal). "What": NameError — meaning the name toltal has never been defined; it’s a typo of total. Python’s suggestion ("Did you mean: ‘total’?") is exactly the answer hint.

Answer 4. "7" + "3" becomes the string '73', while int("7") + int("3") becomes the number 10. With quotes, Python treats them as text and addition becomes "concatenation"; after converting to numbers with int(), addition becomes arithmetic (the same principle was verified in interactive mode on 2026-09-09).

Completion Criteria Checklist

  • [ ] I verified the installation and PATH registration with python --version
  • [ ] I entered interactive mode (>>>), checked "10" + "5" myself, and exited with exit()
  • [ ] I installed the Python extension in VSCode and ran a .py file with the ▶ button
  • [ ] I built a conversational program with variables, input(), print(), and f-strings
  • [ ] I can explain that input() returns a string and why int() conversion is needed
  • [ ] I actually met the three errors — TypeError, SyntaxError, NameError — and read their last lines
  • [ ] I completed the mission (future.py) and verified the four requirements

6. Common Pitfalls & Fixes

Wall 1. python is not recognized

Symptom: typing python in the terminal gives an error like "’python’ is not recognized as the name of a cmdlet…" (the wording varies with PowerShell version and language settings).
Cause: you didn’t check "Add python.exe to PATH" during installation, or you didn’t open a fresh terminal after installing. PATH is copied the moment a terminal opens, so a terminal opened before installation doesn’t know the new registration.
Fix: close the terminal completely, open a new one, and retry. If it still fails, try py --version (Windows’ alternative invocation), and if that fails too, rerun the installer and check the PATH option via "Modify" to reinstall.

Wall 2. I pressed ▶ in VSCode and it runs strangely

Symptom: no output appears, or it runs with a different Python.
Cause: the Python extension isn’t installed, or VSCode doesn’t know which Python to use.
Fix: check in Extensions (Ctrl+Shift+X) whether Microsoft’s Python extension is installed, and click the Python version on the status bar at the bottom right to select the version you just installed.

Wall 3. SyntaxError from a missing parenthesis or quote

Symptom: errors like the SyntaxError: '(' was never closed you saw in 3-6.
Cause: quotes and parentheses are partners. If one opens, it must close.
Fix: trace upward from where VSCode underlines, looking for the unmatched pair. Often the culprit is the line right above the line the error points to — an open parenthesis gets discovered on the next line.

Wall 4. Non-English characters come out garbled

Symptom: something like 안녕 prints as 안녕.
Cause: the code tables (encodings) that turn characters into numbers are mismatched. This happens when the Windows terminal’s default code table differs from Python’s.
Fix: run chcp 65001 in PowerShell to set the code table to UTF-8, then run again. Using VSCode’s built-in terminal usually works correctly from the start. Encoding is covered in more detail in Step 45.


7. Summary

Today’s Concepts

Concept One-line description
Interpreted language A language executed line by line through an interpreter — Python is the classic example
PATH The list of folders the terminal looks through for commands
IDE A development workbench that colors, runs, and flags errors (VSCode)
Variable A name tag attached to a value (name = "Minsu")
f-string A string that replaces {curly braces} with variable values
Traceback Python’s error report — read it in two boxes: "where / what"

Today’s Grammar & Commands

Grammar/command What it does
python --version Verify install + verify PATH
python / exit() Enter / exit interactive mode
print(value) Output to the screen
input("question") Receive input — result is always a string
int(value) Convert a string to an integer
f"...{variable}..." A string with variables interpolated
# Comment — a note only humans read

Instincts More Important Than Grammar

Inside today’s three-line program lives the whole skeleton of programming: input, store, process, output. And an error message is not an enemy — it’s a diagnostic report. The habit of reading it in two boxes — "where (file, line), what (last line)" — will save you hundreds of hours ahead.

Remember two more things. First, the security industry uses Python because you can build things fast. Vulnerability proofs of concept and breach log analysis both start in Python. Second, the Python you installed today comes with pip, which downloads parts (libraries) from around the world (its presence was verified in the test environment with pip --version). You have no use for it now, but later you’ll meet it as the single line pip install part-name. And the place where every script written in this language gets used is always the same. ⚠️ All exercises in this chapter are for your own lab and legal platforms only. Applying them to unauthorized systems is a crime.


Once every box is checked, Step 41 is complete.

ONE STEP FURTHER

Finished this lesson?

Check the completion criteria, then mark your progress.

Something wrong with this page or a link? Let us know.
Next