Programming · AI · Crypto · Kali Linux

Decode tech.
Build what's next.

Hands-on guides, tutorials and honest insights on programming, artificial intelligence, cryptocurrency and ethical hacking with Kali Linux.

Latest articles

Wednesday, 21 October 2026

Python for Absolute Beginners: Your First 10 Lines of Code

Your First 10 Lines of Python" showing a code window named first.py with print, input and if statements, a warning about forgetting the colon, and the note

Python is one of the best first programming languages. Its code reads almost like plain English, it is free, and it is used for websites, data analysis, automation and AI. The hardest part is simply getting started.

In this guide you will install Python, write a real program in just 10 lines, run it, and understand what every line does. No experience needed.

The best way to learn is to type the code yourself instead of copying and pasting. Your fingers and brain learn together.

Step 1: Install Python

Download Python from the official site, python.org, and install it. On Windows, tick the box that says "Add Python to PATH" during setup. Kali Linux and most Linux systems already include Python 3.

Check that it works by opening a terminal (or Command Prompt) and running:

python3 --version

On Windows the command may be python --version or py --version instead. You should see something like Python 3.12.x. Any recent Python 3 version is fine for this guide.

Step 2: Create your file

Open any plain text editor (Notepad, VS Code, or Mousepad on Kali), and create a new file called first.py. The .py ending tells your computer it is a Python file.

Step 3: Type your first 10 lines

print("Hello, world!")
name = input("What is your name? ")
print("Nice to meet you,", name)
age = int(input("How old are you? "))
if age >= 18:
    print("You are an adult.")
else:
    print("You are under 18.")
for i in range(1, 4):
    print("Counting:", i)

Note that lines 6, 8 and 10 start with four spaces. That space at the beginning is called indentation, and Python uses it to know which lines belong together.

Step 4: Run it

In your terminal, go to the folder where you saved the file and run:

python3 first.py

(Use python first.py or py first.py on Windows.) The program will ask for your name and age, then print a message. If you enter the name Sam and the age 20, you will see:

Hello, world!
What is your name? Sam
Nice to meet you, Sam
How old are you? 20
You are an adult.
Counting: 1
Counting: 2
Counting: 3

What does each line do?

Line 1: print

print("Hello, world!") shows text on the screen. The text goes inside quotes, and the quotes mark it as text, which programmers call a string.

Line 2: variables and input

name = input("What is your name? ") asks the user a question and waits for an answer. The answer is stored in a variable called name. Think of a variable as a labeled box that holds a value.

Line 3: print with a variable

print("Nice to meet you,", name) prints the text and the value stored in name. Notice there are no quotes around name, because we want its value, not the word "name".

Line 4: numbers

input() always gives you text, even if the user types digits. The int() function converts that text into a whole number, so Python can compare it. Without it, the next line would fail.

Lines 5 to 8: making decisions

if age >= 18: checks a condition. If it is true, Python runs the indented line below it. If not, it runs the lines after else:. The colon at the end of if and else is required.

Lines 9 and 10: repeating

for i in range(1, 4): is a loop. It repeats the indented line below it, with i taking the values 1, 2 and 3. The range stops before the last number, so range(1, 4) counts 1, 2, 3, not 4.

Errors are normal (and helpful)

Try running the program again and type the word abc as your age. Python will stop with an error that ends like this:

ValueError: invalid literal for int() with base 10: 'abc'

This is not a failure. Read the last line of any error, because it tells you what went wrong. Here Python is saying it can't turn "abc" into a number. Every programmer sees errors every day, and reading them is a core skill.

Common beginner mistakes

  • Missing quotes. print(Hello) fails because Python thinks Hello is a variable. Text needs quotes.
  • Forgetting the colon. if, else and for lines must end with :.
  • Wrong indentation. The line under a colon must be indented, and lines that belong together must use the same amount of spaces.
  • Case sensitivity. Print is not the same as print, and Name is not the same as name.
  • Wrong quotes. Use straight quotes ("), not curly "smart" quotes copied from a document.

Try it yourself: 4 small challenges

  1. Change the program so that it also asks for your favourite colour and prints it back.
  2. Change 18 to 21 and see how the result changes.
  3. Make the loop count from 1 to 10.
  4. Print the age the user will be next year (hint: age + 1).

Try each one on your own before searching for the answer. If you get stuck, you can ask an AI assistant to explain the error, but ask it to explain rather than write the solution for you.

What to learn next

You have now used the four building blocks of almost every program: output (print), variables, decisions (if) and loops (for). Next, learn more about strings and numbers, then functions and lists. That path will carry you to your first small projects.

Final thoughts

Ten lines may look small, but you just wrote a program that talks to the user, makes a decision and repeats an action. Everything else in programming builds on these ideas. Keep the file, change it, break it and fix it. That is how every programmer learns.

Did your program run on the first try? Tell me in the comments, and follow the blog for more guides on programming, AI, crypto and Kali Linux.

No comments:

Post a Comment