Python for begginers 6 min read

Python course Part 1: The Zero-to-One Python Guide (Variables, Math, & Your First Script)

Adrian Kuczyński
Senior Security Developer
Python course Part 1: The Zero-to-One Python Guide (Variables, Math, & Your First Script)

Welcome to Part 1 of the Pragmatic Python Bootcamp.

Today we aren't going to install Python and print "Hello World" like it's 1999. We're going to build an interactive terminal tool. By the end of this post you'll have written a script that takes user input, runs some math, and formats the output cleanly.

Here's what we're building:

Welcome to the Terminal Tip & Split Calculator!
Enter the total bill amount: $120.50
Enter the tip percentage (e.g. 15, 20): 20
How many people are splitting the bill? 3

--- Receipt ---
Total Bill (with tip): $144.60
Each person pays: $48.20

Let's get your environment dialed in and start writing logic.

🛑 Dev Callout: The Python Mental Model

Coming from C#, .NET, or Java? Adding Python to your toolbelt feels like unlocking a cheat code, but the architecture is different in three ways worth internalizing up front:

  • No compilation step. Python is interpreted line by line. You write, you run. There's no build.

  • Dynamically typed. You don't declare string name or int age. Variables get their type at runtime, from whatever you assign.

  • Whitespace matters. Brace yourself (literally). Python uses indentation instead of {} to define code blocks.

1. The 60-Second Setup Speedrun

Before we write code, you need the Python interpreter and an editor.

Step 1 — The interpreter

  • Linux (Arch / EndeavourOS): sudo pacman -S python

  • Linux (Debian / Ubuntu): sudo apt install python3 python3-pip

  • macOS (via Homebrew): brew install python

  • Windows: download the installer from python.org. Make absolutely sure you tick "Add Python to PATH" on the first screen — skipping that box is the single most common reason a Windows install "doesn't work."

Step 2 — The editor

You want something that understands Python. Two solid choices:

  • Visual Studio Code — lightweight, fast, terminal-centric. Install the official "Python" extension by Microsoft and you're set.

  • JetBrains PyCharm — if you already live in the JetBrains ecosystem (Rider for .NET, IntelliJ for Java), PyCharm will feel like home. World-class refactoring and data tooling out of the box.

Verify the install by opening a terminal (Zsh, Bash, or PowerShell) and running:

python --version
# Output should be something like: Python 3.12.x

If you see a version number, you're ready.

2. Variables and Dynamic Typing

In Python, developer time is treated as more expensive than machine time. You stop fighting the syntax and start solving the problem. Creating a variable is just naming it and assigning a value:

target_ip = "192.168.1.15"  # a string
port = 8080                 # an integer
is_secure = True            # a boolean

Notice we never said what type each variable is. Python works that out from the value. If you ever need to check, the built-in type() function tells you:

print(type(port))  # <class 'int'>

3. Strings & F-Strings

Python makes text manipulation genuinely pleasant. You can use single ' or double " quotes interchangeably, but the real magic is f-strings (formatted string literals).

Put an f before the opening quote, then drop variables straight into the text inside curly braces {}:

username = "admin"
login_attempts = 3

# The old, clunky way — manual concatenation, manual str() conversion:
print("User " + username + " failed to login " + str(login_attempts) + " times.")

# The f-string way:
print(f"User {username} failed to login {login_attempts} times.")

Both print the same thing. Only one of them is worth typing.

4. Math and Type Casting

Python is a capable calculator straight out of the box:

Operation

Operator

Note

Addition / subtraction

+ -

Multiplication

*

Division

/

Always returns a float, e.g. 10 / 2 is 5.0

Floor division

//

Drops the remainder: 7 // 2 is 3

Modulo (remainder)

%

7 % 2 is 1

Exponent

**

2 ** 10 is 1024

There's one trap waiting for you the moment you mix math with user input. Meet the input() function:

age = input("How old are you? ")

The trap: input() always hands you back a string. If the user types 34, Python sees "34". Try to do math on it — age + 5 — and the script crashes, because you can't add a number to a piece of text.

The fix is to cast (convert) the string into a number: int() for whole numbers, float() for decimals.

age = int(input("How old are you? "))
print(f"In 10 years, you will be {age + 10}.")

5. Bringing It Together: Your First Script

Let's combine all of it — variables, f-strings, math, input, and casting — into the tool we previewed at the top.

Create a file named calculator.py and type this in. Read the comments as you go; they explain the why, not just the what.

# 1. Greet the user
print("Welcome to the Terminal Tip & Split Calculator!")

# 2. Get the inputs and convert them right away.
#    float() because money has decimals:
bill_amount = float(input("Enter the total bill amount: $"))

# Dividing by 100 turns a number like 20 into 0.20, which is what we need for the math:
tip_percentage = float(input("Enter the tip percentage (e.g. 15, 20): ")) / 100

# People come in whole numbers, so int():
people = int(input("How many people are splitting the bill? "))

# 3. Do the math
tip_amount = bill_amount * tip_percentage
total_bill = bill_amount + tip_amount
cost_per_person = total_bill / people

# 4. Print the results.
#    \n adds a blank line. The :.2f rounds to exactly two decimal places —
#    handy for money, since 144.6 / 3 would otherwise print as 48.199999999999996.
print("\n--- Receipt ---")
print(f"Total Bill (with tip): ${total_bill:.2f}")
print(f"Each person pays: ${cost_per_person:.2f}")

That :.2f at the end of the variable is a format specifier. It tells the f-string "show this number with two digits after the decimal point." Without it, floating-point math leaks ugly trailing digits into your receipt. With it, you get clean currency.

Save the file, open your integrated terminal in VS Code or PyCharm, and run it:

python calculator.py

Type in some numbers and watch your receipt print.

What's Next?

Congratulations — you didn't print "Hello World," you built a script that handles real input and real math.

But notice how fragile it still is. What happens if the user types the word "twenty" instead of 20? Right now the whole thing falls over. In Part 2: Logic & Loops, we'll add the brains of programming — if/else decisions and while loops — so your code can react to what it's given instead of blindly trusting it.

Discussion

Read Next